1 #include "actionlist.h"
7 actionlist::actionlist() :
12 actionlist::~actionlist() {
17 bzero(children, sizeof(children));
22 for(int i=0;i<ALLNODESIZE;i++) {
23 if (children[i] != NULL && !(((uintptr_t) children[i]) & ISACT))
28 sllnode<ModelAction *> * allnode::findPrev(modelclock_t index) {
30 modelclock_t increment = 1;
31 modelclock_t mask = ALLMASK;
36 modelclock_t shiftclock = index >> totalshift;
37 modelclock_t currindex = shiftclock & ALLMASK;
39 //See if we went negative...
40 if (currindex != ALLMASK) {
41 if (ptr->children[currindex] == NULL) {
42 //need to keep searching at this level
48 ptr = ptr->children[currindex];
49 //need to increment here...
50 increment = increment >> ALLBITS;
51 mask = mask >> ALLBITS;
52 totalshift -= ALLBITS;
56 //If we get here, we already did the decrement earlier...no need to decrement again
58 increment = increment << ALLBITS;
59 mask = mask << ALLBITS;
60 totalshift += ALLBITS;
69 modelclock_t shiftclock = index >> totalshift;
70 modelclock_t currindex = shiftclock & ALLMASK;
71 if (ptr->children[currindex] != NULL) {
72 if (totalshift != 0) {
73 ptr = ptr->children[currindex];
75 allnode * act = ptr->children[currindex];
76 sllnode<ModelAction *> * node = reinterpret_cast<sllnode<ModelAction *>*>(((uintptr_t)act) & ALLMASK);
83 increment = increment >> ALLBITS;
84 mask = mask >> ALLBITS;
85 totalshift -= ALLBITS;
89 void actionlist::addAction(ModelAction * act) {
91 int shiftbits = MODELCLOCKBITS - ALLBITS;
92 modelclock_t clock = act->get_seq_number();
94 allnode * ptr = &root;
96 int index = (clock >> shiftbits) & ALLMASK;
97 allnode * tmp = ptr->children[index];
99 sllnode<ModelAction *> * llnode = new sllnode<ModelAction *>();
102 ptr->children[index] = reinterpret_cast<allnode *>(((uintptr_t) llnode) | ISACT);
103 sllnode<ModelAction *> * llnodeprev = ptr->findPrev(index);
104 if (llnodeprev != NULL) {
106 llnode->next = llnodeprev->next;
107 llnode->prev = llnodeprev;
109 //see if we are the new tail
110 if (llnodeprev->next == NULL)
113 llnode->next->prev = llnode;
115 llnodeprev->next = llnode;
117 //We are the begining
123 //we are the first node
129 //need to find next link
132 //handle case where something else is here
134 sllnode<ModelAction *> * llnodeprev = reinterpret_cast<sllnode<ModelAction *>*>(((uintptr_t) llnode) & ALLMASK);
135 llnode->next = llnodeprev->next;
136 llnode->prev = llnodeprev;
137 llnode->next->prev = llnode;
138 llnodeprev->next = llnode;
139 ptr->children[index] = reinterpret_cast<allnode *>(((uintptr_t) llnode) | ISACT);
142 } else if (tmp == NULL) {
144 ptr->children[index] = tmp;
148 shiftbits -= ALLBITS;
154 void decrementCount(allnode * ptr) {
156 if (ptr->count == 0) {
157 if (ptr->parent != NULL) {
158 for(uint i=0;i<ALLNODESIZE;i++) {
159 if (ptr->parent->children[i]==ptr) {
160 ptr->parent->children[i] = NULL;
161 decrementCount(ptr->parent);
169 void actionlist::removeAction(ModelAction * act) {
170 int shiftbits = MODELCLOCKBITS - ALLBITS;
171 modelclock_t clock = act->get_seq_number();
172 allnode * ptr = &root;
174 int index = (clock >> shiftbits) & ALLMASK;
175 allnode * tmp = ptr->children[index];
176 if (shiftbits == 0) {
181 sllnode<ModelAction *> * llnode = reinterpret_cast<sllnode<ModelAction *> *>(((uintptr_t) tmp) & ALLMASK);
184 if (llnode->val == act) {
185 //found node to remove
186 sllnode<ModelAction *> * llnodeprev = llnode->prev;
187 sllnode<ModelAction *> * llnodenext = llnode->next;
188 if (llnodeprev != NULL) {
189 llnodeprev->next = llnodenext;
193 if (llnodenext != NULL) {
194 llnodenext->prev = llnodeprev;
199 //see if previous node has same clock as us...
200 if (llnodeprev->val->get_seq_number() == clock) {
201 ptr->children[index] = reinterpret_cast<allnode *>(((uintptr_t)llnodeprev) | ISACT);
203 //remove ourselves and go up tree
204 ptr->children[index] = NULL;
212 llnode = llnode->prev;
214 } while(llnode != NULL && llnode->val->get_seq_number() == clock);
215 //node not found in list... no deletion
218 } else if (tmp == NULL) {
222 shiftbits -= ALLBITS;
227 void actionlist::clear() {
228 for(uint i = 0;i < ALLNODESIZE;i++) {
229 if (root.children[i] != NULL) {
230 delete root.children[i];
231 root.children[i] = NULL;
235 while(head != NULL) {
236 sllnode<ModelAction *> *tmp=head->next;
246 bool actionlist::isEmpty() {
247 return root.count == 0;