support for trie compact lists
This commit is contained in:
parent
3ccad9aff2
commit
eeb62b63b4
@ -347,26 +347,50 @@
|
||||
OPCODE(trie_trust_null ,e),
|
||||
OPCODE(trie_try_null ,e),
|
||||
OPCODE(trie_retry_null ,e),
|
||||
OPCODE(trie_do_null_in_new_list ,e),
|
||||
OPCODE(trie_trust_null_in_new_list,e),
|
||||
OPCODE(trie_try_null_in_new_list ,e),
|
||||
OPCODE(trie_retry_null_in_new_list,e),
|
||||
OPCODE(trie_do_var ,e),
|
||||
OPCODE(trie_trust_var ,e),
|
||||
OPCODE(trie_try_var ,e),
|
||||
OPCODE(trie_retry_var ,e),
|
||||
OPCODE(trie_do_var_in_new_list ,e),
|
||||
OPCODE(trie_trust_var_in_new_list ,e),
|
||||
OPCODE(trie_try_var_in_new_list ,e),
|
||||
OPCODE(trie_retry_var_in_new_list ,e),
|
||||
OPCODE(trie_do_val ,e),
|
||||
OPCODE(trie_trust_val ,e),
|
||||
OPCODE(trie_try_val ,e),
|
||||
OPCODE(trie_retry_val ,e),
|
||||
OPCODE(trie_do_val_in_new_list ,e),
|
||||
OPCODE(trie_trust_val_in_new_list ,e),
|
||||
OPCODE(trie_try_val_in_new_list ,e),
|
||||
OPCODE(trie_retry_val_in_new_list ,e),
|
||||
OPCODE(trie_do_atom ,e),
|
||||
OPCODE(trie_trust_atom ,e),
|
||||
OPCODE(trie_try_atom ,e),
|
||||
OPCODE(trie_retry_atom ,e),
|
||||
OPCODE(trie_do_atom_in_new_list ,e),
|
||||
OPCODE(trie_trust_atom_in_new_list,e),
|
||||
OPCODE(trie_try_atom_in_new_list ,e),
|
||||
OPCODE(trie_retry_atom_in_new_list,e),
|
||||
OPCODE(trie_do_list ,e),
|
||||
OPCODE(trie_trust_list ,e),
|
||||
OPCODE(trie_try_list ,e),
|
||||
OPCODE(trie_retry_list ,e),
|
||||
OPCODE(trie_do_list_in_new_list ,e),
|
||||
OPCODE(trie_trust_list_in_new_list,e),
|
||||
OPCODE(trie_try_list_in_new_list ,e),
|
||||
OPCODE(trie_retry_list_in_new_list,e),
|
||||
OPCODE(trie_do_struct ,e),
|
||||
OPCODE(trie_trust_struct ,e),
|
||||
OPCODE(trie_try_struct ,e),
|
||||
OPCODE(trie_retry_struct ,e),
|
||||
OPCODE(trie_do_struct_in_new_list ,e),
|
||||
OPCODE(trie_trust_struct_in_new_list,e),
|
||||
OPCODE(trie_try_struct_in_new_list,e),
|
||||
OPCODE(trie_retry_struct_in_new_list,e),
|
||||
OPCODE(trie_do_extension ,e),
|
||||
OPCODE(trie_trust_extension ,e),
|
||||
OPCODE(trie_try_extension ,e),
|
||||
|
24
H/rclause.h
24
H/rclause.h
@ -795,41 +795,65 @@ restore_opcodes(yamop *pc)
|
||||
break;
|
||||
/* instructions type e */
|
||||
case _trie_do_atom:
|
||||
case _trie_do_atom_in_new_list:
|
||||
case _trie_do_extension:
|
||||
case _trie_do_float:
|
||||
case _trie_do_list:
|
||||
case _trie_do_list_in_new_list:
|
||||
case _trie_do_long:
|
||||
case _trie_do_null:
|
||||
case _trie_do_null_in_new_list:
|
||||
case _trie_do_struct:
|
||||
case _trie_do_struct_in_new_list:
|
||||
case _trie_do_val:
|
||||
case _trie_do_val_in_new_list:
|
||||
case _trie_do_var:
|
||||
case _trie_do_var_in_new_list:
|
||||
case _trie_retry_atom:
|
||||
case _trie_retry_atom_in_new_list:
|
||||
case _trie_retry_extension:
|
||||
case _trie_retry_float:
|
||||
case _trie_retry_list:
|
||||
case _trie_retry_list_in_new_list:
|
||||
case _trie_retry_long:
|
||||
case _trie_retry_null:
|
||||
case _trie_retry_null_in_new_list:
|
||||
case _trie_retry_struct:
|
||||
case _trie_retry_struct_in_new_list:
|
||||
case _trie_retry_val:
|
||||
case _trie_retry_val_in_new_list:
|
||||
case _trie_retry_var:
|
||||
case _trie_retry_var_in_new_list:
|
||||
case _trie_trust_atom:
|
||||
case _trie_trust_atom_in_new_list:
|
||||
case _trie_trust_extension:
|
||||
case _trie_trust_float:
|
||||
case _trie_trust_list:
|
||||
case _trie_trust_list_in_new_list:
|
||||
case _trie_trust_long:
|
||||
case _trie_trust_null:
|
||||
case _trie_trust_null_in_new_list:
|
||||
case _trie_trust_struct:
|
||||
case _trie_trust_struct_in_new_list:
|
||||
case _trie_trust_val:
|
||||
case _trie_trust_val_in_new_list:
|
||||
case _trie_trust_var:
|
||||
case _trie_trust_var_in_new_list:
|
||||
case _trie_try_atom:
|
||||
case _trie_try_atom_in_new_list:
|
||||
case _trie_try_extension:
|
||||
case _trie_try_float:
|
||||
case _trie_try_list:
|
||||
case _trie_try_list_in_new_list:
|
||||
case _trie_try_long:
|
||||
case _trie_try_null:
|
||||
case _trie_try_null_in_new_list:
|
||||
case _trie_try_struct:
|
||||
case _trie_try_struct_in_new_list:
|
||||
case _trie_try_val:
|
||||
case _trie_try_val_in_new_list:
|
||||
case _trie_try_var:
|
||||
case _trie_try_var_in_new_list:
|
||||
if (op == _Nstop || op == _copy_idb_term || op == _unify_idb_term) return;
|
||||
pc = NEXTOP(pc,e);
|
||||
break;
|
||||
|
@ -614,41 +614,65 @@
|
||||
break;
|
||||
/* instructions type e */
|
||||
case _trie_do_atom:
|
||||
case _trie_do_atom_in_new_list:
|
||||
case _trie_do_extension:
|
||||
case _trie_do_float:
|
||||
case _trie_do_list:
|
||||
case _trie_do_list_in_new_list:
|
||||
case _trie_do_long:
|
||||
case _trie_do_null:
|
||||
case _trie_do_null_in_new_list:
|
||||
case _trie_do_struct:
|
||||
case _trie_do_struct_in_new_list:
|
||||
case _trie_do_val:
|
||||
case _trie_do_val_in_new_list:
|
||||
case _trie_do_var:
|
||||
case _trie_do_var_in_new_list:
|
||||
case _trie_retry_atom:
|
||||
case _trie_retry_atom_in_new_list:
|
||||
case _trie_retry_extension:
|
||||
case _trie_retry_float:
|
||||
case _trie_retry_list:
|
||||
case _trie_retry_list_in_new_list:
|
||||
case _trie_retry_long:
|
||||
case _trie_retry_null:
|
||||
case _trie_retry_null_in_new_list:
|
||||
case _trie_retry_struct:
|
||||
case _trie_retry_struct_in_new_list:
|
||||
case _trie_retry_val:
|
||||
case _trie_retry_val_in_new_list:
|
||||
case _trie_retry_var:
|
||||
case _trie_retry_var_in_new_list:
|
||||
case _trie_trust_atom:
|
||||
case _trie_trust_atom_in_new_list:
|
||||
case _trie_trust_extension:
|
||||
case _trie_trust_float:
|
||||
case _trie_trust_list:
|
||||
case _trie_trust_list_in_new_list:
|
||||
case _trie_trust_long:
|
||||
case _trie_trust_null:
|
||||
case _trie_trust_null_in_new_list:
|
||||
case _trie_trust_struct:
|
||||
case _trie_trust_struct_in_new_list:
|
||||
case _trie_trust_val:
|
||||
case _trie_trust_val_in_new_list:
|
||||
case _trie_trust_var:
|
||||
case _trie_trust_var_in_new_list:
|
||||
case _trie_try_atom:
|
||||
case _trie_try_atom_in_new_list:
|
||||
case _trie_try_extension:
|
||||
case _trie_try_float:
|
||||
case _trie_try_list:
|
||||
case _trie_try_list_in_new_list:
|
||||
case _trie_try_long:
|
||||
case _trie_try_null:
|
||||
case _trie_try_null_in_new_list:
|
||||
case _trie_try_struct:
|
||||
case _trie_try_struct_in_new_list:
|
||||
case _trie_try_val:
|
||||
case _trie_try_val_in_new_list:
|
||||
case _trie_try_var:
|
||||
case _trie_try_var_in_new_list:
|
||||
pc = NEXTOP(pc,e);
|
||||
break;
|
||||
#endif
|
||||
|
@ -73,6 +73,11 @@
|
||||
** ----------------------------------------------- */
|
||||
/* #define INCOMPLETE_TABLING 1 */
|
||||
|
||||
/* ----------------------------------------------- **
|
||||
** support trie compact lists? (optional) **
|
||||
** ----------------------------------------------- */
|
||||
/* #define TRIE_COMPACT_LISTS 1 */
|
||||
|
||||
/* --------------------------------------- **
|
||||
** support inner cuts? (optional) **
|
||||
** --------------------------------------- */
|
||||
@ -169,6 +174,7 @@
|
||||
#undef BBREG_TRAIL_SCHEME
|
||||
#undef LIMIT_TABLING
|
||||
#undef INCOMPLETE_TABLING
|
||||
#undef TRIE_COMPACT_LISTS
|
||||
#undef TABLING_ERRORS
|
||||
#endif /* !TABLING */
|
||||
|
||||
|
@ -111,6 +111,11 @@ STD_PROTO(static inline tg_sol_fr_ptr CUT_prune_tg_solution_frames, (tg_sol_fr_p
|
||||
#define IsTableVarTerm(TERM) \
|
||||
((CELL) TERM) >= GLOBAL_table_var_enumerator(0) && \
|
||||
((CELL) TERM) <= GLOBAL_table_var_enumerator(MAX_TABLE_VARS - 1)
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
#define PairTermMark NULL
|
||||
#define PairTermInit ((Term *) 0)
|
||||
#define PairTermLast ((Term *) (LowTagBits + 1))
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
|
||||
#define HASH_TABLE_LOCK(NODE) ((((unsigned long int)NODE) >> 5) & (TABLE_LOCK_BUCKETS - 1))
|
||||
#define LOCK_TABLE(NODE) LOCK(GLOBAL_table_lock(HASH_TABLE_LOCK(NODE)))
|
||||
|
@ -714,10 +714,35 @@ sg_fr_ptr subgoal_search(yamop *preg, CELL **Yaddr) {
|
||||
} else if (IsAtomOrIntTerm(t)) {
|
||||
current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, t);
|
||||
} else if (IsPairTerm(t)) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
CELL *aux = RepPair(t);
|
||||
if (aux == PairTermMark) {
|
||||
t = Deref(STACK_POP_DOWN(stack_terms));
|
||||
if (IsPairTerm(t)) {
|
||||
aux = RepPair(t);
|
||||
/* STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 2, stack_terms_base); */
|
||||
/* STACK_CHECK_EXPAND is not necessary here because the situation of pushing **
|
||||
** up 3 terms has already initially checked for the PairTermInit term */
|
||||
STACK_PUSH_UP(*(aux + 1), stack_terms);
|
||||
STACK_PUSH_UP(AbsPair(PairTermMark), stack_terms);
|
||||
STACK_PUSH_UP(*(aux), stack_terms);
|
||||
} else {
|
||||
current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, AbsPair(PairTermLast));
|
||||
STACK_PUSH_UP(t, stack_terms);
|
||||
}
|
||||
} else {
|
||||
current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, AbsPair(PairTermInit));
|
||||
STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 2, stack_terms_base);
|
||||
STACK_PUSH_UP(*(aux + 1), stack_terms);
|
||||
STACK_PUSH_UP(AbsPair(PairTermMark), stack_terms);
|
||||
STACK_PUSH_UP(*(aux), stack_terms);
|
||||
}
|
||||
#else
|
||||
current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, AbsPair(NULL));
|
||||
STACK_CHECK_EXPAND(stack_terms, stack_terms_limit + 1, stack_terms_base);
|
||||
STACK_PUSH_UP(*(RepPair(t) + 1), stack_terms);
|
||||
STACK_PUSH_UP(*(RepPair(t)), stack_terms);
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
} else if (IsApplTerm(t)) {
|
||||
Functor f = FunctorOfTerm(t);
|
||||
current_sg_node = subgoal_trie_node_check_insert(tab_ent, current_sg_node, AbsAppl((Term *)f));
|
||||
@ -782,6 +807,11 @@ ans_node_ptr answer_search(sg_fr_ptr sg_fr, CELL *subs_ptr) {
|
||||
int i, j, count_vars, subs_arity;
|
||||
CELL *stack_vars, *stack_terms_base, *stack_terms;
|
||||
ans_node_ptr current_ans_node;
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
int in_new_list = 0;
|
||||
#else
|
||||
#define in_new_list 0
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
|
||||
count_vars = 0;
|
||||
subs_arity = *subs_ptr;
|
||||
@ -801,7 +831,7 @@ ans_node_ptr answer_search(sg_fr_ptr sg_fr, CELL *subs_ptr) {
|
||||
if (IsVarTerm(t)) {
|
||||
if (IsTableVarTerm(t)) {
|
||||
t = MakeTableVarTerm(VarIndexOfTerm(t));
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, t, _trie_retry_val);
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, t, _trie_retry_val + in_new_list);
|
||||
} else {
|
||||
if (count_vars == MAX_TABLE_VARS)
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "MAX_TABLE_VARS exceeded (answer_search)");
|
||||
@ -809,21 +839,54 @@ ans_node_ptr answer_search(sg_fr_ptr sg_fr, CELL *subs_ptr) {
|
||||
*((CELL *)t) = GLOBAL_table_var_enumerator(count_vars);
|
||||
t = MakeTableVarTerm(count_vars);
|
||||
count_vars++;
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, t, _trie_retry_var);
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, t, _trie_retry_var + in_new_list);
|
||||
}
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
in_new_list = 0;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
} else if (IsAtomOrIntTerm(t)) {
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, t, _trie_retry_atom);
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, t, _trie_retry_atom + in_new_list);
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
in_new_list = 0;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
} else if (IsPairTerm(t)) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
CELL *aux = RepPair(t);
|
||||
if (aux == PairTermMark) {
|
||||
t = Deref(STACK_POP_DOWN(stack_terms));
|
||||
if (IsPairTerm(t)) {
|
||||
aux = RepPair(t);
|
||||
/* STACK_CHECK_EXPAND(stack_terms, stack_vars + 2, stack_terms_base); */
|
||||
/* STACK_CHECK_EXPAND is not necessary here because the situation of pushing **
|
||||
** up 3 terms has already initially checked for the PairTermInit term */
|
||||
STACK_PUSH_UP(*(aux + 1), stack_terms);
|
||||
STACK_PUSH_UP(AbsPair(PairTermMark), stack_terms);
|
||||
STACK_PUSH_UP(*(aux), stack_terms);
|
||||
in_new_list = 4;
|
||||
} else {
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsPair(PairTermLast), _trie_retry_null);
|
||||
STACK_PUSH_UP(t, stack_terms);
|
||||
}
|
||||
} else {
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsPair(PairTermInit), _trie_retry_list + in_new_list);
|
||||
STACK_CHECK_EXPAND(stack_terms, stack_vars + 2, stack_terms_base);
|
||||
STACK_PUSH_UP(*(aux + 1), stack_terms);
|
||||
STACK_PUSH_UP(AbsPair(PairTermMark), stack_terms);
|
||||
STACK_PUSH_UP(*(aux), stack_terms);
|
||||
in_new_list = 0;
|
||||
}
|
||||
#else
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsPair(NULL), _trie_retry_list);
|
||||
STACK_CHECK_EXPAND(stack_terms, stack_vars + 1, stack_terms_base);
|
||||
STACK_PUSH_UP(*(RepPair(t) + 1), stack_terms);
|
||||
STACK_PUSH_UP(*(RepPair(t)), stack_terms);
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
} else if (IsApplTerm(t)) {
|
||||
Functor f = FunctorOfTerm(t);
|
||||
if (f == FunctorDouble) {
|
||||
volatile Float dbl = FloatOfTerm(t);
|
||||
volatile Term *t_dbl = (Term *)((void *) &dbl);
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_null);
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_null + in_new_list);
|
||||
#if SIZEOF_DOUBLE == 2 * SIZEOF_INT_P
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, *(t_dbl + 1), _trie_retry_extension);
|
||||
#endif /* SIZEOF_DOUBLE x SIZEOF_INT_P */
|
||||
@ -831,15 +894,18 @@ ans_node_ptr answer_search(sg_fr_ptr sg_fr, CELL *subs_ptr) {
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_float);
|
||||
} else if (f == FunctorLongInt) {
|
||||
Int li = LongIntOfTerm (t);
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_null);
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_null + in_new_list);
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, li, _trie_retry_extension);
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_long);
|
||||
} else {
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_struct);
|
||||
current_ans_node = answer_trie_node_check_insert(sg_fr, current_ans_node, AbsAppl((Term *)f), _trie_retry_struct + in_new_list);
|
||||
STACK_CHECK_EXPAND(stack_terms, stack_vars + ArityOfFunctor(f) - 1, stack_terms_base);
|
||||
for (j = ArityOfFunctor(f); j >= 1; j--)
|
||||
STACK_PUSH_UP(*(RepAppl(t) + j), stack_terms);
|
||||
}
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
in_new_list = 0;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
} else {
|
||||
Yap_Error(INTERNAL_ERROR, TermNil, "unknown type tag (answer_search)");
|
||||
}
|
||||
@ -860,6 +926,9 @@ void load_answer_trie(ans_node_ptr ans_node, CELL *subs_ptr) {
|
||||
CELL *stack_vars_base, *stack_vars, *stack_terms_base, *stack_terms;
|
||||
int subs_arity, i, n_vars = -1;
|
||||
Term t;
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
int stack_terms_pair_offset = 0;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
|
||||
if ((subs_arity = *subs_ptr) == 0)
|
||||
return;
|
||||
@ -890,10 +959,31 @@ void load_answer_trie(ans_node_ptr ans_node, CELL *subs_ptr) {
|
||||
STACK_CHECK_EXPAND(stack_terms, stack_vars, stack_terms_base);
|
||||
STACK_PUSH_UP(t, stack_terms);
|
||||
} else if (IsPairTerm(t)) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
if (t == AbsPair(PairTermInit)) {
|
||||
Term *stack_aux = stack_terms_base - stack_terms_pair_offset;
|
||||
Term head, tail = STACK_POP_UP(stack_aux);
|
||||
while (STACK_NOT_EMPTY(stack_aux, stack_terms)) {
|
||||
head = STACK_POP_UP(stack_aux);
|
||||
tail = MkPairTerm(head, tail);
|
||||
}
|
||||
stack_terms = stack_terms_base - stack_terms_pair_offset;
|
||||
stack_terms_pair_offset = (int) STACK_POP_DOWN(stack_terms);
|
||||
STACK_PUSH_UP(tail, stack_terms);
|
||||
} else { /* AbsPair(PairTermLast)) */
|
||||
Term last;
|
||||
STACK_CHECK_EXPAND(stack_terms, stack_vars, stack_terms_base);
|
||||
last = STACK_POP_DOWN(stack_terms);
|
||||
STACK_PUSH_UP(stack_terms_pair_offset, stack_terms);
|
||||
stack_terms_pair_offset = (int) (stack_terms_base - stack_terms);
|
||||
STACK_PUSH_UP(last, stack_terms);
|
||||
}
|
||||
#else
|
||||
Term head = STACK_POP_DOWN(stack_terms);
|
||||
Term tail = STACK_POP_DOWN(stack_terms);
|
||||
t = MkPairTerm(head, tail);
|
||||
STACK_PUSH_UP(t, stack_terms);
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
} else if (IsApplTerm(t)) {
|
||||
Functor f = (Functor) RepAppl(t);
|
||||
if (f == FunctorDouble) {
|
||||
@ -1286,6 +1376,12 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a
|
||||
sg_node = *bucket;
|
||||
traverse_subgoal_trie(sg_node, str, str_index, arity, depth, mode);
|
||||
memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
|
||||
if (arity[arity[0]] == -1)
|
||||
str[str_index - 1] = '|';
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
else if (arity[arity[0]] == -2 && str[str_index - 1] != '[')
|
||||
str[str_index - 1] = ',';
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
}
|
||||
} while (++bucket != last_bucket);
|
||||
free(current_arity);
|
||||
@ -1301,6 +1397,10 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a
|
||||
free(current_arity);
|
||||
if (arity[arity[0]] == -1)
|
||||
str[str_index - 1] = '|';
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
else if (arity[arity[0]] == -2 && str[str_index - 1] != '[')
|
||||
str[str_index - 1] = ',';
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
}
|
||||
|
||||
/* test the node type */
|
||||
@ -1334,13 +1434,17 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
arity[arity[0]]++;
|
||||
if (arity[arity[0]] == 0) {
|
||||
if (arity[arity[0]] == -2) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
str_index += sprintf(& str[str_index], ",");
|
||||
#else
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
arity[arity[0]] = -1;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
break;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "]");
|
||||
arity[0]--;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1363,13 +1467,17 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
arity[arity[0]]++;
|
||||
if (arity[arity[0]] == 0) {
|
||||
if (arity[arity[0]] == -2) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
str_index += sprintf(& str[str_index], ",");
|
||||
#else
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
arity[arity[0]] = -1;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
break;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "]");
|
||||
arity[0]--;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1391,13 +1499,17 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
arity[arity[0]]++;
|
||||
if (arity[arity[0]] == 0) {
|
||||
if (arity[arity[0]] == -2) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
str_index += sprintf(& str[str_index], ",");
|
||||
#else
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
arity[arity[0]] = -1;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
break;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "]");
|
||||
arity[0]--;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1418,13 +1530,17 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
arity[arity[0]]++;
|
||||
if (arity[arity[0]] == 0) {
|
||||
if (arity[arity[0]] == -2) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
str_index += sprintf(& str[str_index], ",");
|
||||
#else
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
arity[arity[0]] = -1;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
break;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "]");
|
||||
arity[0]--;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1445,20 +1561,30 @@ void traverse_subgoal_trie(sg_node_ptr sg_node, char *str, int str_index, int *a
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
arity[arity[0]]++;
|
||||
if (arity[arity[0]] == 0) {
|
||||
if (arity[arity[0]] == -2) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
str_index += sprintf(& str[str_index], ",");
|
||||
#else
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
arity[arity[0]] = -1;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
break;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "]");
|
||||
arity[0]--;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (IsPairTerm(t)) {
|
||||
} else if (IsPairTerm(t)) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
if (t == AbsPair(PairTermLast)) {
|
||||
str[str_index - 1] = '|';
|
||||
arity[arity[0]] = -1;
|
||||
#else
|
||||
if (arity[arity[0]] == -1) {
|
||||
str[str_index - 1] = ',';
|
||||
arity[arity[0]] = -2;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "[");
|
||||
arity[0]++;
|
||||
@ -1549,6 +1675,12 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int *
|
||||
ans_node = *bucket;
|
||||
traverse_answer_trie(ans_node, str, str_index, arity, var_index, depth, mode);
|
||||
memcpy(arity, current_arity, sizeof(int) * (current_arity[0] + 1));
|
||||
if (arity[arity[0]] == -1)
|
||||
str[str_index - 1] = '|';
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
else if (arity[arity[0]] == -2 && str[str_index - 1] != '[')
|
||||
str[str_index - 1] = ',';
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
}
|
||||
} while (++bucket != last_bucket);
|
||||
free(current_arity);
|
||||
@ -1564,6 +1696,10 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int *
|
||||
free(current_arity);
|
||||
if (arity[arity[0]] == -1)
|
||||
str[str_index - 1] = '|';
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
else if (arity[arity[0]] == -2 && str[str_index - 1] != '[')
|
||||
str[str_index - 1] = ',';
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
}
|
||||
|
||||
/* print VAR when starting a term */
|
||||
@ -1602,13 +1738,17 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int *
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
arity[arity[0]]++;
|
||||
if (arity[arity[0]] == 0) {
|
||||
if (arity[arity[0]] == -2) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
str_index += sprintf(& str[str_index], ",");
|
||||
#else
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
arity[arity[0]] = -1;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
break;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "]");
|
||||
arity[0]--;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1633,13 +1773,17 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int *
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
arity[arity[0]]++;
|
||||
if (arity[arity[0]] == 0) {
|
||||
if (arity[arity[0]] == -2) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
str_index += sprintf(& str[str_index], ",");
|
||||
#else
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
arity[arity[0]] = -1;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
break;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "]");
|
||||
arity[0]--;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1663,13 +1807,17 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int *
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
arity[arity[0]]++;
|
||||
if (arity[arity[0]] == 0) {
|
||||
if (arity[arity[0]] == -2) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
str_index += sprintf(& str[str_index], ",");
|
||||
#else
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
arity[arity[0]] = -1;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
break;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "]");
|
||||
arity[0]--;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1690,13 +1838,17 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int *
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
arity[arity[0]]++;
|
||||
if (arity[arity[0]] == 0) {
|
||||
if (arity[arity[0]] == -2) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
str_index += sprintf(& str[str_index], ",");
|
||||
#else
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
arity[arity[0]] = -1;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
break;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "]");
|
||||
arity[0]--;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1717,20 +1869,30 @@ void traverse_answer_trie(ans_node_ptr ans_node, char *str, int str_index, int *
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
arity[arity[0]]++;
|
||||
if (arity[arity[0]] == 0) {
|
||||
if (arity[arity[0]] == -2) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
str_index += sprintf(& str[str_index], ",");
|
||||
#else
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
arity[arity[0]] = -1;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
break;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "]");
|
||||
arity[0]--;
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "|");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (IsPairTerm(t)) {
|
||||
#ifdef TRIE_COMPACT_LISTS
|
||||
if (t == AbsPair(PairTermLast)) {
|
||||
str[str_index - 1] = '|';
|
||||
arity[arity[0]] = -1;
|
||||
#else
|
||||
if (arity[arity[0]] == -1) {
|
||||
str[str_index - 1] = ',';
|
||||
arity[arity[0]] = -2;
|
||||
#endif /* TRIE_COMPACT_LISTS */
|
||||
} else {
|
||||
str_index += sprintf(& str[str_index], "[");
|
||||
arity[0]++;
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user