diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-03-11 16:58:27 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-03-11 16:58:27 +0000 |
commit | 562b33143ee9fa431a68ea6741e4feb3ba388f83 (patch) | |
tree | 6318eb2c56ff76730708a4791804842c63cf1f81 /src/util/container_heap.c | |
parent | 64821d4ae43b03b30de3dd136137598c0d5a2ab2 (diff) | |
download | gnunet-562b33143ee9fa431a68ea6741e4feb3ba388f83.tar.gz gnunet-562b33143ee9fa431a68ea6741e4feb3ba388f83.zip |
changing heap remove node api to not pass heap; more fs hacking
Diffstat (limited to 'src/util/container_heap.c')
-rw-r--r-- | src/util/container_heap.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/util/container_heap.c b/src/util/container_heap.c index 7cd30a0a7..c332cdd63 100644 --- a/src/util/container_heap.c +++ b/src/util/container_heap.c | |||
@@ -37,6 +37,11 @@ | |||
37 | struct GNUNET_CONTAINER_HeapNode | 37 | struct GNUNET_CONTAINER_HeapNode |
38 | { | 38 | { |
39 | /** | 39 | /** |
40 | * Heap this node belongs to. | ||
41 | */ | ||
42 | struct GNUNET_CONTAINER_Heap *heap; | ||
43 | |||
44 | /** | ||
40 | * Parent node. | 45 | * Parent node. |
41 | */ | 46 | */ |
42 | struct GNUNET_CONTAINER_HeapNode *parent; | 47 | struct GNUNET_CONTAINER_HeapNode *parent; |
@@ -340,6 +345,7 @@ GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, | |||
340 | struct GNUNET_CONTAINER_HeapNode *node; | 345 | struct GNUNET_CONTAINER_HeapNode *node; |
341 | 346 | ||
342 | node = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_HeapNode)); | 347 | node = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_HeapNode)); |
348 | node->heap = heap; | ||
343 | node->element = element; | 349 | node->element = element; |
344 | node->cost = cost; | 350 | node->cost = cost; |
345 | heap->size++; | 351 | heap->size++; |
@@ -405,10 +411,10 @@ GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap) | |||
405 | * 'size' field of the tree. | 411 | * 'size' field of the tree. |
406 | */ | 412 | */ |
407 | static void | 413 | static void |
408 | remove_node (struct GNUNET_CONTAINER_Heap *heap, | 414 | remove_node (struct GNUNET_CONTAINER_HeapNode *node) |
409 | struct GNUNET_CONTAINER_HeapNode *node) | ||
410 | { | 415 | { |
411 | struct GNUNET_CONTAINER_HeapNode *ancestor; | 416 | struct GNUNET_CONTAINER_HeapNode *ancestor; |
417 | struct GNUNET_CONTAINER_Heap *heap = node->heap; | ||
412 | 418 | ||
413 | /* update 'size' of the ancestors */ | 419 | /* update 'size' of the ancestors */ |
414 | ancestor = node; | 420 | ancestor = node; |
@@ -471,20 +477,20 @@ remove_node (struct GNUNET_CONTAINER_Heap *heap, | |||
471 | /** | 477 | /** |
472 | * Removes a node from the heap. | 478 | * Removes a node from the heap. |
473 | * | 479 | * |
474 | * @param heap heap to modify | ||
475 | * @param node node to remove | 480 | * @param node node to remove |
476 | * @return element data stored at the node | 481 | * @return element data stored at the node |
477 | */ | 482 | */ |
478 | void * | 483 | void * |
479 | GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_Heap *heap, | 484 | GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node) |
480 | struct GNUNET_CONTAINER_HeapNode *node) | ||
481 | { | 485 | { |
482 | void *ret; | 486 | void *ret; |
483 | 487 | struct GNUNET_CONTAINER_Heap *heap; | |
488 | |||
489 | heap = node->heap; | ||
484 | CHECK (heap->root); | 490 | CHECK (heap->root); |
485 | if (heap->walk_pos == node) | 491 | if (heap->walk_pos == node) |
486 | (void) GNUNET_CONTAINER_heap_walk_get_next (heap); | 492 | (void) GNUNET_CONTAINER_heap_walk_get_next (heap); |
487 | remove_node (heap, node); | 493 | remove_node (node); |
488 | heap->size--; | 494 | heap->size--; |
489 | ret = node->element; | 495 | ret = node->element; |
490 | if (heap->walk_pos == node) | 496 | if (heap->walk_pos == node) |
@@ -518,7 +524,7 @@ GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, | |||
518 | (heap->size == heap->root->tree_size + 1) ); | 524 | (heap->size == heap->root->tree_size + 1) ); |
519 | CHECK (heap->root); | 525 | CHECK (heap->root); |
520 | #endif | 526 | #endif |
521 | remove_node (heap, node); | 527 | remove_node (node); |
522 | #if DEBUG | 528 | #if DEBUG |
523 | CHECK (heap->root); | 529 | CHECK (heap->root); |
524 | GNUNET_assert ( ( (heap->size == 1) && | 530 | GNUNET_assert ( ( (heap->size == 1) && |