15 assert((
sizeof(1ULL)*8 == 64)) ;
16 pool = (
E*) malloc(
sizeof(
E)*nelements) ;
17 freed.resize(ceil(nelements/64.), ~0ULL) ;
58 new_element->val =
value ;
62 new_element->fwd = nullptr ;
78 new_element->
bwd = nullptr ;
79 pos->bwd = new_element ;
84 new_element->
fwd =
pos.raw() ;
85 new_element->bwd =
pos->bwd ;
86 pos->bwd = new_element ;
87 (new_element->bwd)->fwd = new_element ;
90 return {new_element} ;
95 if (el==
nullptr)
return nullptr ;
97 if (
n==0 && el !=
nullptr)
99 printf(
"ERR: cannot remove from empty list\n") ;
113 else if (el->
bwd ==
nullptr)
115 (el->
fwd)->bwd =
nullptr ;
120 (el->
fwd)->bwd = el->
bwd ;
139 for (i = 0 ; i<
freed.size() &&
freed[i]==0 ; ++i) ;
140 if (i==
freed.size()) {printf(
"ERROR: no more space to allocate element in the list\n") ;
return nullptr ; }
142 for (j = 0 ; (v & 1ULL) == 0 ; v>>=1, j++) ;
143 freed[i] &= ~(1ULL << j) ;
145 return pool + (i*64+j) ;
153 freed[i] |= 1ULL<<j ;
Definition: LinkedList.h:29
iterator()
Definition: LinkedList.h:33
iterator & operator++(int v)
Definition: LinkedList.h:37
E * operator->()
Definition: LinkedList.h:40
iterator(E *element)
Definition: LinkedList.h:34
bool operator!=(iterator e)
Definition: LinkedList.h:36
iterator & operator--(int v)
Definition: LinkedList.h:38
bool operator==(iterator e)
Definition: LinkedList.h:35
E * raw()
Definition: LinkedList.h:41
T & operator*()
Definition: LinkedList.h:39
E * el
Definition: LinkedList.h:31
Definition: LinkedList.h:12
iterator insert(iterator pos, T &&value)
Definition: LinkedList.h:54
void freemem(iterator el)
Definition: LinkedList.h:148
E * ending
Definition: LinkedList.h:48
E * allocate()
Definition: LinkedList.h:136
list(size_t nelements)
Definition: LinkedList.h:14
~list()
Definition: LinkedList.h:19
E * pool
Definition: LinkedList.h:45
E * erase(iterator el)
Definition: LinkedList.h:92
iterator end()
Definition: LinkedList.h:53
iterator begin()
Definition: LinkedList.h:52
size_t n
Definition: LinkedList.h:49
E * lastelement
Definition: LinkedList.h:47
size_t size()
Definition: LinkedList.h:51
E * beg
Definition: LinkedList.h:46
std::vector< uint64_t > freed
Definition: LinkedList.h:134
@ pos
Definition: Typedefs.h:19
Definition: LinkedList.h:9
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1282
unsigned __int64 uint64_t
Definition: stdint.h:136
Definition: LinkedList.h:22
T val
Definition: LinkedList.h:23
E * bwd
Definition: LinkedList.h:25
E * fwd
Definition: LinkedList.h:24