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 sllnode<ModelAction *> * llnodeprev = ptr->findPrev(clock);
108 if (llnodeprev != NULL) {
109 llnode->next = llnodeprev->next;
110 llnode->prev = llnodeprev;
112 //see if we are the new tail
113 if (llnode->next != NULL)
114 llnode->next->prev = llnode;
117 llnodeprev->next = llnode;
119 //We are the begining
125 //we are the first node
131 ptr->children[index] = reinterpret_cast<allnode *>(((uintptr_t) llnode) | ISACT);
133 //need to find next link
136 //handle case where something else is here
138 sllnode<ModelAction *> * llnodeprev = reinterpret_cast<sllnode<ModelAction *>*>(((uintptr_t) tmp) & ACTMASK);
139 llnode->next = llnodeprev->next;
140 llnode->prev = llnodeprev;
141 if (llnode->next != NULL)
142 llnode->next->prev = llnode;
145 llnodeprev->next = llnode;
146 ptr->children[index] = reinterpret_cast<allnode *>(((uintptr_t) llnode) | ISACT);
149 } else if (tmp == NULL) {
151 ptr->children[index] = tmp;
155 shiftbits -= ALLBITS;
161 void decrementCount(allnode * ptr) {
163 if (ptr->count == 0) {
164 if (ptr->parent != NULL) {
165 for(uint i=0;i<ALLNODESIZE;i++) {
166 if (ptr->parent->children[i]==ptr) {
167 ptr->parent->children[i] = NULL;
168 decrementCount(ptr->parent);
176 void actionlist::removeAction(ModelAction * act) {
177 int shiftbits = MODELCLOCKBITS - ALLBITS;
178 modelclock_t clock = act->get_seq_number();
179 allnode * ptr = &root;
181 int index = (clock >> shiftbits) & ALLMASK;
182 allnode * tmp = ptr->children[index];
183 if (shiftbits == 0) {
188 sllnode<ModelAction *> * llnode = reinterpret_cast<sllnode<ModelAction *> *>(((uintptr_t) tmp) & ACTMASK);
191 if (llnode->val == act) {
192 //found node to remove
193 sllnode<ModelAction *> * llnodeprev = llnode->prev;
194 sllnode<ModelAction *> * llnodenext = llnode->next;
195 if (llnodeprev != NULL) {
196 llnodeprev->next = llnodenext;
200 if (llnodenext != NULL) {
201 llnodenext->prev = llnodeprev;
206 //see if previous node has same clock as us...
207 if (llnodeprev->val->get_seq_number() == clock) {
208 ptr->children[index] = reinterpret_cast<allnode *>(((uintptr_t)llnodeprev) | ISACT);
210 //remove ourselves and go up tree
211 ptr->children[index] = NULL;
219 llnode = llnode->prev;
221 } while(llnode != NULL && llnode->val->get_seq_number() == clock);
222 //node not found in list... no deletion
225 } else if (tmp == NULL) {
229 shiftbits -= ALLBITS;
234 void actionlist::clear() {
235 for(uint i = 0;i < ALLNODESIZE;i++) {
236 if (root.children[i] != NULL) {
237 delete root.children[i];
238 root.children[i] = NULL;
242 while(head != NULL) {
243 sllnode<ModelAction *> *tmp=head->next;
253 bool actionlist::isEmpty() {
254 return root.count == 0;