tries module: fix bug in trie_get_first_entry/2
This commit is contained in:
parent
c3fb089eeb
commit
71a9be9742
@ -28,13 +28,12 @@
|
||||
itrie_save/2,
|
||||
itrie_save_as_trie/2,
|
||||
itrie_load/2,
|
||||
itrie_save2stream/2,
|
||||
itrie_loadFromstream/2,
|
||||
itrie_stats/4,
|
||||
itrie_max_stats/4,
|
||||
itrie_usage/4,
|
||||
itrie_print/1,
|
||||
%added by nf
|
||||
itrie_save2stream/2,
|
||||
itrie_loadFromstream/2
|
||||
itrie_print/1
|
||||
]).
|
||||
|
||||
:- load_foreign_files([itries], [], init_itries).
|
||||
|
@ -72,8 +72,10 @@ void trie_data_destruct(TrNode node) {
|
||||
if (TrData_next(data)) {
|
||||
TrData_previous(TrData_next(data)) = TrData_previous(data);
|
||||
TrData_next(TrData_previous(data)) = TrData_next(data);
|
||||
} else
|
||||
} else {
|
||||
TrEntry_last_data(trie) = TrData_previous(data);
|
||||
TrData_next(TrData_previous(data)) = NULL;
|
||||
}
|
||||
free_trie_data(data);
|
||||
return;
|
||||
}
|
||||
@ -177,6 +179,8 @@ TrData trie_get_last_entry(TrEntry trie) {
|
||||
TrData data;
|
||||
|
||||
data = TrEntry_last_data(trie);
|
||||
if (data == AS_TR_DATA_NEXT(&TrEntry_first_data(trie)))
|
||||
return NULL;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -53,32 +53,32 @@ typedef struct trie_data {
|
||||
/* Macros */
|
||||
/* --------------------------- */
|
||||
|
||||
#define new_trie_entry(TR_ENTRY, TR_NODE) \
|
||||
{ new_struct(TR_ENTRY, TYPE_TR_ENTRY, SIZEOF_TR_ENTRY); \
|
||||
TrEntry_trie(TR_ENTRY) = TR_NODE; \
|
||||
TrEntry_first_data(TR_ENTRY) = NULL; \
|
||||
TrEntry_last_data(TR_ENTRY) = NULL; \
|
||||
TrEntry_traverse_data(TR_ENTRY) = NULL; \
|
||||
TrEntry_next(TR_ENTRY) = FIRST_TRIE; \
|
||||
TrEntry_previous(TR_ENTRY) = AS_TR_ENTRY_NEXT(&FIRST_TRIE); \
|
||||
INCREMENT_MEMORY(TRIE_ENGINE, SIZEOF_TR_ENTRY); \
|
||||
#define new_trie_entry(TR_ENTRY, TR_NODE) \
|
||||
{ new_struct(TR_ENTRY, TYPE_TR_ENTRY, SIZEOF_TR_ENTRY); \
|
||||
TrEntry_trie(TR_ENTRY) = TR_NODE; \
|
||||
TrEntry_first_data(TR_ENTRY) = NULL; \
|
||||
TrEntry_last_data(TR_ENTRY) = AS_TR_DATA_NEXT(&TrEntry_first_data(TR_ENTRY)); \
|
||||
TrEntry_traverse_data(TR_ENTRY) = NULL; \
|
||||
TrEntry_next(TR_ENTRY) = FIRST_TRIE; \
|
||||
TrEntry_previous(TR_ENTRY) = AS_TR_ENTRY_NEXT(&FIRST_TRIE); \
|
||||
INCREMENT_MEMORY(TRIE_ENGINE, SIZEOF_TR_ENTRY); \
|
||||
}
|
||||
#define new_trie_data(TR_DATA, TR_ENTRY, TR_NODE) \
|
||||
{ TrData last_data = TrEntry_last_data(TR_ENTRY); \
|
||||
new_struct(TR_DATA, TYPE_TR_DATA, SIZEOF_TR_DATA); \
|
||||
TrData_trie(TR_DATA) = TR_ENTRY; \
|
||||
TrData_leaf(TR_DATA) = TR_NODE; \
|
||||
TrData_next(TR_DATA) = NULL; \
|
||||
if (last_data) { \
|
||||
TrData_next(last_data) = TR_DATA; \
|
||||
TrData_previous(TR_DATA) = last_data; \
|
||||
TrEntry_last_data(TR_ENTRY) = TR_DATA; \
|
||||
} else { \
|
||||
TrData_previous(TR_DATA) = AS_TR_DATA_NEXT(&TrEntry_first_data(TR_ENTRY)); \
|
||||
TrEntry_first_data(TR_ENTRY) = TR_DATA; \
|
||||
TrEntry_last_data(TR_ENTRY) = TR_DATA; \
|
||||
} \
|
||||
INCREMENT_MEMORY(TRIE_ENGINE, SIZEOF_TR_DATA); \
|
||||
#define new_trie_data(TR_DATA, TR_ENTRY, TR_NODE) \
|
||||
{ TrData first_data = TrEntry_first_data(TR_ENTRY); \
|
||||
new_struct(TR_DATA, TYPE_TR_DATA, SIZEOF_TR_DATA); \
|
||||
TrData_trie(TR_DATA) = TR_ENTRY; \
|
||||
TrData_leaf(TR_DATA) = TR_NODE; \
|
||||
TrData_next(TR_DATA) = NULL; \
|
||||
if (first_data) { \
|
||||
TrData last_data = TrEntry_last_data(TR_ENTRY); \
|
||||
TrData_next(last_data) = TR_DATA; \
|
||||
TrData_previous(TR_DATA) = last_data; \
|
||||
} else { \
|
||||
TrData_previous(TR_DATA) = AS_TR_DATA_NEXT(&TrEntry_first_data(TR_ENTRY)); \
|
||||
TrEntry_first_data(TR_ENTRY) = TR_DATA; \
|
||||
} \
|
||||
TrEntry_last_data(TR_ENTRY) = TR_DATA; \
|
||||
INCREMENT_MEMORY(TRIE_ENGINE, SIZEOF_TR_DATA); \
|
||||
}
|
||||
|
||||
|
||||
|
@ -431,7 +431,8 @@ TrNode core_trie_load(TrEngine engine, FILE *file, void (*load_function)(TrNode,
|
||||
fpos_t curpos;
|
||||
|
||||
fscanf(file, "%14s", version);
|
||||
if (fgetpos(file, &curpos) ) return NULL;
|
||||
if (fgetpos(file, &curpos))
|
||||
return NULL;
|
||||
|
||||
if (!strcmp(version, "BEGIN_TRIE_v2")) {
|
||||
fseek(file, -11, SEEK_END);
|
||||
@ -442,7 +443,8 @@ TrNode core_trie_load(TrEngine engine, FILE *file, void (*load_function)(TrNode,
|
||||
fprintf(stderr, "******************************************\n");
|
||||
return NULL;
|
||||
}
|
||||
if (fsetpos(file, &curpos) ) return NULL;
|
||||
if (fsetpos(file, &curpos))
|
||||
return NULL;
|
||||
CURRENT_LOAD_VERSION = 2;
|
||||
} else if (!strcmp(version, "BEGIN_TRIE")) {
|
||||
fseek(file, -8, SEEK_END);
|
||||
@ -453,7 +455,8 @@ TrNode core_trie_load(TrEngine engine, FILE *file, void (*load_function)(TrNode,
|
||||
fprintf(stderr, "******************************************\n");
|
||||
return NULL;
|
||||
}
|
||||
if (fsetpos(file, &curpos) ) return NULL;
|
||||
if (fsetpos(file, &curpos))
|
||||
return NULL;
|
||||
CURRENT_LOAD_VERSION = 1;
|
||||
} else {
|
||||
fprintf(stderr, "****************************************\n");
|
||||
|
@ -47,13 +47,13 @@ static int p_itrie_count_intersect(void);
|
||||
static int p_itrie_save(void);
|
||||
static int p_itrie_save_as_trie(void);
|
||||
static int p_itrie_load(void);
|
||||
static int p_itrie_save2stream(void);
|
||||
static int p_itrie_loadFromStream(void);
|
||||
static int p_itrie_stats(void);
|
||||
static int p_itrie_max_stats(void);
|
||||
static int p_itrie_usage(void);
|
||||
static int p_itrie_print(void);
|
||||
//nf
|
||||
static int p_itrie_loadFromStream(void);
|
||||
static int p_itrie_save2stream(void);
|
||||
|
||||
|
||||
|
||||
/* -------------------------- */
|
||||
@ -85,13 +85,12 @@ void init_itries(void) {
|
||||
YAP_UserCPredicate("itrie_save", p_itrie_save, 2);
|
||||
YAP_UserCPredicate("itrie_save_as_trie", p_itrie_save_as_trie, 2);
|
||||
YAP_UserCPredicate("itrie_load", p_itrie_load, 2);
|
||||
YAP_UserCPredicate("itrie_save2stream", p_itrie_save2stream, 2);
|
||||
YAP_UserCPredicate("itrie_loadFromstream", p_itrie_loadFromStream, 2);
|
||||
YAP_UserCPredicate("itrie_stats", p_itrie_stats, 4);
|
||||
YAP_UserCPredicate("itrie_max_stats", p_itrie_max_stats, 4);
|
||||
YAP_UserCPredicate("itrie_usage", p_itrie_usage, 4);
|
||||
YAP_UserCPredicate("itrie_print", p_itrie_print, 1);
|
||||
// nf
|
||||
YAP_UserCPredicate("itrie_save2stream", p_itrie_save2stream, 2);
|
||||
YAP_UserCPredicate("itrie_loadFromstream", p_itrie_loadFromStream, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -101,7 +100,7 @@ void init_itries(void) {
|
||||
/* Local Procedures */
|
||||
/* -------------------------- */
|
||||
|
||||
/* itrie_open(+Itrie) */
|
||||
/* itrie_open(-Itrie) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
static int p_itrie_open(void) {
|
||||
TrEntry itrie;
|
||||
@ -117,7 +116,7 @@ static int p_itrie_open(void) {
|
||||
#undef arg_itrie
|
||||
|
||||
|
||||
/* itrie_close(-Itrie) */
|
||||
/* itrie_close(+Itrie) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
static int p_itrie_close(void) {
|
||||
/* check arg */
|
||||
@ -138,7 +137,7 @@ static int p_itrie_close_all(void) {
|
||||
}
|
||||
|
||||
|
||||
/* itrie_mode(-Itrie,?Mode) */
|
||||
/* itrie_mode(+Itrie,?Mode) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_mode YAP_ARG2
|
||||
static int p_itrie_mode(void) {
|
||||
@ -189,7 +188,7 @@ static int p_itrie_mode(void) {
|
||||
#undef arg_mode
|
||||
|
||||
|
||||
/* itrie_timestamp(-Itrie,?Time) */
|
||||
/* itrie_timestamp(+Itrie,?Time) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_time YAP_ARG2
|
||||
static int p_itrie_timestamp(void) {
|
||||
@ -218,7 +217,7 @@ static int p_itrie_timestamp(void) {
|
||||
#undef arg_time
|
||||
|
||||
|
||||
/* itrie_put_entry(-Itrie,-Entry) */
|
||||
/* itrie_put_entry(+Itrie,+Entry) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_entry YAP_ARG2
|
||||
static int p_itrie_put_entry(void) {
|
||||
@ -234,7 +233,7 @@ static int p_itrie_put_entry(void) {
|
||||
#undef arg_entry
|
||||
|
||||
|
||||
/* itrie_update_entry(-Itrie,-Entry) */
|
||||
/* itrie_update_entry(+Itrie,+Entry) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_entry YAP_ARG2
|
||||
static int p_itrie_update_entry(void) {
|
||||
@ -250,7 +249,7 @@ static int p_itrie_update_entry(void) {
|
||||
#undef arg_entry
|
||||
|
||||
|
||||
/* itrie_check_entry(-Itrie,-Entry,+Ref) */
|
||||
/* itrie_check_entry(+Itrie,+Entry,-Ref) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_entry YAP_ARG2
|
||||
#define arg_ref YAP_ARG3
|
||||
@ -271,7 +270,7 @@ static int p_itrie_check_entry(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* itrie_get_entry(-Ref,+Entry) */
|
||||
/* itrie_get_entry(+Ref,-Entry) */
|
||||
#define arg_ref YAP_ARG1
|
||||
#define arg_entry YAP_ARG2
|
||||
static int p_itrie_get_entry(void) {
|
||||
@ -289,7 +288,7 @@ static int p_itrie_get_entry(void) {
|
||||
#undef arg_entry
|
||||
|
||||
|
||||
/* itrie_get_data(-Ref,+Data) */
|
||||
/* itrie_get_data(+Ref,-Data) */
|
||||
#define arg_ref YAP_ARG1
|
||||
#define arg_data YAP_ARG2
|
||||
static int p_itrie_get_data(void) {
|
||||
@ -323,7 +322,7 @@ static int p_itrie_get_data(void) {
|
||||
#undef arg_data
|
||||
|
||||
|
||||
/* itrie_traverse(-Itrie,+Ref) */
|
||||
/* itrie_traverse(+Itrie,-Ref) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_ref YAP_ARG2
|
||||
static int p_itrie_traverse_init(void) {
|
||||
@ -344,7 +343,7 @@ static int p_itrie_traverse_init(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* itrie_traverse(-Itrie,+Ref) */
|
||||
/* itrie_traverse(+Itrie,-Ref) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_ref YAP_ARG2
|
||||
static int p_itrie_traverse_cont(void) {
|
||||
@ -361,7 +360,7 @@ static int p_itrie_traverse_cont(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* itrie_remove_entry(-Ref) */
|
||||
/* itrie_remove_entry(+Ref) */
|
||||
#define arg_ref YAP_ARG1
|
||||
static int p_itrie_remove_entry(void) {
|
||||
/* check arg */
|
||||
@ -375,7 +374,7 @@ static int p_itrie_remove_entry(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* itrie_remove_subtree(-Ref) */
|
||||
/* itrie_remove_subtree(+Ref) */
|
||||
#define arg_ref YAP_ARG1
|
||||
static int p_itrie_remove_subtree(void) {
|
||||
/* check arg */
|
||||
@ -389,7 +388,7 @@ static int p_itrie_remove_subtree(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* itrie_add(-ItrieDest,-ItrieSource) */
|
||||
/* itrie_add(+ItrieDest,+ItrieSource) */
|
||||
#define arg_itrie_dest YAP_ARG1
|
||||
#define arg_itrie_source YAP_ARG2
|
||||
static int p_itrie_add(void) {
|
||||
@ -407,7 +406,7 @@ static int p_itrie_add(void) {
|
||||
#undef arg_itrie_source
|
||||
|
||||
|
||||
/* itrie_subtract(-ItrieDest,-ItrieSource) */
|
||||
/* itrie_subtract(+ItrieDest,+ItrieSource) */
|
||||
#define arg_itrie_dest YAP_ARG1
|
||||
#define arg_itrie_source YAP_ARG2
|
||||
static int p_itrie_subtract(void) {
|
||||
@ -425,7 +424,7 @@ static int p_itrie_subtract(void) {
|
||||
#undef arg_itrie_source
|
||||
|
||||
|
||||
/* itrie_join(-ItrieDest,-ItrieSource) */
|
||||
/* itrie_join(+ItrieDest,+ItrieSource) */
|
||||
#define arg_itrie_dest YAP_ARG1
|
||||
#define arg_itrie_source YAP_ARG2
|
||||
static int p_itrie_join(void) {
|
||||
@ -443,7 +442,7 @@ static int p_itrie_join(void) {
|
||||
#undef arg_itrie_source
|
||||
|
||||
|
||||
/* itrie_intersect(-ItrieDest,-ItrieSource) */
|
||||
/* itrie_intersect(+ItrieDest,+ItrieSource) */
|
||||
#define arg_itrie_dest YAP_ARG1
|
||||
#define arg_itrie_source YAP_ARG2
|
||||
static int p_itrie_intersect(void) {
|
||||
@ -461,7 +460,7 @@ static int p_itrie_intersect(void) {
|
||||
#undef arg_itrie_source
|
||||
|
||||
|
||||
/* itrie_count_join(-Itrie1,-Itrie2,+Entries) */
|
||||
/* itrie_count_join(+Itrie1,+Itrie2,-Entries) */
|
||||
#define arg_itrie1 YAP_ARG1
|
||||
#define arg_itrie2 YAP_ARG2
|
||||
#define arg_entries YAP_ARG3
|
||||
@ -483,7 +482,7 @@ static int p_itrie_count_join(void) {
|
||||
#undef arg_entries
|
||||
|
||||
|
||||
/* itrie_count_intersect(-Itrie1,-Itrie2,+Entries) */
|
||||
/* itrie_count_intersect(+Itrie1,+Itrie2,-Entries) */
|
||||
#define arg_itrie1 YAP_ARG1
|
||||
#define arg_itrie2 YAP_ARG2
|
||||
#define arg_entries YAP_ARG3
|
||||
@ -505,7 +504,7 @@ static int p_itrie_count_intersect(void) {
|
||||
#undef arg_entries
|
||||
|
||||
|
||||
/* itrie_save(-Itrie,-FileName) */
|
||||
/* itrie_save(+Itrie,+FileName) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_file YAP_ARG2
|
||||
static int p_itrie_save(void) {
|
||||
@ -533,7 +532,7 @@ static int p_itrie_save(void) {
|
||||
#undef arg_file
|
||||
|
||||
|
||||
/* itrie_save_as_trie(-Itrie,-FileName) */
|
||||
/* itrie_save_as_trie(+Itrie,+FileName) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_file YAP_ARG2
|
||||
static int p_itrie_save_as_trie(void) {
|
||||
@ -561,7 +560,7 @@ static int p_itrie_save_as_trie(void) {
|
||||
#undef arg_file
|
||||
|
||||
|
||||
/* itrie_load(+Itrie,-FileName) */
|
||||
/* itrie_load(-Itrie,+FileName) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_file YAP_ARG2
|
||||
static int p_itrie_load(void) {
|
||||
@ -581,10 +580,9 @@ static int p_itrie_load(void) {
|
||||
return FALSE;
|
||||
|
||||
/* load itrie and close file */
|
||||
itrie = itrie_load(file);
|
||||
if (fclose(file))
|
||||
if (!(itrie = itrie_load(file)))
|
||||
return FALSE;
|
||||
if (!itrie)
|
||||
if (fclose(file))
|
||||
return FALSE;
|
||||
return YAP_Unify(arg_itrie, YAP_MkIntTerm((YAP_Int) itrie));
|
||||
}
|
||||
@ -592,7 +590,49 @@ static int p_itrie_load(void) {
|
||||
#undef arg_file
|
||||
|
||||
|
||||
/* itrie_stats(+Memory,+Tries,+Entries,+Nodes) */
|
||||
/* itrie_save2stream(+Itrie,+Stream) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_stream YAP_ARG2
|
||||
static int p_itrie_save2stream(void) {
|
||||
FILE *file;
|
||||
|
||||
/* check args */
|
||||
if (!YAP_IsIntTerm(arg_itrie))
|
||||
return FALSE;
|
||||
if ((file = (FILE*) YAP_FileDescriptorFromStream(arg_stream)) == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* save itrie */
|
||||
itrie_save((TrEntry) YAP_IntOfTerm(arg_itrie), file);
|
||||
return TRUE;
|
||||
}
|
||||
#undef arg_itrie
|
||||
#undef arg_stream
|
||||
|
||||
|
||||
/* itrie_loadFromStream(-Itrie,+Stream) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_stream YAP_ARG2
|
||||
static int p_itrie_loadFromStream(void) {
|
||||
TrEntry itrie;
|
||||
FILE *file;
|
||||
|
||||
/* check args */
|
||||
if (!YAP_IsVarTerm(arg_itrie))
|
||||
return FALSE;
|
||||
if (!(file = (FILE*) Yap_FileDescriptorFromStream(arg_stream)))
|
||||
return FALSE;
|
||||
|
||||
/* load itrie */
|
||||
if (!(itrie = itrie_load(file)))
|
||||
return FALSE;
|
||||
return YAP_Unify(arg_itrie, YAP_MkIntTerm((YAP_Int) itrie));
|
||||
}
|
||||
#undef arg_itrie
|
||||
#undef arg_stream
|
||||
|
||||
|
||||
/* itrie_stats(-Memory,-Tries,-Entries,-Nodes) */
|
||||
#define arg_memory YAP_ARG1
|
||||
#define arg_tries YAP_ARG2
|
||||
#define arg_entries YAP_ARG3
|
||||
@ -618,7 +658,7 @@ static int p_itrie_stats(void) {
|
||||
#undef arg_nodes
|
||||
|
||||
|
||||
/* itrie_max_stats(+Memory,+Tries,+Entries,+Nodes) */
|
||||
/* itrie_max_stats(-Memory,-Tries,-Entries,-Nodes) */
|
||||
#define arg_memory YAP_ARG1
|
||||
#define arg_tries YAP_ARG2
|
||||
#define arg_entries YAP_ARG3
|
||||
@ -644,7 +684,7 @@ static int p_itrie_max_stats(void) {
|
||||
#undef arg_nodes
|
||||
|
||||
|
||||
/* itrie_usage(-Itrie,+Entries,+Nodes,+VirtualNodes) */
|
||||
/* itrie_usage(+Itrie,-Entries,-Nodes,-VirtualNodes) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_entries YAP_ARG2
|
||||
#define arg_nodes YAP_ARG3
|
||||
@ -672,7 +712,7 @@ static int p_itrie_usage(void) {
|
||||
#undef arg_virtualnodes
|
||||
|
||||
|
||||
/* itrie_print(-Itrie) */
|
||||
/* itrie_print(+Itrie) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
static int p_itrie_print(void) {
|
||||
/* check arg */
|
||||
@ -684,44 +724,3 @@ static int p_itrie_print(void) {
|
||||
return TRUE;
|
||||
}
|
||||
#undef arg_itrie
|
||||
|
||||
/* added by nf: itrie_save2stream(+Itrie,+Stream) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_stream YAP_ARG2
|
||||
static int p_itrie_save2stream(void) {
|
||||
FILE *file;
|
||||
|
||||
/* check args */
|
||||
if (!YAP_IsIntTerm(arg_itrie))
|
||||
return FALSE;
|
||||
if ((file=(FILE*)YAP_FileDescriptorFromStream(arg_stream))==NULL)
|
||||
return FALSE;
|
||||
|
||||
/* save itrie and close file */
|
||||
itrie_save((TrEntry) YAP_IntOfTerm(arg_itrie), file);
|
||||
return TRUE;
|
||||
}
|
||||
#undef arg_itrie
|
||||
#undef arg_stream
|
||||
|
||||
/* added by nf: itrie_loadFromStream(-Itrie,+Stream) */
|
||||
#define arg_itrie YAP_ARG1
|
||||
#define arg_stream YAP_ARG2
|
||||
static int p_itrie_loadFromStream(void) {
|
||||
TrEntry itrie;
|
||||
FILE *file;
|
||||
|
||||
/* check args */
|
||||
if (!YAP_IsVarTerm(arg_itrie))
|
||||
return FALSE;
|
||||
if (!(file=(FILE*)Yap_FileDescriptorFromStream(arg_stream)))
|
||||
return FALSE;
|
||||
|
||||
/* load itrie and close file */
|
||||
itrie = itrie_load(file);
|
||||
if (!itrie)
|
||||
return FALSE;
|
||||
return YAP_Unify(arg_itrie, YAP_MkIntTerm((YAP_Int) itrie));
|
||||
}
|
||||
#undef arg_itrie
|
||||
#undef arg_stream
|
||||
|
@ -104,13 +104,13 @@ void init_tries(void) {
|
||||
/* Backwards Compatibility */
|
||||
/* --------------------------------- */
|
||||
|
||||
/* open_trie(+Trie) */
|
||||
/* open_trie(-Trie) */
|
||||
static int p_open_trie(void) {
|
||||
return p_trie_open();
|
||||
}
|
||||
|
||||
|
||||
/* close_trie(-Trie) */
|
||||
/* close_trie(+Trie) */
|
||||
static int p_close_trie(void) {
|
||||
return p_trie_close();
|
||||
}
|
||||
@ -122,7 +122,7 @@ static int p_close_all_tries(void) {
|
||||
}
|
||||
|
||||
|
||||
/* put_trie_entry(-Mode,-Trie,-Entry,+Ref) */
|
||||
/* put_trie_entry(+Mode,+Trie,+Entry,-Ref) */
|
||||
#define arg_mode YAP_ARG1
|
||||
#define arg_trie YAP_ARG2
|
||||
#define arg_entry YAP_ARG3
|
||||
@ -156,7 +156,7 @@ static int p_put_trie_entry(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* get_trie_entry(-Mode,-Ref,+Entry) */
|
||||
/* get_trie_entry(+Mode,+Ref,-Entry) */
|
||||
#define arg_mode YAP_ARG1
|
||||
#define arg_ref YAP_ARG2
|
||||
#define arg_entry YAP_ARG3
|
||||
@ -188,13 +188,13 @@ static int p_get_trie_entry(void) {
|
||||
#undef arg_entry
|
||||
|
||||
|
||||
/* remove_trie_entry(-Ref) */
|
||||
/* remove_trie_entry(+Ref) */
|
||||
static int p_remove_trie_entry(void) {
|
||||
return p_trie_remove_entry();
|
||||
}
|
||||
|
||||
|
||||
/* print_trie(-Trie) */
|
||||
/* print_trie(+Trie) */
|
||||
static int p_print_trie(void) {
|
||||
return p_trie_print();
|
||||
}
|
||||
@ -205,7 +205,7 @@ static int p_print_trie(void) {
|
||||
/* Local Procedures */
|
||||
/* -------------------------- */
|
||||
|
||||
/* trie_open(+Trie) */
|
||||
/* trie_open(-Trie) */
|
||||
#define arg_trie YAP_ARG1
|
||||
static int p_trie_open(void) {
|
||||
TrEntry trie;
|
||||
@ -221,7 +221,7 @@ static int p_trie_open(void) {
|
||||
#undef arg_trie
|
||||
|
||||
|
||||
/* trie_close(-Trie) */
|
||||
/* trie_close(+Trie) */
|
||||
#define arg_trie YAP_ARG1
|
||||
static int p_trie_close(void) {
|
||||
/* check arg */
|
||||
@ -275,7 +275,7 @@ static int p_trie_mode(void) {
|
||||
#undef arg_mode
|
||||
|
||||
|
||||
/* trie_put_entry(-Trie,-Entry,+Ref) */
|
||||
/* trie_put_entry(+Trie,+Entry,-Ref) */
|
||||
#define arg_trie YAP_ARG1
|
||||
#define arg_entry YAP_ARG2
|
||||
#define arg_ref YAP_ARG3
|
||||
@ -295,7 +295,7 @@ static int p_trie_put_entry(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* trie_check_entry(-Trie,-Entry,+Ref) */
|
||||
/* trie_check_entry(+Trie,+Entry,-Ref) */
|
||||
#define arg_trie YAP_ARG1
|
||||
#define arg_entry YAP_ARG2
|
||||
#define arg_ref YAP_ARG3
|
||||
@ -316,7 +316,7 @@ static int p_trie_check_entry(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* trie_get_entry(-Ref,+Entry) */
|
||||
/* trie_get_entry(+Ref,-Entry) */
|
||||
#define arg_ref YAP_ARG1
|
||||
#define arg_entry YAP_ARG2
|
||||
static int p_trie_get_entry(void) {
|
||||
@ -334,7 +334,7 @@ static int p_trie_get_entry(void) {
|
||||
#undef arg_entry
|
||||
|
||||
|
||||
/* trie_get_first_entry(-Trie,+Ref) */
|
||||
/* trie_get_first_entry(+Trie,-Ref) */
|
||||
#define arg_trie YAP_ARG1
|
||||
#define arg_ref YAP_ARG2
|
||||
static int p_trie_get_first_entry(void) {
|
||||
@ -353,7 +353,7 @@ static int p_trie_get_first_entry(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* trie_get_last_entry(-Trie,+Ref) */
|
||||
/* trie_get_last_entry(+Trie,-Ref) */
|
||||
#define arg_trie YAP_ARG1
|
||||
#define arg_ref YAP_ARG2
|
||||
static int p_trie_get_last_entry(void) {
|
||||
@ -372,7 +372,7 @@ static int p_trie_get_last_entry(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* trie_traverse(-Trie,-FirstRef,+Ref) */
|
||||
/* trie_traverse(+Trie,+FirstRef,-Ref) */
|
||||
#define arg_trie YAP_ARG1
|
||||
#define arg_init_ref YAP_ARG2
|
||||
#define arg_ref YAP_ARG3
|
||||
@ -397,7 +397,7 @@ static int p_trie_traverse_init(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* trie_traverse(-Trie,-FirstRef,+Ref) */
|
||||
/* trie_traverse(+Trie,+FirstRef,-Ref) */
|
||||
#define arg_trie YAP_ARG1
|
||||
#define arg_init_ref YAP_ARG2
|
||||
#define arg_ref YAP_ARG3
|
||||
@ -416,7 +416,7 @@ static int p_trie_traverse_cont(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* trie_remove_entry(-Ref) */
|
||||
/* trie_remove_entry(+Ref) */
|
||||
#define arg_ref YAP_ARG1
|
||||
static int p_trie_remove_entry(void) {
|
||||
/* check arg */
|
||||
@ -430,7 +430,7 @@ static int p_trie_remove_entry(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* trie_remove_subtree(-Ref) */
|
||||
/* trie_remove_subtree(+Ref) */
|
||||
#define arg_ref YAP_ARG1
|
||||
static int p_trie_remove_subtree(void) {
|
||||
/* check arg */
|
||||
@ -444,7 +444,7 @@ static int p_trie_remove_subtree(void) {
|
||||
#undef arg_ref
|
||||
|
||||
|
||||
/* trie_join(-TrieDest,-TrieSource) */
|
||||
/* trie_join(+TrieDest,+TrieSource) */
|
||||
#define arg_trie_dest YAP_ARG1
|
||||
#define arg_trie_source YAP_ARG2
|
||||
static int p_trie_join(void) {
|
||||
@ -462,7 +462,7 @@ static int p_trie_join(void) {
|
||||
#undef arg_trie_source
|
||||
|
||||
|
||||
/* trie_intersect(-TrieDest,-TrieSource) */
|
||||
/* trie_intersect(+TrieDest,+TrieSource) */
|
||||
#define arg_trie_dest YAP_ARG1
|
||||
#define arg_trie_source YAP_ARG2
|
||||
static int p_trie_intersect(void) {
|
||||
@ -480,7 +480,7 @@ static int p_trie_intersect(void) {
|
||||
#undef arg_trie_source
|
||||
|
||||
|
||||
/* trie_count_join(-Trie1,-Trie2,+Entries) */
|
||||
/* trie_count_join(+Trie1,+Trie2,-Entries) */
|
||||
#define arg_trie1 YAP_ARG1
|
||||
#define arg_trie2 YAP_ARG2
|
||||
#define arg_entries YAP_ARG3
|
||||
@ -502,7 +502,7 @@ static int p_trie_count_join(void) {
|
||||
#undef arg_entries
|
||||
|
||||
|
||||
/* trie_count_intersect(-Trie1,-Trie2,+Entries) */
|
||||
/* trie_count_intersect(+Trie1,+Trie2,-Entries) */
|
||||
#define arg_trie1 YAP_ARG1
|
||||
#define arg_trie2 YAP_ARG2
|
||||
#define arg_entries YAP_ARG3
|
||||
@ -524,7 +524,7 @@ static int p_trie_count_intersect(void) {
|
||||
#undef arg_entries
|
||||
|
||||
|
||||
/* trie_save(-Trie,-FileName) */
|
||||
/* trie_save(+Trie,+FileName) */
|
||||
#define arg_trie YAP_ARG1
|
||||
#define arg_file YAP_ARG2
|
||||
static int p_trie_save(void) {
|
||||
@ -552,7 +552,7 @@ static int p_trie_save(void) {
|
||||
#undef arg_file
|
||||
|
||||
|
||||
/* trie_load(+Trie,-FileName) */
|
||||
/* trie_load(-Trie,+FileName) */
|
||||
#define arg_trie YAP_ARG1
|
||||
#define arg_file YAP_ARG2
|
||||
static int p_trie_load(void) {
|
||||
@ -572,10 +572,9 @@ static int p_trie_load(void) {
|
||||
return FALSE;
|
||||
|
||||
/* load trie and close file */
|
||||
data = trie_load(file);
|
||||
if (fclose(file))
|
||||
if (!(data = trie_load(file)))
|
||||
return FALSE;
|
||||
if (!data)
|
||||
if (fclose(file))
|
||||
return FALSE;
|
||||
return YAP_Unify(arg_trie, YAP_MkIntTerm((YAP_Int) data));
|
||||
}
|
||||
@ -583,7 +582,7 @@ static int p_trie_load(void) {
|
||||
#undef arg_file
|
||||
|
||||
|
||||
/* trie_stats(+Memory,+Tries,+Entries,+Nodes) */
|
||||
/* trie_stats(-Memory,-Tries,-Entries,-Nodes) */
|
||||
#define arg_memory YAP_ARG1
|
||||
#define arg_tries YAP_ARG2
|
||||
#define arg_entries YAP_ARG3
|
||||
@ -609,7 +608,7 @@ static int p_trie_stats(void) {
|
||||
#undef arg_nodes
|
||||
|
||||
|
||||
/* trie_max_stats(+Memory,+Tries,+Entries,+Nodes) */
|
||||
/* trie_max_stats(-Memory,-Tries,-Entries,-Nodes) */
|
||||
#define arg_memory YAP_ARG1
|
||||
#define arg_tries YAP_ARG2
|
||||
#define arg_entries YAP_ARG3
|
||||
@ -635,7 +634,7 @@ static int p_trie_max_stats(void) {
|
||||
#undef arg_nodes
|
||||
|
||||
|
||||
/* trie_usage(-Trie,+Entries,+Nodes,+VirtualNodes) */
|
||||
/* trie_usage(+Trie,-Entries,-Nodes,-VirtualNodes) */
|
||||
#define arg_trie YAP_ARG1
|
||||
#define arg_entries YAP_ARG2
|
||||
#define arg_nodes YAP_ARG3
|
||||
@ -663,7 +662,7 @@ static int p_trie_usage(void) {
|
||||
#undef arg_virtualnodes
|
||||
|
||||
|
||||
/* trie_print(-Trie) */
|
||||
/* trie_print(+Trie) */
|
||||
#define arg_trie YAP_ARG1
|
||||
static int p_trie_print(void) {
|
||||
/* check arg */
|
||||
|
Reference in New Issue
Block a user