diff options
Diffstat (limited to 'litmus/binheap.c')
-rw-r--r-- | litmus/binheap.c | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/litmus/binheap.c b/litmus/binheap.c index f76260e64b0b..22feea614e50 100644 --- a/litmus/binheap.c +++ b/litmus/binheap.c | |||
@@ -1,5 +1,7 @@ | |||
1 | #include <litmus/binheap.h> | 1 | #include <litmus/binheap.h> |
2 | 2 | ||
3 | //extern void dump_node_data(struct binheap_node* parent, struct binheap_node* child); | ||
4 | //extern void dump_node_data2(struct binheap_handle *handle, struct binheap_node* bad_node); | ||
3 | 5 | ||
4 | int binheap_is_in_this_heap(struct binheap_node *node, | 6 | int binheap_is_in_this_heap(struct binheap_node *node, |
5 | struct binheap_handle* heap) | 7 | struct binheap_handle* heap) |
@@ -29,6 +31,11 @@ static void __update_ref(struct binheap_node *parent, | |||
29 | static void __binheap_swap(struct binheap_node *parent, | 31 | static void __binheap_swap(struct binheap_node *parent, |
30 | struct binheap_node *child) | 32 | struct binheap_node *child) |
31 | { | 33 | { |
34 | // if(parent == BINHEAP_POISON || child == BINHEAP_POISON) { | ||
35 | // dump_node_data(parent, child); | ||
36 | // BUG(); | ||
37 | // } | ||
38 | |||
32 | swap(parent->data, child->data); | 39 | swap(parent->data, child->data); |
33 | __update_ref(parent, child); | 40 | __update_ref(parent, child); |
34 | } | 41 | } |
@@ -185,12 +192,24 @@ static void __binheap_bubble_up( | |||
185 | struct binheap_handle *handle, | 192 | struct binheap_handle *handle, |
186 | struct binheap_node *node) | 193 | struct binheap_node *node) |
187 | { | 194 | { |
188 | /* Note: NULL data pointers are used internally for arbitrary delete */ | 195 | //BUG_ON(!binheap_is_in_heap(node)); |
196 | // if(!binheap_is_in_heap(node)) | ||
197 | // { | ||
198 | // dump_node_data2(handle, node); | ||
199 | // BUG(); | ||
200 | // } | ||
201 | |||
189 | while((node->parent != NULL) && | 202 | while((node->parent != NULL) && |
190 | ((node->data == BINHEAP_POISON) /* let BINHEAP_POISON data bubble to the top */ || | 203 | ((node->data == BINHEAP_POISON) /* let BINHEAP_POISON data bubble to the top */ || |
191 | handle->compare(node, node->parent))) { | 204 | handle->compare(node, node->parent))) { |
192 | __binheap_swap(node->parent, node); | 205 | __binheap_swap(node->parent, node); |
193 | node = node->parent; | 206 | node = node->parent; |
207 | |||
208 | // if(!binheap_is_in_heap(node)) | ||
209 | // { | ||
210 | // dump_node_data2(handle, node); | ||
211 | // BUG(); | ||
212 | // } | ||
194 | } | 213 | } |
195 | } | 214 | } |
196 | 215 | ||
@@ -228,6 +247,12 @@ void __binheap_add(struct binheap_node *new_node, | |||
228 | struct binheap_handle *handle, | 247 | struct binheap_handle *handle, |
229 | void *data) | 248 | void *data) |
230 | { | 249 | { |
250 | // if(binheap_is_in_heap(new_node)) | ||
251 | // { | ||
252 | // dump_node_data2(handle, new_node); | ||
253 | // BUG(); | ||
254 | // } | ||
255 | |||
231 | new_node->data = data; | 256 | new_node->data = data; |
232 | new_node->ref = new_node; | 257 | new_node->ref = new_node; |
233 | new_node->ref_ptr = &(new_node->ref); | 258 | new_node->ref_ptr = &(new_node->ref); |
@@ -284,6 +309,12 @@ void __binheap_delete_root(struct binheap_handle *handle, | |||
284 | { | 309 | { |
285 | struct binheap_node *root = handle->root; | 310 | struct binheap_node *root = handle->root; |
286 | 311 | ||
312 | // if(!binheap_is_in_heap(container)) | ||
313 | // { | ||
314 | // dump_node_data2(handle, container); | ||
315 | // BUG(); | ||
316 | // } | ||
317 | |||
287 | if(root != container) { | 318 | if(root != container) { |
288 | /* coalesce */ | 319 | /* coalesce */ |
289 | __binheap_swap_safe(handle, root, container); | 320 | __binheap_swap_safe(handle, root, container); |
@@ -366,6 +397,18 @@ void __binheap_delete(struct binheap_node *node_to_delete, | |||
366 | struct binheap_node *target = node_to_delete->ref; | 397 | struct binheap_node *target = node_to_delete->ref; |
367 | void *temp_data = target->data; | 398 | void *temp_data = target->data; |
368 | 399 | ||
400 | // if(!binheap_is_in_heap(node_to_delete)) | ||
401 | // { | ||
402 | // dump_node_data2(handle, node_to_delete); | ||
403 | // BUG(); | ||
404 | // } | ||
405 | // | ||
406 | // if(!binheap_is_in_heap(target)) | ||
407 | // { | ||
408 | // dump_node_data2(handle, target); | ||
409 | // BUG(); | ||
410 | // } | ||
411 | |||
369 | /* temporarily set data to null to allow node to bubble up to the top. */ | 412 | /* temporarily set data to null to allow node to bubble up to the top. */ |
370 | target->data = BINHEAP_POISON; | 413 | target->data = BINHEAP_POISON; |
371 | 414 | ||
@@ -373,7 +416,7 @@ void __binheap_delete(struct binheap_node *node_to_delete, | |||
373 | __binheap_delete_root(handle, node_to_delete); | 416 | __binheap_delete_root(handle, node_to_delete); |
374 | 417 | ||
375 | node_to_delete->data = temp_data; /* restore node data pointer */ | 418 | node_to_delete->data = temp_data; /* restore node data pointer */ |
376 | node_to_delete->parent = BINHEAP_POISON; /* poison the node */ | 419 | //node_to_delete->parent = BINHEAP_POISON; /* poison the node */ |
377 | } | 420 | } |
378 | 421 | ||
379 | /** | 422 | /** |
@@ -383,5 +426,18 @@ void __binheap_decrease(struct binheap_node *orig_node, | |||
383 | struct binheap_handle *handle) | 426 | struct binheap_handle *handle) |
384 | { | 427 | { |
385 | struct binheap_node *target = orig_node->ref; | 428 | struct binheap_node *target = orig_node->ref; |
429 | |||
430 | // if(!binheap_is_in_heap(orig_node)) | ||
431 | // { | ||
432 | // dump_node_data2(handle, orig_node); | ||
433 | // BUG(); | ||
434 | // } | ||
435 | // | ||
436 | // if(!binheap_is_in_heap(target)) | ||
437 | // { | ||
438 | // dump_node_data2(handle, target); | ||
439 | // BUG(); | ||
440 | // } | ||
441 | // | ||
386 | __binheap_bubble_up(handle, target); | 442 | __binheap_bubble_up(handle, target); |
387 | } | 443 | } |