/
fine-trie.c
909 lines (766 loc) · 26.1 KB
/
fine-trie.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
/* A simple, (reverse) trie. Only for use with 1 thread. */
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include "trie.h"
struct trie_node {
struct trie_node *next; /* parent list */
unsigned int strlen; /* Length of the key */
int32_t ip4_address; /* 4 octets */
struct trie_node *children; /* Sorted list of children */
char key[64]; /* Up to 64 chars */
pthread_mutex_t lock;
pthread_cond_t c;
int waiting;
};
int _insert (const char *string, size_t strlen, int32_t ip4_address,
struct trie_node *node, struct trie_node *parent, struct trie_node *left);
static struct trie_node * root = NULL;
static pthread_mutex_t root_lock;
struct trie_node * new_leaf (const char *string, size_t strlen, int32_t ip4_address) {
struct trie_node *new_node = malloc(sizeof(struct trie_node));
if (!new_node) {
printf ("WARNING: Node memory allocation failed. Results may be bogus.\n");
return NULL;
}
assert(strlen < 64);
assert(strlen > 0);
new_node->next = NULL;
new_node->strlen = strlen;
strncpy(new_node->key, string, strlen);
new_node->key[strlen] = '\0';
new_node->ip4_address = ip4_address;
new_node->children = NULL;
int rv = pthread_mutex_init(&(new_node->lock), NULL);
assert(rv == 0);
rv = pthread_cond_init(&(new_node->c), NULL);
assert(rv == 0);
new_node->waiting = 0;
return new_node;
}
int compare_keys (const char *string1, int len1, const char *string2, int len2, int *pKeylen) {
int keylen, offset1, offset2;
keylen = len1 < len2 ? len1 : len2;
offset1 = len1 - keylen;
offset2 = len2 - keylen;
assert (keylen > 0);
if (pKeylen)
*pKeylen = keylen;
return strncmp(&string1[offset1], &string2[offset2], keylen);
}
void init(int numthreads) {
//Initialization function, set root node to null, initialize the lock we will use for root.
root = NULL;
int rv = pthread_mutex_init(&root_lock, NULL);
assert(rv == 0);
}
/* Recursive helper function.
* Returns a pointer to the node if found.
* Returns ip address of the node... -1 if not found
* Stores an optional pointer to the
* parent, or what should be the parent if not found.
*
* assumes node is locked
* node lock will be released before returning
*
* node should never be null
*/
int32_t _search (struct trie_node *node, const char *string, size_t strlen) {
//This function is always entered by one of the _search functions, this is the HEAVY LIFTER of the searchers.
int keylen, cmp;
int rc;
// First things first, check if we are NULL
// NULL node means something screwed up somewhere.
assert(node != NULL);
if (node == NULL) return -1;
//Strlen must be below 64 characters, this is just a standard of the application
assert(node->strlen < 64);
//Similar to the strlen being below 64 it must be greater than 0
assert(strlen >0);
//Check for substring, we start by comparing the sizes.
cmp = compare_keys(node->key, node->strlen, string, strlen, &keylen);
if (cmp == 0)
{
// Yes, either quit, or recur on the children
// If this key is longer than our search string, the key isn't here
if (node->strlen > keylen)
{
//Unlock the lock we previously acquired in a controller search function
int rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
//return fail code
return -1;
}
else if (strlen > keylen)
{
if(node->children != NULL)
{
// first lock children, then unlock parent to prevent possible
// hand over hand
//acquire childs lock, assert gaurantees we got it or terminates
rc = pthread_mutex_lock(&(node->children->lock));
assert(rc == 0);
//unlock the current nodes lock, this is us moving forward on the search
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
//Recur into the child
return _search(node->children, string, strlen - keylen);
}
else
{
//if there are no children release the lock, return fail code
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return -1;
}
}
else
{
//strlen should be the same length as keylen, assert it, return the IP address of the node
assert (strlen == keylen);
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return node->ip4_address;
}
}
else if (cmp < 0)
{
//cmp returns 0 then we are looking next to us for the node
if(node->next != NULL)
{
// No, look right (the node's key is "less" than the search key)
// hand over hand
//assign the next node
struct trie_node *next = node->next;
//get its lock, release the lock of current node
rc = pthread_mutex_lock(&(next->lock));
assert(rc == 0);
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
//recur the search through the next node
return _search(next, string, strlen);
}
else
{
//not found release lock, return fail.
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return -1;
}
}
else
{
// Quit early
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return -1;
}
}
/* Recursive helper function.
* Returns a pointer to the node if found.
* Returns ip address of the node... -1 if not found
* Stores an optional pointer to the
* parent, or what should be the parent if not found.
*
* assumes node is locked
* node lock will be released before returning
*
* node should never be null
*/
int32_t _search_and_squat(struct trie_node *node, const char *string, size_t strlen, int32_t ip4_address) {
int keylen, cmp;
int rc;
// First things first, check if we are NULL
// this should never happen
assert(node != NULL);
if (node == NULL) return -1;
assert(node->strlen < 64);
assert(strlen >0);
// See if this key is a substring of the string passed in
cmp = compare_keys(node->key, node->strlen, string, strlen, &keylen);
if (cmp == 0)
{
// Yes, either quit, or recur on the children
// If this key is longer than our search string, the key isn't here
if (node->strlen > keylen)
{
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return -1;
}
else if (strlen > keylen)
{
if(node->children != NULL)
{
// first lock children, then unlock parent to prevent possible
// situation where the thread has no locks and children is deleted
rc = pthread_mutex_lock(&(node->children->lock));
assert(rc == 0);
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
// Recur on children list
return _search(node->children, string, strlen - keylen);
}
else
{
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return -1;
}
}
else
{
//here is where squatting block happens, loop through until rv = 1 due to having a max # of squats
int rv = 0;
node->waiting++;
while(!rv)
{
if(node->ip4_address == 0)
{
node->ip4_address = ip4_address;
node->waiting--;
rv = 1;
}
else
{
int waitSuccess = pthread_cond_wait(&(node->c), &(node->lock));
assert(waitSuccess == 0);
}
}
assert (strlen == keylen);
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return 1;
}
}
else if (cmp < 0)
{
if(node->next != NULL)
{
// No, look right (the node's key is "less" than the search key)
// first lock next, then unlock parent to prevent possible
// situation where the thread has no locks and next is deleted
//assign next node, get its lock, return lock of current node
//recur through the next
struct trie_node *next = node->next;
rc = pthread_mutex_lock(&(next->lock));
assert(rc == 0);
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return _search(next, string, strlen);
}
else
{
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return -1;
}
}
else
{
// Quit early
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return -1;
}
}
int search (const char *string, size_t strlen, int32_t *ip4_address) {
//Search Controller
//main thread communicates directly with this and this pushes us where to go.
int32_t found;
int rc;
// Skip strings of length 0
if (strlen == 0)
return 0;
struct trie_node *node = root;
if(node == NULL)
return 0;
rc = pthread_mutex_lock(&(node->lock));
assert(rc == 0);
found = _search(node, string, strlen);
if (found >= 0 && ip4_address)
*ip4_address = found;
return (found >= 0);
}
int search_and_squat (const char *string, size_t strlen, int32_t ip4_address) {
int32_t found;
int rc;
// Skip strings of length 0
if (strlen == 0)
return 0;
// in case the node was removed between trying to insert and squatting
rc = pthread_mutex_lock(&(root_lock));
assert(rc == 0);
if(root != NULL)
{
found = _insert(string, strlen, ip4_address, root, NULL, NULL);
}
else
{
root = new_leaf (string, strlen, ip4_address);
found = 1;
}
rc = pthread_mutex_unlock(&(root_lock));
assert(rc == 0);
while(!found)
{
rc = pthread_mutex_lock(&(root->lock));
assert(rc == 0);
found = _search_and_squat(root, string, strlen, ip4_address);
// in case the node was removed between trying to insert and squatting
if(!found)
{
found = insert(string, strlen, ip4_address);
}
}
return (found >= 0);
}
/* Recursive helper function */
int _insert (const char *string, size_t strlen, int32_t ip4_address,
struct trie_node *node, struct trie_node *parent, struct trie_node *left)
{
int rc;
// assert that this thread has a lock on both parent or left
// whichever is not null
// First things first, check if we are NULL
assert (node != NULL);
// get a lock on node
rc = pthread_mutex_lock(&(node->lock));
assert(rc == 0);
int cmp, keylen;
assert (node->strlen < 64);
assert (node->strlen > 0);
assert (strlen > 0);
// Take the minimum of the two lengths
cmp = compare_keys (node->key, node->strlen, string, strlen, &keylen);
if (cmp == 0) {
// Yes, either quit, or recur on the children
// If this key is longer than our search string, we need to insert
// "above" this node
if (node->strlen > keylen)
{
struct trie_node *new_node;
assert(keylen == strlen);
assert((!parent) || parent->children == node);
new_node = new_leaf (string, strlen, ip4_address);
rc = pthread_mutex_lock(&(new_node->lock));
assert(rc == 0);
node->strlen -= keylen;
new_node->children = node;
assert ((!parent) || (!left));
// should already have a lock on the parent or left node
if (parent)
{
parent->children = new_node;
}
else if (left) {
left->next = new_node;
}
else if ((!parent) || (!left)) {
root = new_node;
}
rc = pthread_mutex_unlock(&(new_node->lock));
assert(rc == 0);
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return 1;
}
else if (strlen > keylen)
{
if (node->children == NULL)
{
struct trie_node *new_node = new_leaf (string, strlen - keylen, ip4_address);
rc = pthread_mutex_lock(&(new_node->lock));
assert(rc == 0);
node->children = new_node;
rc = pthread_mutex_unlock(&(new_node->lock));
assert(rc == 0);
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return 1;
}
else
{
// Recur on children list, store "parent" (loosely defined)
int rv = _insert(string, strlen - keylen, ip4_address, node->children, node, NULL);
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return rv;
}
}
else
{
assert (strlen == keylen);
if (node->ip4_address == 0)
{
node->ip4_address = ip4_address;
// unlock node
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return 1;
}
else
{
// unlock node
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return 0;
}
}
} else
{
/* Is there any common substring? */
int i, cmp2, keylen2, overlap = 0;
for (i = 1; i < keylen; i++) {
cmp2 = compare_keys (&node->key[i], node->strlen - i,
&string[i], strlen - i, &keylen2);
assert (keylen2 > 0);
if (cmp2 == 0)
{
overlap = 1;
break;
}
}
if (overlap) {
// Insert a common parent, recur
struct trie_node *new_node = new_leaf (&string[i], strlen - i, 0);
// lock new node
rc = pthread_mutex_lock(&(new_node->lock));
assert(rc == 0);
int diff = node->strlen - i;
assert ((node->strlen - diff) > 0);
node->strlen -= diff;
new_node->children = node;
assert ((!parent) || (!left));
// TODO get root lock
if (node == root)
{
new_node->next = node->next;
node->next = NULL;
root = new_node;
}
else if (parent)
{
assert(parent->children == node);
new_node->next = NULL;
parent->children = new_node;
}
else if (left)
{
new_node->next = node->next;
node->next = NULL;
left->next = new_node;
}
else if ((!parent) && (!left)) {
// TODO get root lock
root = new_node;
}
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
int rv = _insert(string, i, ip4_address, node, new_node, NULL);
rc = pthread_mutex_unlock(&(new_node->lock));
assert(rc == 0);
return rv;
}
else if (cmp < 0)
{
if (node->next == NULL) {
// Insert here
struct trie_node *new_node = new_leaf (string, strlen, ip4_address);
rc = pthread_mutex_lock(&(new_node->lock));
assert(rc == 0);
node->next = new_node;
rc = pthread_mutex_unlock(&(new_node->lock));
assert(rc == 0);
// unlock node
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return 1;
}
else
{
// No, recur right (the node's key is "greater" than the search key)
// by convention node should be locked and node->next will be locked inside the method
int rv = _insert(string, strlen, ip4_address, node->next, NULL, node);
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return rv;
}
}
else
{
// Insert here
struct trie_node *new_node = new_leaf (string, strlen, ip4_address);
rc = pthread_mutex_lock(&(new_node->lock));
assert(rc == 0);
new_node->next = node;
// TODO get root lock
if (node == root)
{
root = new_node;
}
else if (parent && parent->children == node)
{
parent->children = new_node;
}
rc = pthread_mutex_unlock(&(new_node->lock));
assert(rc == 0);
}
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return 1;
}
}
int insert (const char *string, size_t strlen, int32_t ip4_address) {
// Skip strings of length 0
int rc;
if (strlen == 0)
return 0;
int rv;
// get root lock
rc = pthread_mutex_lock(&(root_lock));
assert(rc == 0);
if (root == NULL) {
root = new_leaf (string, strlen, ip4_address);
rv = 1;
rc = pthread_mutex_unlock(&(root_lock));
assert(rc == 0);
}
else
{
rv = _insert (string, strlen, ip4_address, root, NULL, NULL);
rc = pthread_mutex_unlock(&(root_lock));
assert(rc == 0);
if (!rv && allow_squatting)
{
search_and_squat(string, strlen, ip4_address);
}
}
return rv;
}
/* Recursive helper function.
* Returns a pointer to the node if found.
* Stores an optional pointer to the
* parent, or what should be the parent if not found.
*
* If it returns a node, there will be a lock on that node
*/
struct trie_node *
_delete (struct trie_node *node, const char *string,
size_t strlen) {
int keylen, cmp;
int rc;
// First things first, check if we are NULL
if (node == NULL) return NULL;
// lock the node here,
rc = pthread_mutex_lock(&(node->lock));
assert(rc == 0);
assert(node->strlen < 64);
// See if this key is a substring of the string passed in
cmp = compare_keys (node->key, node->strlen, string, strlen, &keylen);
if (cmp == 0) {
// Yes, either quit, or recur on the children
// If this key is longer than our search string, the key isn't here
if (node->strlen > keylen)
{
// unlock node
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return NULL;
}
else if (strlen > keylen)
{
// found wont be unlocked by this method
struct trie_node *found = _delete(node->children, string, strlen - keylen);
if (found)
{
if(found->waiting > 0 && allow_squatting)
{
pthread_cond_broadcast(&(found->c));
rc = pthread_mutex_unlock(&(found->lock));
assert(rc == 0);
}
else
{
/* If the node doesn't have children, delete it.
* Otherwise, keep it around to find the kids */
if (found->children == NULL && found->ip4_address == 0)
{
// shouldnt need to lock found->next because as long as parent is locked,
// nothing bad should be able to happen to it (check what insert does)
assert(node->children == found);
node->children = found->next;
// unlock found
rc = pthread_mutex_unlock(&(found->lock));
assert(rc == 0);
free(found);
}
else
{
rc = pthread_mutex_unlock(&(found->lock));
assert(rc == 0);
}
}
// unlock found
// TODO get root lock
/* Delete the root node if we empty the tree */
if (node == root && node->children == NULL && node->ip4_address == 0)
{
if(node->waiting > 0 && allow_squatting)
{
pthread_cond_broadcast(&(node->c));
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
}
else
{
root = node->next;
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
free(node);
}
}
// dont unlock node, we are still doing operations on it
return node; /* Recursively delete needless interior nodes */
}
else
{
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return NULL;
}
}
else
{
assert (strlen == keylen);
/* We found it! Clear the ip4 address and return. */
if (node->ip4_address)
{
node->ip4_address = 0;
//TODO lock root
/* Delete the root node if we empty the tree */
if (node == root && node->children == NULL && node->ip4_address == 0)
{
root = node->next;
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
// dont free if waiting > 0
free(node);
return (struct trie_node *) 0x100100; /* XXX: Don't use this pointer for anything except
* comparison with NULL, since the memory is freed.
* Return a "poison" pointer that will probably
* segfault if used.
*/
}
// dont return node, still doing stuff
return node;
}
else
{
/* Just an interior node with no value */
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return NULL;
}
}
}
else if (cmp < 0) {
// No, look right (the node's key is "less" than the search key)
// found should be locked
struct trie_node *found = _delete(node->next, string, strlen);
if (found)
{
if(found->waiting > 0 && allow_squatting)
{
pthread_cond_broadcast(&(found->c));
rc = pthread_mutex_unlock(&(found->lock));
assert(rc == 0);
}
else
{
/* If the node doesn't have children, delete it.
* Otherwise, keep it around to find the kids */
if (found->children == NULL && found->ip4_address == 0)
{
assert(node->next == found);
node->next = found->next;
rc = pthread_mutex_unlock(&(found->lock));
assert(rc == 0);
free(found);
}
else
{
rc = pthread_mutex_unlock(&(found->lock));
assert(rc == 0);
}
}
return node; /* Recursively delete needless interior nodes */
}
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return NULL;
}
else
{
// Quit early
rc = pthread_mutex_unlock(&(node->lock));
assert(rc == 0);
return NULL;
}
}
int delete (const char *string, size_t strlen) {
// Skip strings of length 0
if (strlen == 0)
return 0;
int rc;
rc = pthread_mutex_lock(&root_lock);
assert(rc == 0);
struct trie_node *parent = _delete(root, string, strlen);
rc = pthread_mutex_unlock(&root_lock);
assert(rc == 0);
// release root lock
int rv =(NULL != parent);
if(parent != NULL && parent != ((struct trie_node *) 0x100100))
{
rc = pthread_mutex_unlock(&(parent->lock));
assert(rc == 0);
}
return rv;
}
void _print (struct trie_node *node, int printLevel, int nodePos) {
// printf ("Node at %p. Key %.*s, IP %d. Next %p, Children %p\n",
// node, node->strlen, node->key, node->ip4_address, node->next, node->children);
printf("\nvvvvvvvv - The %d node on Level %d - vvvvvvvvvv\n", nodePos, printLevel);
printf("|Node at: %p\n", node);
printf("|Key: %.*s\n", node->strlen, node->key);
printf("|IP: %d\n", node->ip4_address);
printf("|Next: %p\n", node->next);
printf("|Child: %p\n", node->children);
printf("^^^^^^^^ - The %d node on Level %d - ^^^^^^^^^^\n", nodePos, printLevel);
if (node->children) {
printf("\nvvvvvvvvvvvvvv\n");
printf("!!!Entering next level of trie!!!\n");
printf("vvvvvvvvvvvvvv\n");
// printf("Now on Level %d at Position %d\n", printLevel, nodePos);
_print(node->children, printLevel+1, 0);
}
if (node->next) {
printf("\n>>>>>>>>>>>>>>\n");
printf("!!!Moving to next node of level!!!\n");
printf(">>>>>>>>>>>>>>\n");
//printf("Node on Level %d at Position %d\n", printLevel, nodePos);
_print(node->next, printLevel, nodePos+1);
}
}
void print() {
// TODO get root lock
printf ("Root is at %p\n", root);
struct trie_node *node = root;
// relese root lock
if(node)
{
_print(node,0 ,0);
}
}