1 #include "actionlist.h"
7 actionlist::actionlist() :
15 actionlist::~actionlist() {
20 bzero(children, sizeof(children));
25 for(int i=0;i<ALLNODESIZE;i++) {
26 if (children[i] != NULL && !(((uintptr_t) children[i]) & ISACT))
31 sllnode<ModelAction *> * allnode::findPrev(modelclock_t index) {
33 modelclock_t increment = 1;
34 modelclock_t mask = ALLMASK;
39 modelclock_t shiftclock = index >> totalshift;
40 modelclock_t currindex = shiftclock & ALLMASK;
42 //See if we went negative...
43 if (currindex != ALLMASK) {
44 if (ptr->children[currindex] == NULL) {
45 //need to keep searching at this level
51 return reinterpret_cast<sllnode<ModelAction *> *>(((uintptr_t)ptr->children[currindex])& ACTMASK);
52 //need to increment here...
53 ptr = ptr->children[currindex];
54 increment = increment >> ALLBITS;
55 mask = mask >> ALLBITS;
56 totalshift -= ALLBITS;
60 //If we get here, we already did the decrement earlier...no need to decrement again
62 increment = increment << ALLBITS;
63 mask = mask << ALLBITS;
64 totalshift += ALLBITS;
73 modelclock_t shiftclock = index >> totalshift;
74 modelclock_t currindex = shiftclock & ALLMASK;
75 if (ptr->children[currindex] != NULL) {
76 if (totalshift != 0) {
77 ptr = ptr->children[currindex];
80 allnode * act = ptr->children[currindex];
81 sllnode<ModelAction *> * node = reinterpret_cast<sllnode<ModelAction *>*>(((uintptr_t)act) & ACTMASK);
88 increment = increment >> ALLBITS;
89 mask = mask >> ALLBITS;
90 totalshift -= ALLBITS;
94 void actionlist::addAction(ModelAction * act) {
96 int shiftbits = MODELCLOCKBITS - ALLBITS;
97 modelclock_t clock = act->get_seq_number();
99 allnode * ptr = &root;
101 int index = (clock >> shiftbits) & ALLMASK;
102 allnode * tmp = ptr->children[index];
103 if (shiftbits == 0) {
104 sllnode<ModelAction *> * llnode = new sllnode<ModelAction *>();
107 ptr->children[index] = reinterpret_cast<allnode *>(((uintptr_t) llnode) | ISACT);
108 sllnode<ModelAction *> * llnodeprev = ptr->findPrev(clock);
109 if (llnodeprev != NULL) {
111 llnode->next = llnodeprev->next;
112 llnode->prev = llnodeprev;
114 //see if we are the new tail
115 if (llnodeprev->next == NULL)
118 llnode->next->prev = llnode;
120 llnodeprev->next = llnode;
122 //We are the begining
128 //we are the first node
134 //need to find next link
137 //handle case where something else is here
139 sllnode<ModelAction *> * llnodeprev = reinterpret_cast<sllnode<ModelAction *>*>(((uintptr_t) llnode) & ACTMASK);
140 llnode->next = llnodeprev->next;
141 llnode->prev = llnodeprev;
142 if (llnode->next != NULL)
143 llnode->next->prev = llnode;
144 llnodeprev->next = llnode;
145 ptr->children[index] = reinterpret_cast<allnode *>(((uintptr_t) llnode) | ISACT);
148 } else if (tmp == NULL) {
150 ptr->children[index] = tmp;
154 shiftbits -= ALLBITS;
160 void decrementCount(allnode * ptr) {
162 if (ptr->count == 0) {
163 if (ptr->parent != NULL) {
164 for(uint i=0;i<ALLNODESIZE;i++) {
165 if (ptr->parent->children[i]==ptr) {
166 ptr->parent->children[i] = NULL;
167 decrementCount(ptr->parent);
175 void actionlist::removeAction(ModelAction * act) {
176 int shiftbits = MODELCLOCKBITS - ALLBITS;
177 modelclock_t clock = act->get_seq_number();
178 allnode * ptr = &root;
180 int index = (clock >> shiftbits) & ALLMASK;
181 allnode * tmp = ptr->children[index];
182 if (shiftbits == 0) {
187 sllnode<ModelAction *> * llnode = reinterpret_cast<sllnode<ModelAction *> *>(((uintptr_t) tmp) & ACTMASK);
190 if (llnode->val == act) {
191 //found node to remove
192 sllnode<ModelAction *> * llnodeprev = llnode->prev;
193 sllnode<ModelAction *> * llnodenext = llnode->next;
194 if (llnodeprev != NULL) {
195 llnodeprev->next = llnodenext;
199 if (llnodenext != NULL) {
200 llnodenext->prev = llnodeprev;
205 //see if previous node has same clock as us...
206 if (llnodeprev->val->get_seq_number() == clock) {
207 ptr->children[index] = reinterpret_cast<allnode *>(((uintptr_t)llnodeprev) | ISACT);
209 //remove ourselves and go up tree
210 ptr->children[index] = NULL;
218 llnode = llnode->prev;
220 } while(llnode != NULL && llnode->val->get_seq_number() == clock);
221 //node not found in list... no deletion
224 } else if (tmp == NULL) {
228 shiftbits -= ALLBITS;
233 void actionlist::clear() {
234 for(uint i = 0;i < ALLNODESIZE;i++) {
235 if (root.children[i] != NULL) {
236 delete root.children[i];
237 root.children[i] = NULL;
241 while(head != NULL) {
242 sllnode<ModelAction *> *tmp=head->next;
252 bool actionlist::isEmpty() {
253 return root.count == 0;