static print_trie(node_patric *trie, int level) { printf("Level:%d\n", level); printf("Skip:%d\n", trie->skip); printf("Base Pointer:%d\n", trie->base); printf("\n"); if (NULL != trie->left) { print_trie(trie->left, level+1); print_trie(trie->right, level+1); } }
/* Function to close and clean up a task */ void task_close () { print_trie (Head); fflush (FOUT); fflush (FERR); fclose (FOUT); fclose (FERR); free_trie (Head); Free (task); }
/* Recursive Function to print the nodes of a TRIE in in-order fashion */ void print_trie (struct node *node) { int i; if (UInfo) { F_OUT ("%s %d %d\n", UID, Followers, Following); } for (i = 0; i < 10; i++) if (Children[i]) print_trie (Children[i]); }
// Print a trie, for debug purposes static void print_trie(int indent, trie_node_t* trie) { if(trie->replace) { indent_depth(indent); fprintf(stdout, "Replacement: %s\n", trie->replace); } for(int i = 0; i < 256; i++) { if(trie->children[i]) { indent_depth(indent); fprintf(stdout, "Child: %i | %c\n", i, i); print_trie(indent + 1, trie->children[i]); } } }
int main(int argc, char **argv) { nitro_prefix_trie_node *root = NULL; nitro_prefix_trie_search(root, (uint8_t *)"bar", 3, callback, NULL); nitro_prefix_trie_add(&root, (uint8_t *)"bar", 3, NULL); printf("after adding bar ---\n"); print_trie(root, 0); nitro_prefix_trie_add(&root, (uint8_t *)"b", 1, NULL); printf("after adding b ---\n"); print_trie(root, 0); nitro_prefix_trie_add(&root, (uint8_t *)"bark", 4, NULL); printf("after adding bark---\n"); print_trie(root, 0); nitro_prefix_trie_add(&root, (uint8_t *)"baz", 3, NULL); printf("after adding baz---\n"); print_trie(root, 0); printf("search for bark ===\n"); nitro_prefix_trie_search(root, (uint8_t *)"bark", 4, callback, NULL); printf("search for baz ===\n"); nitro_prefix_trie_search(root, (uint8_t *)"baz", 3, callback, NULL); nitro_prefix_trie_del(root, (uint8_t *)"bar", 3, NULL); printf("search for bark (post delete) ===\n"); nitro_prefix_trie_search(root, (uint8_t *)"bark", 4, callback, NULL); return 0; }
int main(int argc, char *argv[]) { static entry_t entry[MAXENTRIES]; int nentry,i,j,k; int nprefs = 0, nbases = 0; int nextfree = 1; base_t *b, btemp; pre_t *p, ptemp; if ((nentry = readlist(argv[1], entry, MAXENTRIES)) < 0) { fprintf(stderr, "Input file too large.\n"); return 1; } xidentrysort(entry, nentry, sizeof(entry_t), compareentries); b = (base_t *) malloc(nentry * sizeof(base_t)); p = (pre_t *) malloc(nentry * sizeof(pre_t)); for (i = 0; i < nentry; i++) { if (i < nentry-1 && isprefix(entry[i], entry[i+1])) { ptemp = (pre_t) malloc(sizeof(struct prerec)); ptemp->len = entry[i]->len; ptemp->pre = entry[i]->pre; /* Update 'pre' for all entries that have this prefix */ for (j = i + 1; j < nentry && isprefix(entry[i], entry[j]); j++) entry[j]->pre = nprefs; p[nprefs++] = ptemp; } else { btemp = (base_t) malloc(sizeof(struct baserec)); btemp->len = entry[i]->len; btemp->str = entry[i]->data; btemp->pre = entry[i]->pre; b[nbases++] = btemp; } } node_patric *root; root = buildpatricia(b, 0, 0, nbases); print_trie(root, 0); }
static void print_trie(nitro_prefix_trie_node *t, int c) { int x; for (x = 0; x < c; x++) { printf(" "); } printf("%s:%d:%d", t->rep, t->length, t->members ? 1 : 0); printf("\n"); int i; for (i = 0; i < 256; i++) { if (t->subs[i]) { for (x = 0; x < c + 1; x++) { printf(" "); } printf("%d:\n", i); print_trie(t->subs[i], c + 2); } } }
void print_trie(Node *root) { if (root == NULL ) { return; } printf("%c", root->val); Node *child = root->children; int branched = 0; if (child != NULL ) { if (child->sibling != NULL ) { branched = 1; } while (child != NULL ) { if (branched == 1) { printf("{"); } print_trie(child); child = child->sibling; if (branched == 1) { printf("}"); } } } }