Correction of a huge dbtrie bug

This commit is contained in:
Theofrastos Mantadelis 2010-11-09 01:58:42 +01:00
parent 0a5a1efd77
commit 3432b7bb67

View File

@ -261,14 +261,11 @@ void displaynode(TrNode node) {
else if (TrNode_entry(node) == PairEndTag) else if (TrNode_entry(node) == PairEndTag)
printf("PairEndTag\n"); printf("PairEndTag\n");
else if (IS_FUNCTOR_NODE(node)) else if (IS_FUNCTOR_NODE(node))
{printf("2\n"); printf("functor(%s)\n", YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)( ~ApplTag & TrNode_entry(node)))));
printf("FUNCTOR %s\n", YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)( ~ApplTag & TrNode_entry(node)))));}
else if (YAP_IsIntTerm(TrNode_entry(node))) else if (YAP_IsIntTerm(TrNode_entry(node)))
{printf("3\n"); printf("int(%ld)\n", YAP_IntOfTerm(TrNode_entry(node)));
printf("%ld\n", YAP_IntOfTerm(TrNode_entry(node)));}
else if (YAP_IsAtomTerm(TrNode_entry(node))) else if (YAP_IsAtomTerm(TrNode_entry(node)))
{printf("4\n"); printf("atom(%s)\n", YAP_AtomName(YAP_AtomOfTerm(TrNode_entry(node))));
printf("%s\n", YAP_AtomName(YAP_AtomOfTerm(TrNode_entry(node))));}
else else
printf("What?\n"); printf("What?\n");
} else } else
@ -627,10 +624,14 @@ TrNode core_breadth_reduction(TrEngine engine, TrNode node, TrNode breadth_node,
while(!(child = *--bucket)); while(!(child = *--bucket));
} }
} }
TrNode temp = TrNode_child(child); if (TrNode_child(child) == NULL) return NULL;
if (TrNode_entry(TrNode_child(child)) != PairEndTag) return NULL;
/* TrNode temp = TrNode_child(child);
if (temp == NULL) if (temp == NULL)
return NULL; return NULL;
// printf("Chosen start node child: "); displaynode(temp); printf("Chosen start node child: "); displaynode(temp);
if (IS_HASH_NODE(temp)) { if (IS_HASH_NODE(temp)) {
TrNode *first_bucket, *bucket; TrNode *first_bucket, *bucket;
TrHash hash = (TrHash) temp; TrHash hash = (TrHash) temp;
@ -646,17 +647,19 @@ TrNode core_breadth_reduction(TrEngine engine, TrNode node, TrNode breadth_node,
} else { } else {
while((temp != NULL) && (TrNode_entry(temp) != PairEndTag)) while((temp != NULL) && (TrNode_entry(temp) != PairEndTag))
temp = TrNode_next(temp); temp = TrNode_next(temp);
} }*/
// printf("while end\n"); // printf("while end\n");
//Nested Trie code //Nested Trie code
if (IS_FUNCTOR_NODE(TrNode_parent(child)) && (strcmp(YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)(~ApplTag & TrNode_entry(TrNode_parent(child))))), NESTED_TRIE_TERM) == 0)) { if (IS_FUNCTOR_NODE(TrNode_parent(child)) && (strcmp(YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)(~ApplTag & TrNode_entry(TrNode_parent(child))))), NESTED_TRIE_TERM) == 0)) {
/* nested trie: stop procedure and return nested trie node */ /* nested trie: stop procedure and return nested trie node */
return child; return child;
} }
PUSH_DOWN(stack_args, TrNode_entry(child), stack_top); PUSH_DOWN(stack_args, TrNode_entry(child), stack_top);
count++; count++;
if (IS_FUNCTOR_NODE(TrNode_parent(child))) { if (IS_FUNCTOR_NODE(TrNode_parent(child))) {
temp = TrNode_parent(child); TrNode temp = TrNode_parent(child);
while (IS_FUNCTOR_NODE(temp)) { while (IS_FUNCTOR_NODE(temp)) {
PUSH_DOWN(stack_args, TrNode_entry(temp), stack_top); PUSH_DOWN(stack_args, TrNode_entry(temp), stack_top);
temp = TrNode_parent(temp); temp = TrNode_parent(temp);
@ -665,6 +668,8 @@ TrNode core_breadth_reduction(TrEngine engine, TrNode node, TrNode breadth_node,
child = TrNode_parent(child); child = TrNode_parent(child);
} }
child = TrNode_next(child); child = TrNode_next(child);
// printf("Siblings: ");displaynode(child);
} while (child); } while (child);
// printf("pass through\n"); // printf("pass through\n");
} }