2 This file is part of GNUnet.
3 (C) 2008 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @author Nathan Evans
23 * @file util/test_container_heap.c
24 * @brief Test of heap operations
28 #include "gnunet_common.h"
29 #include "gnunet_container_lib.h"
37 iterator_callback (void *cls, void *element, GNUNET_CONTAINER_HeapCost cost)
39 struct TestItem *node;
40 node = (struct TestItem *) element;
42 fprintf (stdout, "%d\n", node->cost);
49 main (int argc, char **argv)
51 struct GNUNET_CONTAINER_Heap *myHeap;
52 struct TestItem neighbor1;
53 struct TestItem neighbor2;
54 struct TestItem neighbor3;
55 struct TestItem neighbor4;
56 struct TestItem neighbor5;
57 struct TestItem neighbor6;
59 GNUNET_log_setup ("test-container-heap", "WARNING", NULL);
61 myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
70 GNUNET_CONTAINER_heap_insert (myHeap, &neighbor1, neighbor1.cost);
71 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
72 GNUNET_CONTAINER_heap_insert (myHeap, &neighbor2, neighbor2.cost);
73 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
74 GNUNET_CONTAINER_heap_insert (myHeap, &neighbor3, neighbor3.cost);
75 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
76 GNUNET_CONTAINER_heap_insert (myHeap, &neighbor4, neighbor4.cost);
77 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
78 GNUNET_CONTAINER_heap_insert (myHeap, &neighbor5, neighbor5.cost);
79 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
80 GNUNET_CONTAINER_heap_insert (myHeap, &neighbor6, neighbor6.cost);
81 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
82 GNUNET_CONTAINER_heap_remove_node (myHeap, &neighbor5);
83 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
84 GNUNET_CONTAINER_heap_remove_root (myHeap);
85 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
86 GNUNET_CONTAINER_heap_update_cost (myHeap, &neighbor6, 200);
87 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
88 GNUNET_CONTAINER_heap_destroy (myHeap);
93 /* end of test_container_heap.c */