Rev 2450 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2450 | Rev 2461 | ||
---|---|---|---|
Line 27... | Line 27... | ||
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include <test.h> |
29 | #include <test.h> |
30 | #include <print.h> |
30 | #include <print.h> |
31 | #include <adt/avl.h> |
31 | #include <adt/avl.h> |
- | 32 | #include <adt/favl.h> |
|
32 | #include <adt/extavl.h> |
33 | #include <adt/extavl.h> |
33 | #include <adt/extavlrel.h> |
34 | #include <adt/extavlrel.h> |
34 | #include <debug.h> |
35 | #include <debug.h> |
35 | #include <arch/types.h> |
36 | #include <arch/types.h> |
36 | #include <arch/cycle.h> |
37 | #include <arch/cycle.h> |
Line 50... | Line 51... | ||
50 | 51 | ||
51 | /* |
52 | /* |
52 | * Wrapper tree data structures. |
53 | * Wrapper tree data structures. |
53 | */ |
54 | */ |
54 | static avltree_t avltree; |
55 | static avltree_t avltree; |
- | 56 | static favltree_t favltree; |
|
55 | static extavltree_t extavltree; |
57 | static extavltree_t extavltree; |
56 | static extavlreltree_t extavlreltree; |
58 | static extavlreltree_t extavlreltree; |
57 | 59 | ||
58 | /* |
60 | /* |
59 | * Slab cache variables. |
61 | * Slab cache variables. |
60 | */ |
62 | */ |
61 | static slab_cache_t *avl_slab; |
63 | static slab_cache_t *avl_slab; |
- | 64 | static slab_cache_t *favl_slab; |
|
62 | static slab_cache_t *extavl_slab; |
65 | static slab_cache_t *extavl_slab; |
63 | static slab_cache_t *extavlrel_slab; |
66 | static slab_cache_t *extavlrel_slab; |
64 | 67 | ||
65 | /* |
68 | /* |
66 | * Head of free nodes' list: |
69 | * Head of free nodes' list: |
67 | */ |
70 | */ |
68 | static avltree_node_t *avl_ffn = NULL; |
71 | static avltree_node_t *avl_ffn = NULL; |
- | 72 | static favltree_node_t *favl_ffn = NULL; |
|
69 | static extavltree_node_t *extavl_ffn = NULL; |
73 | static extavltree_node_t *extavl_ffn = NULL; |
70 | static extavlreltree_node_t *extavlrel_ffn = NULL; |
74 | static extavlreltree_node_t *extavlrel_ffn = NULL; |
71 | 75 | ||
72 | 76 | ||
73 | static void keys_prepare(int node_count, int type) |
77 | static void keys_prepare(int node_count, int type) |
74 | { |
78 | { |
75 | unsigned int i; |
79 | unsigned int i; |
76 | uint16_t s; |
80 | uint16_t s; |
77 | avltree_node_t *a = avl_ffn; |
81 | avltree_node_t *a = avl_ffn; |
- | 82 | favltree_node_t *b = favl_ffn; |
|
78 | extavltree_node_t *b = extavl_ffn; |
83 | extavltree_node_t *c = extavl_ffn; |
79 | extavlreltree_node_t *c = extavlrel_ffn; |
84 | extavlreltree_node_t *d = extavlrel_ffn; |
80 | 85 | ||
81 | switch (type) { |
86 | switch (type) { |
82 | case 0: |
87 | case 0: |
83 | s = (uint16_t) get_cycle(); |
88 | s = (uint16_t) get_cycle(); |
84 | for (i = 0; i < node_count; i++) { |
89 | for (i = 0; i < node_count; i++) { |
85 | a->key = s; |
90 | a->key = s; |
86 | b->key = s; |
91 | b->key = s; |
87 | c->key = s; |
92 | c->key = s; |
- | 93 | d->key = s; |
|
88 | s += GEN_NUM; |
94 | s += GEN_NUM; |
89 | a = a->par; |
95 | a = a->par; |
90 | b = b->par; |
96 | b = b->par; |
91 | c = c->par; |
97 | c = c->par; |
- | 98 | d = d->par; |
|
92 | } |
99 | } |
93 | break; |
100 | break; |
94 | case 1: |
101 | case 1: |
95 | for (i = 1; i <= node_count; i++) { |
102 | for (i = 1; i <= node_count; i++) { |
96 | a->key = i; |
103 | a->key = i; |
97 | b->key = i; |
104 | b->key = i; |
98 | c->key = i; |
105 | c->key = i; |
- | 106 | d->key = i; |
|
99 | a = a->par; |
107 | a = a->par; |
100 | b = b->par; |
108 | b = b->par; |
101 | c = c->par; |
109 | c = c->par; |
- | 110 | d = d->par; |
|
102 | } |
111 | } |
103 | break; |
112 | break; |
104 | case 2: |
113 | case 2: |
105 | for (i = node_count; i > 0; i--) { |
114 | for (i = node_count; i > 0; i--) { |
106 | a->key = i; |
115 | a->key = i; |
107 | b->key = i; |
116 | b->key = i; |
108 | c->key = i; |
117 | c->key = i; |
- | 118 | d->key = i; |
|
109 | a = a->par; |
119 | a = a->par; |
110 | b = b->par; |
120 | b = b->par; |
- | 121 | c = c->par; |
|
111 | c = c->par; |
122 | d = d->par; |
112 | } |
123 | } |
113 | break; |
124 | break; |
114 | } |
125 | } |
115 | } |
126 | } |
116 | 127 | ||
Line 119... | Line 130... | ||
119 | { |
130 | { |
120 | int i; |
131 | int i; |
121 | avltree_node_t *a; |
132 | avltree_node_t *a; |
122 | extavltree_node_t *b; |
133 | extavltree_node_t *b; |
123 | extavlreltree_node_t *c; |
134 | extavlreltree_node_t *c; |
- | 135 | favltree_node_t *d; |
|
124 | 136 | ||
125 | avl_ffn = NULL; |
137 | avl_ffn = NULL; |
- | 138 | favl_ffn = NULL; |
|
126 | extavl_ffn = NULL; |
139 | extavl_ffn = NULL; |
127 | extavlrel_ffn = NULL; |
140 | extavlrel_ffn = NULL; |
128 | 141 | ||
129 | for (i = 0; i < node_count; i++) { |
142 | for (i = 0; i < node_count; i++) { |
130 | a = (avltree_node_t *) slab_alloc(avl_slab,0); |
143 | a = (avltree_node_t *) slab_alloc(avl_slab,0); |
Line 140... | Line 153... | ||
140 | c = (extavlreltree_node_t *) slab_alloc(extavlrel_slab,0); |
153 | c = (extavlreltree_node_t *) slab_alloc(extavlrel_slab,0); |
141 | if (!c) { |
154 | if (!c) { |
142 | printf("Not enough memory to allocate test arrays."); |
155 | printf("Not enough memory to allocate test arrays."); |
143 | return false; |
156 | return false; |
144 | } |
157 | } |
- | 158 | d = (favltree_node_t *) slab_alloc(favl_slab,0); |
|
- | 159 | if (!d) { |
|
- | 160 | printf("Not enough memory to allocate test arrays."); |
|
- | 161 | return false; |
|
- | 162 | } |
|
145 | a->par = avl_ffn; |
163 | a->par = avl_ffn; |
146 | b->par = extavl_ffn; |
164 | b->par = extavl_ffn; |
147 | c->par = extavlrel_ffn; |
165 | c->par = extavlrel_ffn; |
- | 166 | d->par = favl_ffn; |
|
148 | avl_ffn = a; |
167 | avl_ffn = a; |
149 | extavl_ffn = b; |
168 | extavl_ffn = b; |
150 | extavlrel_ffn = c; |
169 | extavlrel_ffn = c; |
- | 170 | favl_ffn = d; |
|
151 | } |
171 | } |
152 | return true; |
172 | return true; |
153 | } |
173 | } |
154 | 174 | ||
155 | static void free_nodes(int node_count) |
175 | static void free_nodes(int node_count) |
156 | { |
176 | { |
157 | int i; |
177 | int i; |
158 | avltree_node_t *a; |
178 | avltree_node_t *a; |
159 | extavltree_node_t *b; |
179 | extavltree_node_t *b; |
160 | extavlreltree_node_t *c; |
180 | extavlreltree_node_t *c; |
- | 181 | favltree_node_t *d; |
|
161 | 182 | ||
162 | for (i = 0; i < node_count; i++) { |
183 | for (i = 0; i < node_count; i++) { |
163 | a = avl_ffn; |
184 | a = avl_ffn; |
164 | b = extavl_ffn; |
185 | b = extavl_ffn; |
165 | c = extavlrel_ffn; |
186 | c = extavlrel_ffn; |
- | 187 | d = favl_ffn; |
|
166 | if (!a || !b || !c) { |
188 | if (!a || !b || !c || !d) { |
167 | printf("Deleted nodes: %d, node count: %d, a: %p, b: %p,c: %p ",i,node_count,a,b,c); |
189 | printf("Deleted nodes: %d, node count: %d, a: %p, b: %p, c: %p, d: %p\n", |
- | 190 | i,node_count,a,b,c,d); |
|
168 | panic("Some nodes have been lost!"); |
191 | panic("Some nodes have been lost!"); |
169 | } |
192 | } |
170 | avl_ffn = avl_ffn->par; |
193 | avl_ffn = avl_ffn->par; |
171 | extavl_ffn = extavl_ffn->par; |
194 | extavl_ffn = extavl_ffn->par; |
172 | extavlrel_ffn = extavlrel_ffn->par; |
195 | extavlrel_ffn = extavlrel_ffn->par; |
- | 196 | favl_ffn = favl_ffn->par; |
|
173 | slab_free(avl_slab,a); |
197 | slab_free(avl_slab,a); |
174 | slab_free(extavl_slab,b); |
198 | slab_free(extavl_slab,b); |
175 | slab_free(extavlrel_slab,c); |
199 | slab_free(extavlrel_slab,c); |
- | 200 | slab_free(favl_slab,d); |
|
176 | } |
201 | } |
177 | } |
202 | } |
178 | 203 | ||
179 | static avltree_node_t *alloc_avltree_node(void) |
204 | static avltree_node_t *alloc_avltree_node(void) |
180 | { |
205 | { |
Line 184... | Line 209... | ||
184 | avl_ffn = avl_ffn->par; |
209 | avl_ffn = avl_ffn->par; |
185 | 210 | ||
186 | return node; |
211 | return node; |
187 | } |
212 | } |
188 | 213 | ||
- | 214 | static favltree_node_t *alloc_favltree_node(void) |
|
- | 215 | { |
|
- | 216 | favltree_node_t *node; |
|
- | 217 | ||
- | 218 | node = favl_ffn; |
|
- | 219 | favl_ffn = favl_ffn->par; |
|
- | 220 | ||
- | 221 | return node; |
|
- | 222 | } |
|
- | 223 | ||
189 | static extavltree_node_t *alloc_extavltree_node(void) |
224 | static extavltree_node_t *alloc_extavltree_node(void) |
190 | { |
225 | { |
191 | extavltree_node_t *node; |
226 | extavltree_node_t *node; |
192 | 227 | ||
193 | node = extavl_ffn; |
228 | node = extavl_ffn; |
Line 211... | Line 246... | ||
211 | { |
246 | { |
212 | node->par = avl_ffn; |
247 | node->par = avl_ffn; |
213 | avl_ffn = node; |
248 | avl_ffn = node; |
214 | } |
249 | } |
215 | 250 | ||
- | 251 | static void free_favltree_node(favltree_node_t *node) |
|
- | 252 | { |
|
- | 253 | node->par = favl_ffn; |
|
- | 254 | favl_ffn = node; |
|
- | 255 | } |
|
- | 256 | ||
216 | static void free_extavltree_node(extavltree_node_t *node) |
257 | static void free_extavltree_node(extavltree_node_t *node) |
217 | { |
258 | { |
218 | node->par = extavl_ffn; |
259 | node->par = extavl_ffn; |
219 | extavl_ffn = node; |
260 | extavl_ffn = node; |
220 | } |
261 | } |
Line 227... | Line 268... | ||
227 | 268 | ||
228 | /** Insert keys of ascending sequence and delete tree deleting root nodes. |
269 | /** Insert keys of ascending sequence and delete tree deleting root nodes. |
229 | */ |
270 | */ |
230 | static void test1(void) |
271 | static void test1(void) |
231 | { |
272 | { |
232 | uint64_t s[3][TEST_COUNT],f[3][TEST_COUNT]; |
273 | uint64_t s[4][TEST_COUNT],f[4][TEST_COUNT]; |
233 | uint64_t ds[3][TEST_COUNT],df[3][TEST_COUNT]; |
274 | uint64_t ds[4][TEST_COUNT],df[4][TEST_COUNT]; |
234 | unsigned int i,ii; |
275 | unsigned int i,ii; |
235 | avltree_node_t *a; |
276 | avltree_node_t *a; |
236 | extavltree_node_t *b; |
277 | extavltree_node_t *b; |
237 | extavlreltree_node_t *c; |
278 | extavlreltree_node_t *c; |
- | 279 | favltree_node_t *d; |
|
238 | 280 | ||
239 | 281 | ||
240 | printf("INSERT nodes with keys of ascending sequence.\n"); |
282 | printf("INSERT nodes with keys of ascending sequence.\n"); |
241 | printf("Nodes:\t\t"); |
283 | printf("Nodes:\t\t"); |
242 | for (ii = 0; ii < TEST_COUNT; ii++) { |
284 | for (ii = 0; ii < TEST_COUNT; ii++) { |
Line 309... | Line 351... | ||
309 | extavlreltree_delete(&extavlreltree,c); |
351 | extavlreltree_delete(&extavlreltree,c); |
310 | free_extavlreltree_node(c); |
352 | free_extavlreltree_node(c); |
311 | } |
353 | } |
312 | 354 | ||
313 | df[2][ii] = get_cycle(); |
355 | df[2][ii] = get_cycle(); |
- | 356 | ||
- | 357 | /* |
|
- | 358 | * FAVL INSERT |
|
- | 359 | */ |
|
- | 360 | s[3][ii] = get_cycle(); |
|
- | 361 | ||
- | 362 | favltree_create(&favltree); |
|
- | 363 | for (i = 0; i < node_count[ii]; i++) { |
|
- | 364 | favltree_insert(&favltree,alloc_favltree_node()); |
|
- | 365 | } |
|
- | 366 | ||
- | 367 | f[3][ii] = get_cycle(); |
|
- | 368 | /* |
|
- | 369 | * FAVL DELETE |
|
- | 370 | */ |
|
- | 371 | ds[3][ii] = get_cycle(); |
|
- | 372 | ||
- | 373 | while ((d = favltree.root) != NULL) { |
|
- | 374 | favltree_delete(&favltree,d); |
|
- | 375 | free_favltree_node(d); |
|
- | 376 | } |
|
- | 377 | ||
- | 378 | df[3][ii] = get_cycle(); |
|
314 | } |
379 | } |
315 | printf("\n----------------------------------------------------------------------------"); |
380 | printf("\n----------------------------------------------------------------------------"); |
316 | printf("\nAVL\t\t"); |
381 | printf("\nAVL\t\t"); |
317 | for (ii = 0; ii < TEST_COUNT; ii++) |
382 | for (ii = 0; ii < TEST_COUNT; ii++) |
318 | printf("%20llu",f[0][ii]-s[0][ii]); |
383 | printf("%20llu",f[0][ii]-s[0][ii]); |
- | 384 | printf("\nFAVL\t\t"); |
|
- | 385 | for (ii = 0; ii < TEST_COUNT; ii++) |
|
- | 386 | printf("%20llu",f[3][ii]-s[3][ii]); |
|
319 | printf("\nExtAVL\t\t"); |
387 | printf("\nExtAVL\t\t"); |
320 | for (ii = 0; ii < TEST_COUNT; ii++) |
388 | for (ii = 0; ii < TEST_COUNT; ii++) |
321 | printf("%20llu",f[1][ii]-s[1][ii]); |
389 | printf("%20llu",f[1][ii]-s[1][ii]); |
322 | printf("\nExtAVLrel\t"); |
390 | printf("\nExtAVLrel\t"); |
323 | for (ii = 0; ii < TEST_COUNT; ii++) |
391 | for (ii = 0; ii < TEST_COUNT; ii++) |
Line 330... | Line 398... | ||
330 | printf("%20u",node_count[ii]); |
398 | printf("%20u",node_count[ii]); |
331 | printf("\n----------------------------------------------------------------------------"); |
399 | printf("\n----------------------------------------------------------------------------"); |
332 | printf("\nAVL\t\t"); |
400 | printf("\nAVL\t\t"); |
333 | for (ii = 0; ii < TEST_COUNT; ii++) |
401 | for (ii = 0; ii < TEST_COUNT; ii++) |
334 | printf("%20llu",df[0][ii]-ds[0][ii]); |
402 | printf("%20llu",df[0][ii]-ds[0][ii]); |
- | 403 | printf("\nAVL\t\t"); |
|
- | 404 | for (ii = 0; ii < TEST_COUNT; ii++) |
|
- | 405 | printf("%20llu",df[3][ii]-ds[3][ii]); |
|
335 | printf("\nExtAVL\t\t"); |
406 | printf("\nExtAVL\t\t"); |
336 | for (ii = 0; ii < TEST_COUNT; ii++) |
407 | for (ii = 0; ii < TEST_COUNT; ii++) |
337 | printf("%20llu",df[1][ii]-ds[1][ii]); |
408 | printf("%20llu",df[1][ii]-ds[1][ii]); |
338 | printf("\nExtAVLrel\t"); |
409 | printf("\nExtAVLrel\t"); |
339 | for (ii = 0; ii < TEST_COUNT; ii++) |
410 | for (ii = 0; ii < TEST_COUNT; ii++) |
Line 344... | Line 415... | ||
344 | 415 | ||
345 | /** Insert keys of ascending sequence and delete tree with delete_min functions. |
416 | /** Insert keys of ascending sequence and delete tree with delete_min functions. |
346 | */ |
417 | */ |
347 | static void test2(void) |
418 | static void test2(void) |
348 | { |
419 | { |
349 | uint64_t s[3][TEST_COUNT],f[3][TEST_COUNT]; |
420 | uint64_t s[4][TEST_COUNT],f[4][TEST_COUNT]; |
350 | uint64_t ds[3][TEST_COUNT],df[3][TEST_COUNT]; |
421 | uint64_t ds[4][TEST_COUNT],df[4][TEST_COUNT]; |
351 | unsigned int i,ii; |
422 | unsigned int i,ii; |
352 | avltree_node_t *a; |
423 | avltree_node_t *a; |
353 | extavltree_node_t *b; |
424 | extavltree_node_t *b; |
354 | extavlreltree_node_t *c; |
425 | extavlreltree_node_t *c; |
- | 426 | favltree_node_t *d; |
|
355 | 427 | ||
356 | 428 | ||
357 | printf("INSERT nodes with keys of descending sequence.\n"); |
429 | printf("INSERT nodes with keys of descending sequence.\n"); |
358 | printf("Nodes:\t\t"); |
430 | printf("Nodes:\t\t"); |
359 | for (ii = 0; ii < TEST_COUNT; ii++) { |
431 | for (ii = 0; ii < TEST_COUNT; ii++) { |
Line 428... | Line 500... | ||
428 | extavlreltree_delete_min(&extavlreltree); |
500 | extavlreltree_delete_min(&extavlreltree); |
429 | free_extavlreltree_node(c); |
501 | free_extavlreltree_node(c); |
430 | } |
502 | } |
431 | 503 | ||
432 | df[2][ii] = get_cycle(); |
504 | df[2][ii] = get_cycle(); |
- | 505 | ||
- | 506 | /* |
|
- | 507 | * FAVL INSERT |
|
- | 508 | */ |
|
- | 509 | s[3][ii] = get_cycle(); |
|
- | 510 | ||
- | 511 | favltree_create(&favltree); |
|
- | 512 | for (i = 0; i < node_count[ii]; i++) { |
|
- | 513 | favltree_insert(&favltree,alloc_favltree_node()); |
|
- | 514 | } |
|
- | 515 | ||
- | 516 | f[3][ii] = get_cycle(); |
|
- | 517 | /* |
|
- | 518 | * AVL DELETE |
|
- | 519 | */ |
|
- | 520 | ds[3][ii] = get_cycle(); |
|
- | 521 | ||
- | 522 | while (favltree.root != NULL) { |
|
- | 523 | d = favltree_find_min(&favltree); |
|
- | 524 | favltree_delete_min(&favltree); |
|
- | 525 | free_favltree_node(d); |
|
- | 526 | } |
|
- | 527 | ||
- | 528 | df[3][ii] = get_cycle(); |
|
- | 529 | ||
433 | } |
530 | } |
434 | printf("\n----------------------------------------------------------------------------"); |
531 | printf("\n----------------------------------------------------------------------------"); |
435 | printf("\nAVL\t\t"); |
532 | printf("\nAVL\t\t"); |
436 | for (ii = 0; ii < TEST_COUNT; ii++) |
533 | for (ii = 0; ii < TEST_COUNT; ii++) |
437 | printf("%20llu",f[0][ii]-s[0][ii]); |
534 | printf("%20llu",f[0][ii]-s[0][ii]); |
- | 535 | printf("\nFAVL\t\t"); |
|
- | 536 | for (ii = 0; ii < TEST_COUNT; ii++) |
|
- | 537 | printf("%20llu",f[3][ii]-s[3][ii]); |
|
438 | printf("\nExtAVL\t\t"); |
538 | printf("\nExtAVL\t\t"); |
439 | for (ii = 0; ii < TEST_COUNT; ii++) |
539 | for (ii = 0; ii < TEST_COUNT; ii++) |
440 | printf("%20llu",f[1][ii]-s[1][ii]); |
540 | printf("%20llu",f[1][ii]-s[1][ii]); |
441 | printf("\nExtAVLrel\t"); |
541 | printf("\nExtAVLrel\t"); |
442 | for (ii = 0; ii < TEST_COUNT; ii++) |
542 | for (ii = 0; ii < TEST_COUNT; ii++) |
Line 449... | Line 549... | ||
449 | printf("%20u",node_count[ii]); |
549 | printf("%20u",node_count[ii]); |
450 | printf("\n----------------------------------------------------------------------------"); |
550 | printf("\n----------------------------------------------------------------------------"); |
451 | printf("\nAVL\t\t"); |
551 | printf("\nAVL\t\t"); |
452 | for (ii = 0; ii < TEST_COUNT; ii++) |
552 | for (ii = 0; ii < TEST_COUNT; ii++) |
453 | printf("%20llu",df[0][ii]-ds[0][ii]); |
553 | printf("%20llu",df[0][ii]-ds[0][ii]); |
- | 554 | printf("\nFAVL\t\t"); |
|
- | 555 | for (ii = 0; ii < TEST_COUNT; ii++) |
|
- | 556 | printf("%20llu",df[3][ii]-ds[3][ii]); |
|
454 | printf("\nExtAVL\t\t"); |
557 | printf("\nExtAVL\t\t"); |
455 | for (ii = 0; ii < TEST_COUNT; ii++) |
558 | for (ii = 0; ii < TEST_COUNT; ii++) |
456 | printf("%20llu",df[1][ii]-ds[1][ii]); |
559 | printf("%20llu",df[1][ii]-ds[1][ii]); |
457 | printf("\nExtAVLrel\t"); |
560 | printf("\nExtAVLrel\t"); |
458 | for (ii = 0; ii < TEST_COUNT; ii++) |
561 | for (ii = 0; ii < TEST_COUNT; ii++) |
Line 463... | Line 566... | ||
463 | 566 | ||
464 | /** Insert keys of random sequence and delete tree with delete_min functions. |
567 | /** Insert keys of random sequence and delete tree with delete_min functions. |
465 | */ |
568 | */ |
466 | static void test3(void) |
569 | static void test3(void) |
467 | { |
570 | { |
468 | uint64_t s[3][TEST_COUNT],f[3][TEST_COUNT]; |
571 | uint64_t s[4][TEST_COUNT],f[4][TEST_COUNT]; |
469 | uint64_t ds[3][TEST_COUNT],df[3][TEST_COUNT]; |
572 | uint64_t ds[4][TEST_COUNT],df[4][TEST_COUNT]; |
470 | unsigned int i,ii; |
573 | unsigned int i,ii; |
471 | avltree_node_t *a; |
574 | avltree_node_t *a; |
472 | extavltree_node_t *b; |
575 | extavltree_node_t *b; |
473 | extavlreltree_node_t *c; |
576 | extavlreltree_node_t *c; |
- | 577 | favltree_node_t *d; |
|
474 | 578 | ||
475 | 579 | ||
476 | printf("INSERT nodes with keys of random sequence 1-65536.\n"); |
580 | printf("INSERT nodes with keys of random sequence 1-65536.\n"); |
477 | printf("Nodes:\t\t"); |
581 | printf("Nodes:\t\t"); |
478 | for (ii = 0; ii < TEST_COUNT; ii++) { |
582 | for (ii = 0; ii < TEST_COUNT; ii++) { |
Line 547... | Line 651... | ||
547 | extavlreltree_delete_min(&extavlreltree); |
651 | extavlreltree_delete_min(&extavlreltree); |
548 | free_extavlreltree_node(c); |
652 | free_extavlreltree_node(c); |
549 | } |
653 | } |
550 | 654 | ||
551 | df[2][ii] = get_cycle(); |
655 | df[2][ii] = get_cycle(); |
- | 656 | ||
- | 657 | /* |
|
- | 658 | * FAVL INSERT |
|
- | 659 | */ |
|
- | 660 | s[3][ii] = get_cycle(); |
|
- | 661 | ||
- | 662 | favltree_create(&favltree); |
|
- | 663 | for (i = 0; i < node_count[ii]; i++) { |
|
- | 664 | favltree_insert(&favltree,alloc_favltree_node()); |
|
- | 665 | } |
|
- | 666 | ||
- | 667 | f[3][ii] = get_cycle(); |
|
- | 668 | /* |
|
- | 669 | * AVL DELETE |
|
- | 670 | */ |
|
- | 671 | ds[3][ii] = get_cycle(); |
|
- | 672 | ||
- | 673 | while (favltree.root != NULL) { |
|
- | 674 | d = favltree_find_min(&favltree); |
|
- | 675 | favltree_delete_min(&favltree); |
|
- | 676 | free_favltree_node(d); |
|
- | 677 | } |
|
- | 678 | ||
- | 679 | df[3][ii] = get_cycle(); |
|
552 | } |
680 | } |
553 | printf("\n----------------------------------------------------------------------------"); |
681 | printf("\n----------------------------------------------------------------------------"); |
554 | printf("\nAVL\t\t"); |
682 | printf("\nAVL\t\t"); |
555 | for (ii = 0; ii < TEST_COUNT; ii++) |
683 | for (ii = 0; ii < TEST_COUNT; ii++) |
556 | printf("%20llu",f[0][ii]-s[0][ii]); |
684 | printf("%20llu",f[0][ii]-s[0][ii]); |
- | 685 | printf("\nFAVL\t\t"); |
|
- | 686 | for (ii = 0; ii < TEST_COUNT; ii++) |
|
- | 687 | printf("%20llu",f[3][ii]-s[3][ii]); |
|
557 | printf("\nExtAVL\t\t"); |
688 | printf("\nExtAVL\t\t"); |
558 | for (ii = 0; ii < TEST_COUNT; ii++) |
689 | for (ii = 0; ii < TEST_COUNT; ii++) |
559 | printf("%20llu",f[1][ii]-s[1][ii]); |
690 | printf("%20llu",f[1][ii]-s[1][ii]); |
560 | printf("\nExtAVLrel\t"); |
691 | printf("\nExtAVLrel\t"); |
561 | for (ii = 0; ii < TEST_COUNT; ii++) |
692 | for (ii = 0; ii < TEST_COUNT; ii++) |
Line 568... | Line 699... | ||
568 | printf("%20u",node_count[ii]); |
699 | printf("%20u",node_count[ii]); |
569 | printf("\n----------------------------------------------------------------------------"); |
700 | printf("\n----------------------------------------------------------------------------"); |
570 | printf("\nAVL\t\t"); |
701 | printf("\nAVL\t\t"); |
571 | for (ii = 0; ii < TEST_COUNT; ii++) |
702 | for (ii = 0; ii < TEST_COUNT; ii++) |
572 | printf("%20llu",df[0][ii]-ds[0][ii]); |
703 | printf("%20llu",df[0][ii]-ds[0][ii]); |
- | 704 | printf("\nFAVL\t\t"); |
|
- | 705 | for (ii = 0; ii < TEST_COUNT; ii++) |
|
- | 706 | printf("%20llu",df[3][ii]-ds[3][ii]); |
|
573 | printf("\nExtAVL\t\t"); |
707 | printf("\nExtAVL\t\t"); |
574 | for (ii = 0; ii < TEST_COUNT; ii++) |
708 | for (ii = 0; ii < TEST_COUNT; ii++) |
575 | printf("%20llu",df[1][ii]-ds[1][ii]); |
709 | printf("%20llu",df[1][ii]-ds[1][ii]); |
576 | printf("\nExtAVLrel\t"); |
710 | printf("\nExtAVLrel\t"); |
577 | for (ii = 0; ii < TEST_COUNT; ii++) |
711 | for (ii = 0; ii < TEST_COUNT; ii++) |
Line 582... | Line 716... | ||
582 | 716 | ||
583 | /** Simulating timeout mechanismus with insert and delete_min operations. |
717 | /** Simulating timeout mechanismus with insert and delete_min operations. |
584 | */ |
718 | */ |
585 | static void test4(void) |
719 | static void test4(void) |
586 | { |
720 | { |
587 | uint64_t s[3][TEST_COUNT],f[3][TEST_COUNT]; |
721 | uint64_t s[4][TEST_COUNT],f[4][TEST_COUNT]; |
588 | unsigned int i,ii; |
722 | unsigned int i,ii; |
589 | avltree_node_t *a; |
723 | avltree_node_t *a; |
590 | extavltree_node_t *b; |
724 | extavltree_node_t *b; |
591 | extavlreltree_node_t *c; |
725 | extavlreltree_node_t *c; |
- | 726 | favltree_node_t *d; |
|
592 | uint64_t r; |
727 | uint64_t r; |
593 | uint16_t rr; |
728 | uint16_t rr; |
594 | unsigned int mn,nc; |
729 | unsigned int mn,nc; |
595 | 730 | ||
596 | 731 | ||
Line 640... | Line 775... | ||
640 | } |
775 | } |
641 | 776 | ||
642 | f[0][ii] = get_cycle(); |
777 | f[0][ii] = get_cycle(); |
643 | 778 | ||
644 | /* |
779 | /* |
- | 780 | * FAVL |
|
- | 781 | */ |
|
- | 782 | rr = r; |
|
- | 783 | nc = 0; |
|
- | 784 | s[3][ii] = get_cycle(); |
|
- | 785 | ||
- | 786 | avltree_create(&avltree); |
|
- | 787 | for (i = 0; i < OPERATION_COUNT; i++) { |
|
- | 788 | if (((rr % mn) <= nc) && nc) { |
|
- | 789 | /* |
|
- | 790 | * Delete min. |
|
- | 791 | */ |
|
- | 792 | d = favltree_find_min(&favltree); |
|
- | 793 | favltree_delete_min(&favltree); |
|
- | 794 | free_favltree_node(d); |
|
- | 795 | nc--; |
|
- | 796 | } else { |
|
- | 797 | /* |
|
- | 798 | * Insert. |
|
- | 799 | */ |
|
- | 800 | d = alloc_favltree_node(); |
|
- | 801 | d->key = rr; |
|
- | 802 | favltree_insert(&favltree,d); |
|
- | 803 | nc++; |
|
- | 804 | } |
|
- | 805 | rr += GEN_NUM; |
|
- | 806 | } |
|
- | 807 | /* |
|
- | 808 | * Delete rest tree. |
|
- | 809 | */ |
|
- | 810 | while (favltree.root != NULL) { |
|
- | 811 | d = favltree_find_min(&favltree); |
|
- | 812 | favltree_delete_min(&favltree); |
|
- | 813 | free_favltree_node(d); |
|
- | 814 | } |
|
- | 815 | ||
- | 816 | f[3][ii] = get_cycle(); |
|
- | 817 | ||
- | 818 | /* |
|
645 | * ExtAVL |
819 | * ExtAVL |
646 | */ |
820 | */ |
647 | rr = r; |
821 | rr = r; |
648 | nc = 0; |
822 | nc = 0; |
649 | s[1][ii] = get_cycle(); |
823 | s[1][ii] = get_cycle(); |
Line 723... | Line 897... | ||
723 | } |
897 | } |
724 | printf("\n----------------------------------------------------------------------------"); |
898 | printf("\n----------------------------------------------------------------------------"); |
725 | printf("\nAVL\t\t"); |
899 | printf("\nAVL\t\t"); |
726 | for (ii = 0; ii < TEST_COUNT; ii++) |
900 | for (ii = 0; ii < TEST_COUNT; ii++) |
727 | printf("%20llu",f[0][ii]-s[0][ii]); |
901 | printf("%20llu",f[0][ii]-s[0][ii]); |
- | 902 | printf("\nFAVL\t\t"); |
|
- | 903 | for (ii = 0; ii < TEST_COUNT; ii++) |
|
- | 904 | printf("%20llu",f[3][ii]-s[3][ii]); |
|
728 | printf("\nExtAVL\t\t"); |
905 | printf("\nExtAVL\t\t"); |
729 | for (ii = 0; ii < TEST_COUNT; ii++) |
906 | for (ii = 0; ii < TEST_COUNT; ii++) |
730 | printf("%20llu",f[1][ii]-s[1][ii]); |
907 | printf("%20llu",f[1][ii]-s[1][ii]); |
731 | printf("\nExtAVLrel\t"); |
908 | printf("\nExtAVLrel\t"); |
732 | for (ii = 0; ii < TEST_COUNT; ii++) |
909 | for (ii = 0; ii < TEST_COUNT; ii++) |
Line 740... | Line 917... | ||
740 | printf("\n\tBenchmark test of timeout data structures: AVL, ExtAVL and ExtAVLrel.\n" |
917 | printf("\n\tBenchmark test of timeout data structures: AVL, ExtAVL and ExtAVLrel.\n" |
741 | "Run test more than once for eliminating possible distortion due to caching!\n\n"); |
918 | "Run test more than once for eliminating possible distortion due to caching!\n\n"); |
742 | 919 | ||
743 | 920 | ||
744 | avl_slab = slab_cache_create("avl_slab",sizeof(avltree_node_t), 0, NULL, NULL, SLAB_CACHE_MAGDEFERRED); |
921 | avl_slab = slab_cache_create("avl_slab",sizeof(avltree_node_t), 0, NULL, NULL, SLAB_CACHE_MAGDEFERRED); |
- | 922 | favl_slab = slab_cache_create("favl_slab",sizeof(favltree_node_t), 0, NULL, NULL, SLAB_CACHE_MAGDEFERRED); |
|
745 | extavl_slab = slab_cache_create("extavl_slab",sizeof(extavltree_node_t), 0, NULL, NULL, SLAB_CACHE_MAGDEFERRED); |
923 | extavl_slab = slab_cache_create("extavl_slab",sizeof(extavltree_node_t), 0, NULL, NULL, SLAB_CACHE_MAGDEFERRED); |
746 | extavlrel_slab = slab_cache_create("extavlrel_slab",sizeof(extavlreltree_node_t), 0, NULL, NULL, SLAB_CACHE_MAGDEFERRED); |
924 | extavlrel_slab = slab_cache_create("extavlrel_slab",sizeof(extavlreltree_node_t), 0, NULL, NULL, SLAB_CACHE_MAGDEFERRED); |
747 | 925 | ||
748 | if (!alloc_nodes(NODE_COUNT)) |
926 | if (!alloc_nodes(NODE_COUNT)) |
749 | return NULL; |
927 | return NULL; |