aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_container_heap.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2009-09-22 21:57:17 +0000
committerNathan S. Evans <evans@in.tum.de>2009-09-22 21:57:17 +0000
commitc04768147bc897cfafb343aeeb02221ecd086795 (patch)
treef5c59f607de670e8ebe6de3c551eda44b4032de1 /src/util/test_container_heap.c
parent272d1eccc183b8cec9f5bf823afbbeac02087dbc (diff)
downloadgnunet-c04768147bc897cfafb343aeeb02221ecd086795.tar.gz
gnunet-c04768147bc897cfafb343aeeb02221ecd086795.zip
heap merge from .8, fixed testcase
Diffstat (limited to 'src/util/test_container_heap.c')
-rw-r--r--src/util/test_container_heap.c92
1 files changed, 36 insertions, 56 deletions
diff --git a/src/util/test_container_heap.c b/src/util/test_container_heap.c
index 84f992686..9e6a29ea4 100644
--- a/src/util/test_container_heap.c
+++ b/src/util/test_container_heap.c
@@ -20,94 +20,74 @@
20 20
21/** 21/**
22 * @author Nathan Evans 22 * @author Nathan Evans
23 * @file util/containers/heaptest.c 23 * @file util/test_container_heap.c
24 * @brief Test of heap operations 24 * @brief Test of heap operations
25 */ 25 */
26 26
27#include "gnunet_util.h" 27#include "platform.h"
28#include "gnunet_util_containers.h" 28#include "gnunet_common.h"
29#include "dv.h" 29#include "gnunet_container_lib.h"
30
31struct TestItem
32{
33 unsigned int cost;
34};
30 35
31static int 36static int
32iterator_callback (void *element, GNUNET_CONTAINER_HeapCost cost, 37iterator_callback (void *cls, void *element, GNUNET_CONTAINER_HeapCost cost)
33 struct GNUNET_CONTAINER_Heap *root, void *cls)
34{ 38{
35 struct GNUNET_dv_neighbor *node; 39 struct TestItem *node;
36 node = (struct GNUNET_dv_neighbor *) element; 40 node = (struct TestItem *) element;
41#ifdef VERBOSE
37 fprintf (stdout, "%d\n", node->cost); 42 fprintf (stdout, "%d\n", node->cost);
38 //fprintf (stdout, "%d\n", ((struct GNUNET_dv_neighbor *)element)->cost); 43#endif
39 44
40 return GNUNET_OK; 45 return GNUNET_OK;
41} 46}
42 47
43
44int 48int
45main (int argc, char **argv) 49main (int argc, char **argv)
46{ 50{
47 struct GNUNET_CONTAINER_Heap *myHeap; 51 struct GNUNET_CONTAINER_Heap *myHeap;
48 struct GNUNET_dv_neighbor *neighbor1; 52 struct TestItem neighbor1;
49 struct GNUNET_dv_neighbor *neighbor2; 53 struct TestItem neighbor2;
50 struct GNUNET_dv_neighbor *neighbor3; 54 struct TestItem neighbor3;
51 struct GNUNET_dv_neighbor *neighbor4; 55 struct TestItem neighbor4;
52 struct GNUNET_dv_neighbor *neighbor5; 56 struct TestItem neighbor5;
53 struct GNUNET_dv_neighbor *neighbor6; 57 struct TestItem neighbor6;
54 58
55 GNUNET_log_setup ("test-container-heap", "WARNING", NULL); 59 GNUNET_log_setup ("test-container-heap", "WARNING", NULL);
56 60
57 myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); 61 myHeap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
58 62
59 neighbor1 = malloc (sizeof (struct GNUNET_dv_neighbor)); 63 neighbor1.cost = 60;
60 neighbor2 = malloc (sizeof (struct GNUNET_dv_neighbor)); 64 neighbor2.cost = 50;
61 neighbor3 = malloc (sizeof (struct GNUNET_dv_neighbor)); 65 neighbor3.cost = 70;
62 neighbor4 = malloc (sizeof (struct GNUNET_dv_neighbor)); 66 neighbor4.cost = 120;
63 neighbor5 = malloc (sizeof (struct GNUNET_dv_neighbor)); 67 neighbor5.cost = 100;
64 neighbor6 = malloc (sizeof (struct GNUNET_dv_neighbor)); 68 neighbor6.cost = 30;
65
66 neighbor1->cost = 60;
67 neighbor2->cost = 50;
68 neighbor3->cost = 70;
69 neighbor4->cost = 120;
70 neighbor5->cost = 100;
71 neighbor6->cost = 30;
72 69
73 GNUNET_CONTAINER_heap_insert (myHeap, neighbor1, neighbor1->cost); 70 GNUNET_CONTAINER_heap_insert (myHeap, &neighbor1, neighbor1.cost);
74 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); 71 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
75 72 GNUNET_CONTAINER_heap_insert (myHeap, &neighbor2, neighbor2.cost);
76 fprintf (stdout, "\n");
77 GNUNET_CONTAINER_heap_insert (myHeap, neighbor2, neighbor2->cost);
78
79 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); 73 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
80 fprintf (stdout, "\n"); 74 GNUNET_CONTAINER_heap_insert (myHeap, &neighbor3, neighbor3.cost);
81 GNUNET_CONTAINER_heap_insert (myHeap, neighbor3, neighbor3->cost);
82
83 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); 75 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
84 fprintf (stdout, "\n"); 76 GNUNET_CONTAINER_heap_insert (myHeap, &neighbor4, neighbor4.cost);
85 GNUNET_CONTAINER_heap_insert (myHeap, neighbor4, neighbor4->cost);
86
87 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); 77 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
88 fprintf (stdout, "\n"); 78 GNUNET_CONTAINER_heap_insert (myHeap, &neighbor5, neighbor5.cost);
89 GNUNET_CONTAINER_heap_insert (myHeap, neighbor5, neighbor5->cost);
90
91 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); 79 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
92 fprintf (stdout, "\n"); 80 GNUNET_CONTAINER_heap_insert (myHeap, &neighbor6, neighbor6.cost);
93 GNUNET_CONTAINER_heap_insert (myHeap, neighbor6, neighbor6->cost);
94
95 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); 81 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
96 fprintf (stdout, "\n"); 82 GNUNET_CONTAINER_heap_remove_node (myHeap, &neighbor5);
97 GNUNET_CONTAINER_heap_remove_node (myHeap, neighbor5);
98
99 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); 83 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
100 fprintf (stdout, "\n");
101 GNUNET_CONTAINER_heap_remove_root (myHeap); 84 GNUNET_CONTAINER_heap_remove_root (myHeap);
102
103 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); 85 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
104 fprintf (stdout, "\n"); 86 GNUNET_CONTAINER_heap_update_cost (myHeap, &neighbor6, 200);
105 GNUNET_CONTAINER_heap_update_cost (myHeap, neighbor6, 200);
106
107 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL); 87 GNUNET_CONTAINER_heap_iterate (myHeap, iterator_callback, NULL);
108 fprintf (stdout, "\n");
109 GNUNET_CONTAINER_heap_destroy (myHeap); 88 GNUNET_CONTAINER_heap_destroy (myHeap);
89
110 return 0; 90 return 0;
111} 91}
112 92
113/* end of heaptest.c */ 93/* end of test_container_heap.c */