209int traverse_get_counter(
TrNode node);
210YAP_Term generate_label(YAP_Int Index);
211YAP_Term update_depth_breadth_trie(
TrEngine engine,
TrNode root, YAP_Int opt_level,
void (*construct_function)(
TrNode),
void (*destruct_function)(
TrNode),
void (*copy_function)(
TrNode,
TrNode),
void (*correct_order_function)(
void));
212YAP_Term get_return_node_term(
TrNode node);
213void traverse_and_replace_nested_trie(
TrNode node, YAP_Int nested_trie_id, YAP_Term new_term,
void (*construct_function)(
TrNode),
void (*destruct_function)(
TrNode));
215void check_attach_childs(
TrNode parent,
TrNode search_child,
TrNode existing_child,
void (*construct_function)(
TrNode),
void (*destruct_function)(
TrNode));
224void displaynode(
TrNode node);
225void displayentry(
TrNode node);
226void displayterm(YAP_Term term);
227void displaytrie(
TrNode node);
228void display_trie_inner(
TrNode node);
229void trie_display_node(
TrNode node);
236static YAP_Int LABEL_COUNTER;
237static YAP_Term TRIE_DEPTH_BREADTH_RETURN_TERM;
238static YAP_Int TRIE_DEPTH_BREADTH_MIN_PREFIX = 2;
239static YAP_Int TRIE_DEPTH_BREADTH_OPT_COUNT[3];
247YAP_Int core_get_trie_db_opt_min_prefix(
void) {
248 return TRIE_DEPTH_BREADTH_MIN_PREFIX;
253void core_set_trie_db_opt_min_prefix(YAP_Int min_prefix) {
254 TRIE_DEPTH_BREADTH_MIN_PREFIX = min_prefix;
260void core_depth_breadth_trie_replace_nested_trie(
TrNode node, YAP_Int nested_trie_id, YAP_Term new_term,
void (*construct_function)(
TrNode),
void (*destruct_function)(
TrNode)) {
261 traverse_and_replace_nested_trie(node, nested_trie_id, new_term, construct_function, destruct_function);
267void traverse_and_replace_nested_trie(
TrNode node, YAP_Int nested_trie_id, YAP_Term new_term,
void (*construct_function)(
TrNode),
void (*destruct_function)(
TrNode)) {
269 if (TrNode_entry(node) == PairEndTag) {
270 if (TrNode_next(node))
271 traverse_and_replace_nested_trie(TrNode_next(node), nested_trie_id, new_term, construct_function, destruct_function);
273 }
else if (IS_HASH_NODE(node)) {
274 printf(
"HASH NODE ERROR: db_tries do not support hash nodes.\n");
278 first_bucket = TrHash_buckets(hash);
279 bucket = first_bucket + TrHash_num_buckets(hash);
283 traverse_and_replace_nested_trie(node, nested_trie_id, new_term, construct_function, destruct_function);
284 node = TrNode_next(node);
287 }
while (
bucket != first_bucket);
289 if (IS_FUNCTOR_NODE(node)) {
290 YAP_Functor f = (YAP_Functor) (~ApplTag & TrNode_entry(node));
291 YAP_Int arity = YAP_ArityOfFunctor(f);
292 if (arity == 1 && strcmp(YAP_AtomName(YAP_NameOfFunctor(f)), NESTED_TRIE_TERM) == 0) {
293 child = TrNode_child(node);
294 if (IS_HASH_NODE(child)) {
295 printf(
"HASH NODE ERROR: db_tries do not support hash nodes.\n");
299 first_bucket = TrHash_buckets(hash);
300 bucket = first_bucket + TrHash_num_buckets(hash);
302 if ((child = *--
bucket)) {
304 if (YAP_IntOfTerm(TrNode_entry(child)) == nested_trie_id) {
305 temp = TrNode_previous(node);
306 node = replace_nested_trie(node, child, new_term, construct_function, destruct_function);
308 temp = TrNode_next(node);
312 traverse_and_replace_nested_trie(TrNode_child(node), nested_trie_id, new_term, construct_function, destruct_function);
316 child = TrNode_next(child);
319 }
while (
bucket != first_bucket);
323 if (YAP_IntOfTerm(TrNode_entry(child)) == nested_trie_id) {
324 temp = TrNode_next(node);
325 node = replace_nested_trie(node, child, new_term, construct_function, destruct_function);
326 traverse_and_replace_nested_trie(TrNode_child(node), nested_trie_id, new_term, construct_function, destruct_function);
328 traverse_and_replace_nested_trie(temp, nested_trie_id, new_term, construct_function, destruct_function);
331 child = TrNode_next(child);
336 traverse_and_replace_nested_trie(TrNode_child(node), nested_trie_id, new_term, construct_function, destruct_function);
337 if (TrNode_next(node))
338 traverse_and_replace_nested_trie(TrNode_next(node), nested_trie_id, new_term, construct_function, destruct_function);
345 TrNode newnode, temp, newnodef = NULL;
346 if (YAP_IsApplTerm(new_term)) {
347 YAP_Term new_term_functor = ApplTag | ((YAP_Term) YAP_FunctorOfTerm(new_term));
348 YAP_Int arity = YAP_ArityOfFunctor(YAP_FunctorOfTerm(new_term));
349 if (arity != 1) abort();
350 YAP_Term new_term_arg = YAP_ArgOfTerm(1, new_term);
351 temp = TrNode_child(TrNode_parent(node));
353 if (TrNode_entry(temp) == new_term_functor) {
354 printf(
"Warning - non tested code, please report the example to Theo to test it!\n");
358 temp = TrNode_next(temp);
361 if (newnodef == NULL) {
362 new_trie_node(newnodef, new_term_functor, TrNode_parent(node), NULL, TrNode_child(TrNode_parent(node)), NULL);
363 TrNode_previous(TrNode_child(TrNode_parent(node))) = newnodef;
364 TrNode_child(TrNode_parent(node)) = newnodef;
366 new_trie_node(newnode, new_term_arg, newnodef, TrNode_child(child), TrNode_child(newnodef), NULL);
367 if (TrNode_child(newnodef))
368 TrNode_previous(TrNode_child(newnodef)) = newnode;
369 TrNode_child(newnodef) = newnode;
373 while (TrNode_previous(temp))
374 temp = TrNode_previous(temp);
375 while (temp && TrNode_entry(temp) != new_term)
376 temp = TrNode_next(temp);
380 check_attach_childs(newnode, TrNode_child(child), TrNode_child(newnode), construct_function, destruct_function);
381 DATA_DESTRUCT_FUNCTION = destruct_function;
382 remove_child_nodes(TrNode_child(child));
383 TrNode_child(child) = NULL;
387 new_trie_node(newnode, new_term, TrNode_parent(node), TrNode_child(child), TrNode_child(TrNode_parent(node)), NULL);
388 TrNode_previous(TrNode_child(TrNode_parent(node))) = newnode;
389 TrNode_child(TrNode_parent(node)) = newnode;
392 temp = TrNode_child(child);
393 if (IS_HASH_NODE(temp)) {
394 printf(
"HASH NODE ERROR: db_tries do not support hash nodes.\n");
398 first_bucket = TrHash_buckets(hash);
399 bucket = first_bucket + TrHash_num_buckets(hash);
403 TrNode_parent(temp) = newnode;
404 temp = TrNode_next(temp);
407 }
while (
bucket != first_bucket);
410 TrNode_parent(temp) = newnode;
411 temp = TrNode_next(temp);
414 DATA_DESTRUCT_FUNCTION = destruct_function;
415 TrNode_child(child) = NULL;
421void check_attach_childs(
TrNode parent,
TrNode search_child,
TrNode existing_child,
void (*construct_function)(
TrNode),
void (*destruct_function)(
TrNode)) {
425 while(existing_child && (TrNode_entry(existing_child) != PairEndTag) && (TrNode_entry(existing_child) != TrNode_entry(search_child)))
426 existing_child = TrNode_next(existing_child);
428 if (existing_child) {
429 if (TrNode_entry(existing_child) != PairEndTag)
430 check_attach_childs(existing_child, TrNode_child(search_child), TrNode_child(existing_child), construct_function, destruct_function);
431 existing_child = TrNode_child(parent);
432 search_child = TrNode_next(search_child);
433 }
else if (TrNode_entry(search_child) == PairEndTag) {
435 DATA_DESTRUCT_FUNCTION = destruct_function;
436 remove_child_nodes(TrNode_child(newnode));
437 TrNode_child(newnode) = NULL;
438 newnode = trie_node_check_insert(newnode, PairEndTag);
439 INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
440 (*construct_function)(newnode);
443 existing_child = search_child;
444 search_child = TrNode_next(search_child);
445 if(TrNode_child(TrNode_parent(existing_child)) == existing_child) {
446 if(TrNode_next(existing_child)) {
447 TrNode_child(TrNode_parent(existing_child)) = TrNode_next(existing_child);
449 newnode = TrNode_parent(existing_child);
452 TrNode_child(newnode) = NULL;
453 newnode = trie_node_check_insert(newnode, PairEndTag);
454 INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
455 (*construct_function)(newnode);
459 if (TrNode_next(existing_child))
460 TrNode_previous(TrNode_next(existing_child)) = TrNode_previous(existing_child);
461 if (TrNode_previous(existing_child))
462 TrNode_next(TrNode_previous(existing_child)) = TrNode_next(existing_child);
464 TrNode_parent(existing_child) = parent;
465 TrNode_previous(existing_child) = NULL;
466 TrNode_next(existing_child) = TrNode_child(parent);
467 TrNode_previous(TrNode_child(parent)) = existing_child;
468 TrNode_child(parent) = existing_child;
469 existing_child = TrNode_child(parent);
471 }
while(search_child);
475YAP_Term core_get_trie_db_return_term(
void) {
476 return TRIE_DEPTH_BREADTH_RETURN_TERM;
481void core_set_trie_db_return_term(YAP_Term return_value){
482 TRIE_DEPTH_BREADTH_RETURN_TERM = return_value;
488void core_set_label_counter(YAP_Int value) {
489 LABEL_COUNTER = value;
494YAP_Int core_get_label_counter(
void) {
495 return LABEL_COUNTER;
499void core_initialize_depth_breadth_trie(
TrNode node,
TrNode *depth_node,
TrNode *breadth_node) {
502 f = YAP_MkFunctor(YAP_LookupAtom(
"depth"),2);
503 node = trie_node_check_insert(root, ApplTag | ((YAP_Term) f));
504 *depth_node = trie_node_check_insert(node, PairInitTag);
505 f = YAP_MkFunctor(YAP_LookupAtom(
"breadth"),2);
506 node = trie_node_check_insert(root, ApplTag | ((YAP_Term) f));
507 *breadth_node = trie_node_check_insert(node, PairInitTag);
508 TRIE_DEPTH_BREADTH_OPT_COUNT[0] = 0;
509 TRIE_DEPTH_BREADTH_OPT_COUNT[1] = 0;
510 TRIE_DEPTH_BREADTH_OPT_COUNT[2] = 0;
516void core_finalize_depth_breadth_trie(
TrNode depth_node,
TrNode breadth_node) {
517 depth_node = trie_node_check_insert(depth_node, YAP_MkIntTerm(1));
518 depth_node = trie_node_check_insert(depth_node, PairEndTag);
519 depth_node = trie_node_check_insert(depth_node, YAP_MkIntTerm(1));
520 remove_entry(depth_node);
521 breadth_node = trie_node_check_insert(breadth_node, YAP_MkIntTerm(1));
522 breadth_node = trie_node_check_insert(breadth_node, PairEndTag);
523 breadth_node = trie_node_check_insert(breadth_node, YAP_MkIntTerm(1));
524 remove_entry(breadth_node);
531 while (sibling != NULL && TrNode_entry(sibling) != PairEndTag)
532 sibling = TrNode_next(sibling);
533 if (sibling != NULL && TrNode_entry(sibling) == PairEndTag)
return sibling;
535 while (sibling != NULL && TrNode_entry(sibling) != PairEndTag)
536 sibling = TrNode_previous(sibling);
542 if (TrNode_entry(TrNode_myparent(node)) != PairInitTag) {
543 simplification = check_parent_first(TrNode_myparent(node));
544 if (simplification != NULL && TrNode_entry(simplification) == PairEndTag)
return simplification;
546 simplification = get_simplification_sibling(node);
547 return simplification;
551 TrNode parent = TrNode_parent(node);
552 while (parent != NULL && IS_FUNCTOR_NODE(parent))
553 parent = TrNode_parent(parent);
559 node = check_parent_first(TrNode_myparent(node));
562 node = TrNode_parent(node);
563 DATA_DESTRUCT_FUNCTION = destruct_function;
564 remove_child_nodes(TrNode_child(node));
565 TrNode_child(node) = NULL;
566 node = trie_node_check_insert(node, PairEndTag);
567 INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
575 YAP_Term t, *stack_top;
578 stack_args_base = stack_args = AUXILIARY_TERM_STACK;
579 stack_top = AUXILIARY_TERM_STACK + CURRENT_AUXILIARY_TERM_STACK_SIZE - 1;
581 node = TrNode_parent(node);
582 if (TrNode_entry(node) == PairInitTag) {
583 node = TrNode_child(node);
587 if (IS_FUNCTOR_NODE(TrNode_parent(node)) && (strcmp(YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)(~ApplTag & TrNode_entry(TrNode_parent(node))))), NESTED_TRIE_TERM) == 0)) {
591 PUSH_DOWN(stack_args, TrNode_entry(node), stack_top);
592 if (!IS_FUNCTOR_NODE(node))
594 }
while (TrNode_next(node) == NULL && TrNode_child(TrNode_parent(node)) == node);
597 while (IS_FUNCTOR_NODE(TrNode_parent(node))) {
598 node = TrNode_parent(node);
599 PUSH_DOWN(stack_args, TrNode_entry(node), stack_top);
601 TrNode temp = TrNode_child(TrNode_parent(node));
602 if (IS_HASH_NODE(temp)) {
603 printf(
"HASH NODE ERROR: db_tries do not support hash nodes.\n");
607 first_bucket = TrHash_buckets(hash);
608 bucket = first_bucket + TrHash_num_buckets(hash);
611 while(TrNode_next(temp) != NULL) {
612 if (TrNode_entry(temp) == PairEndTag)
614 temp = TrNode_next(temp);
617 }
while (
bucket != first_bucket);
619 while(TrNode_next(temp) != NULL) {
620 if (TrNode_entry(temp) == PairEndTag)
622 temp = TrNode_next(temp);
626 t = update_depth_breadth_trie(engine, depth_node, opt_level, construct_function, destruct_function, copy_function, correct_order_function);
629 DATA_DESTRUCT_FUNCTION = destruct_function;
630 node = trie_node_check_insert(TrNode_parent(node), t);
631 node = trie_node_check_insert(node, PairEndTag);
632 INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
633 temp = TrNode_parent(leaf);
634 remove_child_nodes(TrNode_child(temp));
635 TrNode_child(temp) = NULL;
642TrNode core_breadth_reduction(
TrEngine engine,
TrNode node,
TrNode breadth_node, YAP_Int opt_level,
void (*construct_function)(
TrNode),
void (*destruct_function)(
TrNode),
void (*copy_function)(
TrNode,
TrNode),
void (*correct_order_function)(
void)) {
643 YAP_Term t, *stack_top;
653 stack_args_base = stack_args = AUXILIARY_TERM_STACK;
654 stack_top = AUXILIARY_TERM_STACK + CURRENT_AUXILIARY_TERM_STACK_SIZE - 1;
655 node = TrNode_parent(TrNode_parent(node));
657 if (IS_FUNCTOR_NODE(node)) {
658 while(IS_FUNCTOR_NODE(node))
659 node = TrNode_parent(node);
660 child = TrNode_child(node);
661 while((TrNode_next(child) == NULL) && (TrNode_child(TrNode_parent(child)) == child) && (TrNode_entry(TrNode_child(child)) != PairEndTag))
662 child = TrNode_child(child);
664 child = TrNode_child(node);
666 if (IS_HASH_NODE(child)) {
667 printf(
"HASH NODE ERROR: db_tries do not support hash nodes.\n");
730 if (TrNode_entry(child) == PairEndTag) {
732 printf(
"SIMPLIFICATION ERROR: I should never arrive here, please contact Theo!\n");
744 while (IS_FUNCTOR_NODE(child)) {
745 child = TrNode_child(child);
746 if (IS_HASH_NODE(child)) {
747 printf(
"HASH NODE ERROR: db_tries do not support hash nodes.\n");
751 first_bucket = TrHash_buckets(hash);
752 bucket = first_bucket + TrHash_num_buckets(hash);
753 while(!(child = *--
bucket));
756 if (TrNode_child(child) == NULL)
return NULL;
757 if (TrNode_entry(TrNode_child(child)) != PairEndTag)
return NULL;
759 if (IS_FUNCTOR_NODE(TrNode_parent(child)) && (strcmp(YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)(~ApplTag & TrNode_entry(TrNode_parent(child))))), NESTED_TRIE_TERM) == 0))
761 PUSH_DOWN(stack_args, TrNode_entry(child), stack_top);
763 if (IS_FUNCTOR_NODE(TrNode_parent(child))) {
764 TrNode temp = TrNode_parent(child);
765 while (IS_FUNCTOR_NODE(temp)) {
766 PUSH_DOWN(stack_args, TrNode_entry(temp), stack_top);
767 temp = TrNode_parent(temp);
769 while ((TrNode_next(child) == NULL) && IS_FUNCTOR_NODE(TrNode_parent(child)))
770 child = TrNode_parent(child);
772 child = TrNode_next(child);
777 core_set_trie_db_return_term(get_return_node_term(TrNode_child(node)));
778 node = TrNode_parent(node);
779 DATA_DESTRUCT_FUNCTION = destruct_function;
780 remove_child_nodes(TrNode_child(node));
781 TrNode_child(node) = NULL;
785 t = update_depth_breadth_trie(engine, breadth_node, opt_level, construct_function, destruct_function, copy_function, correct_order_function);
788 DATA_DESTRUCT_FUNCTION = destruct_function;
789 remove_child_nodes(TrNode_child(node));
790 TrNode_child(node) = NULL;
791 node = trie_node_check_insert(node, t);
792 node = trie_node_check_insert(node, PairEndTag);
793 INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
799YAP_Term get_return_node_term(
TrNode node) {
801 if (IS_HASH_NODE(node)) {
804 first_bucket = TrHash_buckets(hash);
805 bucket = first_bucket + TrHash_num_buckets(hash);
806 while(!(node = *--
bucket));
807 t = TrNode_entry(node);
808 }
else if (IS_FUNCTOR_NODE(node)) {
809 args[0] = get_return_node_term(TrNode_child(node));
810 t = YAP_MkApplTerm((YAP_Functor)(~ApplTag & TrNode_entry(node)), 1, args);
812 t = TrNode_entry(node);
818int traverse_get_counter(
TrNode node) {
820 while (TrNode_entry(node) != PairEndTag) {
821 if (!IS_FUNCTOR_NODE(node))
823 node = TrNode_child(node);
824 if (IS_HASH_NODE(node)) {
827 first_bucket = TrHash_buckets(hash);
828 bucket = first_bucket + TrHash_num_buckets(hash);
831 while(TrNode_next(node) != NULL)
832 node = TrNode_next(node);
834 }
while (
bucket != first_bucket);
836 while(TrNode_next(node) != NULL)
837 node = TrNode_next(node);
840 return atoi(YAP_AtomName(YAP_AtomOfTerm(TrNode_entry(TrNode_child(node)))) + 1) - count;
844YAP_Term generate_label(YAP_Int Index) {
846 sprintf(label,
"L%" Int_F, Index);
847 return YAP_MkAtomTerm(YAP_LookupAtom(label));
852YAP_Term update_depth_breadth_trie(
TrEngine engine,
TrNode root, YAP_Int opt_level,
void (*construct_function)(
TrNode),
void (*destruct_function)(
TrNode),
void (*copy_function)(
TrNode,
TrNode),
void (*correct_order_function)(
void)) {
853 TrNode node = root, remember = NULL;
854 int count = -1, cnt = -1, c_cnt = 0, f_cnt = 0;
855 YAP_Int BAK_CURRENT_TRIE_MODE = CURRENT_TRIE_MODE;
856 YAP_Term t, tt, ret_t = PairEndTag;
858 CURRENT_TRIE_MODE = TRIE_MODE_MINIMAL;
860 CURRENT_TRIE_MODE = TRIE_MODE_STANDARD;
861 CURRENT_TRIE_ENGINE = engine;
862 DATA_DESTRUCT_FUNCTION = destruct_function;
863 DATA_COPY_FUNCTION = copy_function;
865 t = POP_UP(stack_args);
866 node = trie_node_check_insert(node, t);
867 if (!IS_FUNCTOR_NODE(node))
871 if (TrNode_entry(node) == PairEndTag) {
873 TrNode c_node = trie_node_check(TrNode_parent(node), t), end_node;
876 while (c_node != NULL) {
877 if (stack_args_base != stack_args) {
879 tt = POP_UP(stack_args);
880 end_node = trie_node_check(c_node, PairEndTag);
881 c_node = trie_node_check(c_node, tt);
882 if ((c_node!= NULL) && !IS_FUNCTOR_NODE(c_node))
884 if ((end_node != NULL)) {
902 if (TrNode_entry(node) == PairEndTag) {
903 if (count > TRIE_DEPTH_BREADTH_MIN_PREFIX - 2) {
904 TRIE_DEPTH_BREADTH_OPT_COUNT[0]++;
907 node = trie_node_check_insert(root, TrNode_entry(TrNode_child(node)));
908 if (TrNode_child(node) != NULL)
910 node = trie_node_check_insert(node, t);
911 if (!IS_FUNCTOR_NODE(node)) {
913 if (TrNode_child(node) != NULL)
917 CURRENT_TRIE_MODE = TRIE_MODE_STANDARD;
918 node = trie_node_check_insert(TrNode_parent(node), t);
919 CURRENT_TRIE_MODE = TRIE_MODE_MINIMAL;
928 if (TrNode_child(node) != NULL) {
929 if (!IS_FUNCTOR_NODE(node))
932 if ((remember == NULL) && (cnt > 0) && (cnt > TRIE_DEPTH_BREADTH_MIN_PREFIX - 2)) {
933 TRIE_DEPTH_BREADTH_OPT_COUNT[1]--;
934 TRIE_DEPTH_BREADTH_OPT_COUNT[2]++;
937 remember = TrNode_parent(remember);
938 }
while(IS_FUNCTOR_NODE(remember));
942 }
while (stack_args_base != stack_args);
954 if ((TrNode_child(node) != NULL) && (TrNode_entry(TrNode_child(node)) != PairEndTag) && (count > TRIE_DEPTH_BREADTH_MIN_PREFIX - 2)) {
955 TRIE_DEPTH_BREADTH_OPT_COUNT[1]++;
956 t = generate_label(traverse_get_counter(node));
957 root = trie_node_check_insert(root, t);
958 TrNode_child(root) = copy_child_nodes(root, TrNode_child(node));
959 remove_child_nodes(TrNode_child(node));
960 TrNode_child(node) = NULL;
963 node = trie_node_check_insert(node, PairEndTag);
965 if (t == PairEndTag) {
966 if (TrNode_child(node)) {
967 t = TrNode_entry(TrNode_child(node));
969 LABEL_COUNTER += count;
970 t = generate_label(LABEL_COUNTER);
971 node = trie_node_check_insert(node, t);
972 INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
973 (*construct_function)(node);
976 node = trie_node_check_insert(node, t);
977 INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
978 (*construct_function)(node);
979 (*correct_order_function)();
985 if (ret_t == PairEndTag)
987 }
while(node != NULL);
989 CURRENT_TRIE_MODE = BAK_CURRENT_TRIE_MODE;
995YAP_Int core_db_trie_get_optimization_level_count(YAP_Int opt_level) {
996 return TRIE_DEPTH_BREADTH_OPT_COUNT[opt_level - 1];
1004void displaynode(
TrNode node) {
1006 if (IS_HASH_NODE(node))
1007 printf(
"HASH n%i, b%i, p%p\n", TrHash_num_nodes((
TrHash) node), TrHash_num_buckets((
TrHash) node), node);
1008 else if (TrNode_entry(node) == PairInitTag)
1009 printf(
"PairInitTag\n");
1010 else if (TrNode_entry(node) == PairEndTag)
1011 printf(
"PairEndTag\n");
1012 else if (IS_FUNCTOR_NODE(node))
1013 printf(
"functor(%s)\n", YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)( ~ApplTag & TrNode_entry(node)))));
1014 else if (YAP_IsIntTerm(TrNode_entry(node)))
1015 printf(
"int(%"Int_F
")\n", YAP_IntOfTerm(TrNode_entry(node)));
1016 else if (YAP_IsAtomTerm(TrNode_entry(node)))
1017 printf(
"atom(%s)\n", YAP_AtomName(YAP_AtomOfTerm(TrNode_entry(node))));
1025void displayentry(
TrNode node) {
1026 printf(
"Entry Contains Bottom Up:\n");
1029 node = TrNode_parent(node);
1031 printf(
"--- End of Entry ---\n");
1034void displayterm(YAP_Term term) {
1036 if (term == PairInitTag)
1037 printf(
"PairInitTag\n");
1038 else if (term == PairEndTag)
1039 printf(
"PairEndTag\n");
1040 else if (YAP_IsApplTerm(term))
1041 printf(
"functor(%s)\n", YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)( ~ApplTag & term))));
1042 else if (YAP_IsIntTerm(term))
1043 printf(
"int(%"Int_F
")\n", YAP_IntOfTerm(term));
1044 else if (YAP_IsAtomTerm(term))
1045 printf(
"atom(%s)\n", YAP_AtomName(YAP_AtomOfTerm(term)));
1053void displaytrie(
TrNode node) {
1054 while(TrNode_entry(node) != PairInitTag){
1055 printf(
"?: "); displaynode(node);
1056 node = TrNode_parent(node);
1058 display_trie_inner(node);
1061void display_trie_inner(
TrNode node) {
1062 trie_display_node(node);
1063 if (TrNode_entry(node) != PairEndTag && TrNode_child(node))
1064 display_trie_inner(TrNode_child(node));
1065 if (TrNode_next(node)) {
1066 trie_display_node(TrNode_parent(node)); display_trie_inner(TrNode_next(node));
1070void trie_display_node(
TrNode node) {
1072 if (IS_HASH_NODE(node))
1073 printf(
"HASH(n%i, b%i, p%p), ", TrHash_num_nodes((
TrHash) node), TrHash_num_buckets((
TrHash) node), node);
1074 else if (TrNode_entry(node) == PairInitTag)
1075 printf(
"PairInitTag, ");
1076 else if (TrNode_entry(node) == PairEndTag)
1077 printf(
"PairEndTag\n");
1078 else if (IS_FUNCTOR_NODE(node))
1079 printf(
"functor(%s), ", YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)( ~ApplTag & TrNode_entry(node)))));
1080 else if (YAP_IsIntTerm(TrNode_entry(node)))
1081 printf(
"int(%" Int_F
"), ", YAP_IntOfTerm(TrNode_entry(node)));
1082 else if (YAP_IsAtomTerm(TrNode_entry(node)))
1083 printf(
"atom(%s), ", YAP_AtomName(YAP_AtomOfTerm(TrNode_entry(node))));