new support for join/intersect operations

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2086 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
ricroc 2008-02-11 17:00:23 +00:00
parent d39002c271
commit 1ac399f57b
8 changed files with 496 additions and 96 deletions

View File

@ -72,6 +72,17 @@ void itrie_data_print(TrNode node) {
}
inline
void itrie_data_construct(TrNode node_dest, TrNode node_source) {
TrData data_dest, data_source;
data_source = (TrData) GET_DATA_FROM_LEAF_TRIE_NODE(node_source);
new_itrie_data(data_dest, CURRENT_ITRIE, node_dest, TrData_pos(data_source), TrData_neg(data_source), TrData_timestamp(data_source), TrData_depth(data_source));
PUT_DATA_IN_LEAF_TRIE_NODE(node_dest, data_dest);
return;
}
inline
void itrie_data_destruct(TrNode node) {
TrEntry itrie;
@ -95,17 +106,12 @@ inline
void itrie_data_add(TrNode node_dest, TrNode node_source) {
TrData data_dest, data_source;
data_dest = (TrData) GET_DATA_FROM_LEAF_TRIE_NODE(node_dest);
data_source = (TrData) GET_DATA_FROM_LEAF_TRIE_NODE(node_source);
if (!(data_dest = (TrData) GET_DATA_FROM_LEAF_TRIE_NODE(node_dest))) {
new_itrie_data(data_dest, CURRENT_ITRIE, node_dest, TrData_pos(data_source), TrData_neg(data_source),
TrData_timestamp(data_source), TrData_depth(data_source));
PUT_DATA_IN_LEAF_TRIE_NODE(node_dest, data_dest);
} else {
TrData_pos(data_dest) += TrData_pos(data_source);
TrData_neg(data_dest) += TrData_neg(data_source);
if (TrData_timestamp(data_dest) < TrData_timestamp(data_source))
TrData_timestamp(data_dest) = TrData_timestamp(data_source);
}
TrData_pos(data_dest) += TrData_pos(data_source);
TrData_neg(data_dest) += TrData_neg(data_source);
if (TrData_timestamp(data_dest) < TrData_timestamp(data_source))
TrData_timestamp(data_dest) = TrData_timestamp(data_source);
return;
}
@ -302,14 +308,6 @@ void itrie_remove_subtree(TrData data) {
}
inline
void itrie_join(TrEntry itrie_dest, TrEntry itrie_source) {
CURRENT_ITRIE = itrie_dest;
trie_join(ITRIE_ENGINE, TrEntry_trie(itrie_dest), TrEntry_trie(itrie_source), &itrie_data_add);
return;
}
inline
void itrie_add(TrEntry itrie_dest, TrEntry itrie_source) {
trie_add(TrEntry_trie(itrie_dest), TrEntry_trie(itrie_source), &itrie_data_add);
@ -324,6 +322,33 @@ void itrie_subtract(TrEntry itrie_dest, TrEntry itrie_source) {
}
inline
void itrie_join(TrEntry itrie_dest, TrEntry itrie_source) {
CURRENT_ITRIE = itrie_dest;
trie_join(ITRIE_ENGINE, TrEntry_trie(itrie_dest), TrEntry_trie(itrie_source), &itrie_data_add, &itrie_data_construct);
return;
}
inline
void itrie_intersect(TrEntry itrie_dest, TrEntry itrie_source) {
trie_intersect(ITRIE_ENGINE, TrEntry_trie(itrie_dest), TrEntry_trie(itrie_source), &itrie_data_add, &itrie_data_destruct);
return;
}
inline
YAP_Int itrie_count_join(TrEntry itrie1, TrEntry itrie2) {
return trie_count_join(TrEntry_trie(itrie1), TrEntry_trie(itrie2));
}
inline
YAP_Int itrie_count_intersect(TrEntry itrie1, TrEntry itrie2) {
return trie_count_intersect(TrEntry_trie(itrie1), TrEntry_trie(itrie2));
}
inline
void itrie_save(TrEntry itrie, FILE *file) {
trie_save(TrEntry_trie(itrie), file, &itrie_data_save);

View File

@ -171,6 +171,7 @@ inline void itrie_init_module(void);
inline void itrie_data_save(TrNode node, FILE *file);
inline void itrie_data_load(TrNode node, YAP_Int depth, FILE *file);
inline void itrie_data_print(TrNode node);
inline void itrie_data_construct(TrNode node_dest, TrNode node_source);
inline void itrie_data_destruct(TrNode node);
inline void itrie_data_add(TrNode node_dest, TrNode node_source);
inline void itrie_data_subtract(TrNode node_dest, TrNode node_source);
@ -190,9 +191,12 @@ inline TrData itrie_traverse_init(TrEntry itrie);
inline TrData itrie_traverse_cont(TrEntry itrie);
inline void itrie_remove_entry(TrData data);
inline void itrie_remove_subtree(TrData data);
inline void itrie_join(TrEntry itrie_dest, TrEntry itrie_source);
inline void itrie_add(TrEntry itrie_dest, TrEntry itrie_source);
inline void itrie_subtract(TrEntry itrie_dest, TrEntry itrie_source);
inline void itrie_join(TrEntry itrie_dest, TrEntry itrie_source);
inline void itrie_intersect(TrEntry itrie_dest, TrEntry itrie_source);
inline YAP_Int itrie_count_join(TrEntry itrie1, TrEntry itrie2);
inline YAP_Int itrie_count_intersect(TrEntry itrie1, TrEntry itrie2);
inline void itrie_save(TrEntry itrie, FILE *file);
inline TrEntry itrie_load(FILE *file);
inline void itrie_stats(YAP_Int *memory, YAP_Int *tries, YAP_Int *entries, YAP_Int *nodes);

View File

@ -28,8 +28,11 @@ static YAP_Term get_trie(TrNode node, YAP_Term *stack_list, TrNode *cur_node);
static void remove_trie(TrNode node);
static void free_child_nodes(TrNode node);
static TrNode copy_child_nodes(TrNode parent_dest, TrNode node_source);
static void traverse_tries_join(TrNode parent_dest, TrNode parent_source);
static void traverse_tries(TrNode parent_dest, TrNode parent_source);
static void traverse_tries_join(TrNode parent_dest, TrNode parent_source);
static void traverse_tries_intersect(TrNode parent_dest, TrNode parent_source);
static YAP_Int count_tries_intersect(TrNode parent1, TrNode parent2);
static YAP_Int count_trie(TrNode node);
static void traverse_trie_usage(TrNode node, YAP_Int depth);
static void traverse_trie_save(TrNode node, FILE *file, int float_block);
static void traverse_trie_load(TrNode parent, FILE *file);
@ -50,8 +53,9 @@ static YAP_Functor FunctorComma;
static void (*DATA_SAVE_FUNCTION)(TrNode, FILE *);
static void (*DATA_LOAD_FUNCTION)(TrNode, YAP_Int, FILE *);
static void (*DATA_PRINT_FUNCTION)(TrNode);
static void (*DATA_ADD_FUNCTION)(TrNode, TrNode);
static void (*DATA_CONSTRUCT_FUNCTION)(TrNode, TrNode);
static void (*DATA_DESTRUCT_FUNCTION)(TrNode);
static void (*DATA_JOIN_FUNCTION)(TrNode, TrNode);
@ -341,9 +345,19 @@ void trie_remove_subtree(TrEngine engine, TrNode node, void (*destruct_function)
inline
void trie_join(TrEngine engine, TrNode node_dest, TrNode node_source, void (*add_function)(TrNode, TrNode)) {
void trie_add(TrNode node_dest, TrNode node_source, void (*add_function)(TrNode, TrNode)) {
DATA_ADD_FUNCTION = add_function;
if (TrNode_child(node_dest) && TrNode_child(node_source))
traverse_tries(node_dest, node_source);
return;
}
inline
void trie_join(TrEngine engine, TrNode node_dest, TrNode node_source, void (*add_function)(TrNode, TrNode), void (*construct_function)(TrNode, TrNode)) {
CURRENT_TRIE_ENGINE = engine;
DATA_JOIN_FUNCTION = add_function;
DATA_ADD_FUNCTION = add_function;
DATA_CONSTRUCT_FUNCTION = construct_function;
if (TrNode_child(node_dest)) {
if (TrNode_child(node_source))
traverse_tries_join(node_dest, node_source);
@ -354,14 +368,49 @@ void trie_join(TrEngine engine, TrNode node_dest, TrNode node_source, void (*add
inline
void trie_add(TrNode node_dest, TrNode node_source, void (*add_function)(TrNode, TrNode)) {
DATA_JOIN_FUNCTION = add_function;
if (TrNode_child(node_dest) && TrNode_child(node_source))
traverse_tries(node_dest, node_source);
void trie_intersect(TrEngine engine, TrNode node_dest, TrNode node_source, void (*add_function)(TrNode, TrNode), void (*destruct_function)(TrNode)) {
CURRENT_TRIE_ENGINE = engine;
DATA_ADD_FUNCTION = add_function;
DATA_DESTRUCT_FUNCTION = destruct_function;
if (TrNode_child(node_dest)) {
if (TrNode_child(node_source))
traverse_tries_intersect(node_dest, node_source);
else {
free_child_nodes(TrNode_child(node_dest));
TrNode_child(node_dest) = NULL;
}
}
return;
}
inline
YAP_Int trie_count_join(TrNode node1, TrNode node2) {
YAP_Int count = 0;
if (TrNode_child(node1)) {
count += count_trie(TrNode_child(node1));
if (TrNode_child(node2)) {
count += count_trie(TrNode_child(node2));
count -= count_tries_intersect(node1, node2);
}
} else if (TrNode_child(node2))
count += count_trie(TrNode_child(node2));
return count;
}
inline
YAP_Int trie_count_intersect(TrNode node1, TrNode node2) {
YAP_Int count = 0;
if (TrNode_child(node1))
if (TrNode_child(node2))
count = count_tries_intersect(node1, node2);
return count;
}
inline
void trie_save(TrNode node, FILE *file, void (*save_function)(TrNode, FILE *)) {
CURRENT_INDEX = -1;
@ -813,7 +862,8 @@ TrNode copy_child_nodes(TrNode parent_dest, TrNode child_source) {
if (IS_LEAF_TRIE_NODE(child_source)) {
MARK_AS_LEAF_TRIE_NODE(child_dest);
INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
(*DATA_JOIN_FUNCTION)(child_dest, child_source);
if (DATA_CONSTRUCT_FUNCTION)
(*DATA_CONSTRUCT_FUNCTION)(child_dest, child_source);
} else
TrNode_child(child_dest) = copy_child_nodes(child_dest, TrNode_child(child_source));
return child_dest;
@ -821,9 +871,10 @@ TrNode copy_child_nodes(TrNode parent_dest, TrNode child_source) {
static
void traverse_tries_join(TrNode parent_dest, TrNode parent_source){
void traverse_tries(TrNode parent_dest, TrNode parent_source) {
TrNode child_dest, child_source;
/* parent_source is not a leaf node */
child_source = TrNode_child(parent_source);
if (IS_HASH_NODE(child_source)) {
TrNode *first_bucket_source, *bucket_source;
@ -834,20 +885,72 @@ void traverse_tries_join(TrNode parent_dest, TrNode parent_source){
do {
child_source = *--bucket_source;
while (child_source) {
/* parent_dest cannot be a leaf node */
/* parent_dest is not a leaf node */
child_dest = trie_node_check(parent_dest, TrNode_entry(child_source));
if (child_dest) {
if (IS_LEAF_TRIE_NODE(child_dest))
(*DATA_JOIN_FUNCTION)(child_dest, child_source);
else
/* child_dest is not a leaf node */
if (IS_LEAF_TRIE_NODE(child_dest)) {
/* child_source is a leaf node */
if (DATA_ADD_FUNCTION)
(*DATA_ADD_FUNCTION)(child_dest, child_source);
} else
/* child_dest and child_source are not leaf nodes */
traverse_tries(child_dest, child_source);
}
child_source = TrNode_next(child_source);
}
} while (bucket_source != first_bucket_source);
return;
}
while (child_source) {
/* parent_dest is not a leaf node */
child_dest = trie_node_check(parent_dest, TrNode_entry(child_source));
if (child_dest) {
if (IS_LEAF_TRIE_NODE(child_dest)) {
/* child_source is a leaf node */
if (DATA_ADD_FUNCTION)
(*DATA_ADD_FUNCTION)(child_dest, child_source);
} else
/* child_dest and child_source are not leaf nodes */
traverse_tries(child_dest, child_source);
}
child_source = TrNode_next(child_source);
}
return;
}
static
void traverse_tries_join(TrNode parent_dest, TrNode parent_source) {
TrNode child_dest, child_source;
/* parent_source is not a leaf node */
child_source = TrNode_child(parent_source);
if (IS_HASH_NODE(child_source)) {
TrNode *first_bucket_source, *bucket_source;
TrHash hash_source;
hash_source = (TrHash) child_source;
first_bucket_source = TrHash_buckets(hash_source);
bucket_source = first_bucket_source + TrHash_num_buckets(hash_source);
do {
child_source = *--bucket_source;
while (child_source) {
/* parent_dest is not a leaf node */
child_dest = trie_node_check(parent_dest, TrNode_entry(child_source));
if (child_dest) {
if (IS_LEAF_TRIE_NODE(child_dest)) {
/* child_source is a leaf node */
if (DATA_ADD_FUNCTION)
(*DATA_ADD_FUNCTION)(child_dest, child_source);
} else
/* child_dest and child_source are not leaf nodes */
traverse_tries_join(child_dest, child_source);
} else {
child_dest = trie_node_check_insert(parent_dest, TrNode_entry(child_source));
if (IS_LEAF_TRIE_NODE(child_source)) {
MARK_AS_LEAF_TRIE_NODE(child_dest);
INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
(*DATA_JOIN_FUNCTION)(child_dest, child_source);
if (DATA_ADD_FUNCTION)
(*DATA_ADD_FUNCTION)(child_dest, child_source);
} else
TrNode_child(child_dest) = copy_child_nodes(child_dest, TrNode_child(child_source));
}
@ -857,20 +960,23 @@ void traverse_tries_join(TrNode parent_dest, TrNode parent_source){
return;
}
while (child_source) {
/* parent_dest cannot be a leaf node */
/* parent_dest is not a leaf node */
child_dest = trie_node_check(parent_dest, TrNode_entry(child_source));
if (child_dest) {
if (IS_LEAF_TRIE_NODE(child_dest))
(*DATA_JOIN_FUNCTION)(child_dest, child_source);
else
/* child_dest is not a leaf node */
if (IS_LEAF_TRIE_NODE(child_dest)) {
/* child_source is a leaf node */
if (DATA_ADD_FUNCTION)
(*DATA_ADD_FUNCTION)(child_dest, child_source);
} else
/* child_dest and child_source are not leaf nodes */
traverse_tries_join(child_dest, child_source);
} else {
child_dest = trie_node_check_insert(parent_dest, TrNode_entry(child_source));
if (IS_LEAF_TRIE_NODE(child_source)) {
MARK_AS_LEAF_TRIE_NODE(child_dest);
INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
(*DATA_JOIN_FUNCTION)(child_dest, child_source);
if (DATA_ADD_FUNCTION)
(*DATA_ADD_FUNCTION)(child_dest, child_source);
} else
TrNode_child(child_dest) = copy_child_nodes(child_dest, TrNode_child(child_source));
}
@ -881,51 +987,149 @@ void traverse_tries_join(TrNode parent_dest, TrNode parent_source){
static
void traverse_tries(TrNode parent_dest, TrNode parent_source) {
TrNode child_dest, child_source;
void traverse_tries_intersect(TrNode parent_dest, TrNode parent_source) {
TrNode child_dest, child_source, child_next;
child_source = TrNode_child(parent_source);
if (IS_HASH_NODE(child_source)) {
TrNode *first_bucket_source, *bucket_source;
TrHash hash_source;
hash_source = (TrHash) child_source;
first_bucket_source = TrHash_buckets(hash_source);
bucket_source = first_bucket_source + TrHash_num_buckets(hash_source);
/* parent_dest is not a leaf node */
child_dest = TrNode_child(parent_dest);
if (IS_HASH_NODE(child_dest)) {
TrNode *first_bucket_dest, *bucket_dest;
TrHash hash_dest;
hash_dest = (TrHash) child_dest;
first_bucket_dest = TrHash_buckets(hash_dest);
bucket_dest = first_bucket_dest + TrHash_num_buckets(hash_dest);
do {
child_source = *--bucket_source;
while (child_source) {
/* parent_dest cannot be a leaf node */
child_dest = trie_node_check(parent_dest, TrNode_entry(child_source));
if (child_dest) {
child_dest = *--bucket_dest;
while (child_dest) {
child_next = TrNode_next(child_dest);
/* parent_source is not a leaf node */
child_source = trie_node_check(parent_source, TrNode_entry(child_dest));
if (child_source) {
if (IS_LEAF_TRIE_NODE(child_dest)) {
if (IS_LEAF_TRIE_NODE(child_source))
(*DATA_JOIN_FUNCTION)(child_dest, child_source);
/* child_source is a leaf node */
if (DATA_ADD_FUNCTION)
(*DATA_ADD_FUNCTION)(child_dest, child_source);
} else
/* child_dest is not a leaf node */
traverse_tries(child_dest, child_source);
/* child_dest and child_source are not leaf nodes */
traverse_tries_intersect(child_dest, child_source);
} else {
if (IS_LEAF_TRIE_NODE(child_dest)) {
if (DATA_DESTRUCT_FUNCTION)
(*DATA_DESTRUCT_FUNCTION)(child_dest);
DECREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
} else
free_child_nodes(TrNode_child(child_dest));
remove_trie(child_dest);
}
child_source = TrNode_next(child_source);
child_dest = child_next;
}
} while (bucket_source != first_bucket_source);
} while (bucket_dest != first_bucket_dest);
return;
}
while (child_source) {
/* parent_dest cannot be a leaf node */
child_dest = trie_node_check(parent_dest, TrNode_entry(child_source));
if (child_dest) {
while (child_dest) {
child_next = TrNode_next(child_dest);
/* parent_source is not a leaf node */
child_source = trie_node_check(parent_source, TrNode_entry(child_dest));
if (child_source) {
if (IS_LEAF_TRIE_NODE(child_dest)) {
if (IS_LEAF_TRIE_NODE(child_source))
(*DATA_JOIN_FUNCTION)(child_dest, child_source);
/* child_source is a leaf node */
if (DATA_ADD_FUNCTION)
(*DATA_ADD_FUNCTION)(child_dest, child_source);
} else
/* child_dest is not a leaf node */
traverse_tries(child_dest, child_source);
/* child_dest and child_source are not leaf nodes */
traverse_tries_intersect(child_dest, child_source);
} else {
if (IS_LEAF_TRIE_NODE(child_dest)) {
if (DATA_DESTRUCT_FUNCTION)
(*DATA_DESTRUCT_FUNCTION)(child_dest);
DECREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
} else
free_child_nodes(TrNode_child(child_dest));
remove_trie(child_dest);
}
child_source = TrNode_next(child_source);
child_dest = child_next;
}
return;
}
static
YAP_Int count_tries_intersect(TrNode parent1, TrNode parent2) {
TrNode child1, child2;
YAP_Int count = 0;
/* parent1 is not a leaf node */
child1 = TrNode_child(parent1);
if (IS_HASH_NODE(child1)) {
TrNode *first_bucket, *bucket;
TrHash hash;
hash = (TrHash) child1;
first_bucket = TrHash_buckets(hash);
bucket = first_bucket + TrHash_num_buckets(hash);
do {
child1 = *--bucket;
while (child1) {
/* parent2 is not a leaf node */
child2 = trie_node_check(parent2, TrNode_entry(child1));
if (child2) {
if (IS_LEAF_TRIE_NODE(child1))
/* child2 is a leaf node */
count++;
else
/* child1 and child2 are not leaf nodes */
count += count_tries_intersect(child1, child2);
}
child1 = TrNode_next(child1);
}
} while (bucket != first_bucket);
return count;
}
while (child1) {
/* parent2 is not a leaf node */
child2 = trie_node_check(parent2, TrNode_entry(child1));
if (child2) {
if (IS_LEAF_TRIE_NODE(child1))
/* child2 is a leaf node */
count++;
else
/* child1 and child2 are not leaf nodes */
count += count_tries_intersect(child1, child2);
}
child1 = TrNode_next(child1);
}
return count;
}
static
YAP_Int count_trie(TrNode node) {
YAP_Int count = 0;
if (IS_HASH_NODE(node)) {
TrNode *first_bucket, *bucket;
TrHash hash;
hash = (TrHash) node;
first_bucket = TrHash_buckets(hash);
bucket = first_bucket + TrHash_num_buckets(hash);
do {
if (*--bucket) {
node = *bucket;
count += count_trie(node);
}
} while (bucket != first_bucket);
return count;
}
if (TrNode_next(node))
count += count_trie(TrNode_next(node));
if (!IS_LEAF_TRIE_NODE(node))
count += count_trie(TrNode_child(node));
else
count++;
return count;
}
static
void traverse_trie_usage(TrNode node, YAP_Int depth) {
if (IS_HASH_NODE(node)) {

View File

@ -38,15 +38,16 @@
#define FloatInitTag 67 /* 0x43 */
#define FloatEndTag 83 /* 0x53 */
#define TRIE_MODE_STANDARD 0
#define TRIE_MODE_REVERSE 1
#define BASE_AUXILIARY_TERM_STACK_SIZE 1000
#define TRIE_MODE_STANDARD 0
#define TRIE_MODE_REVERSE 1
#define TRIE_PRINT_NORMAL 0
#define TRIE_PRINT_FLOAT 1
#define TRIE_PRINT_FLOAT2 2
#define TRIE_PRINT_FLOAT_END 3
#define BASE_AUXILIARY_TERM_STACK_SIZE 1000
/* --------------------------- */
@ -270,13 +271,16 @@ inline void trie_close(TrEngine engine, TrNode node, void (*destruct_functio
inline void trie_close_all(TrEngine engine, void (*destruct_function)(TrNode));
inline void trie_set_mode(YAP_Int mode);
inline YAP_Int trie_get_mode(void);
inline TrNode trie_put_entry(TrEngine engine, TrNode node, YAP_Term entry, YAP_Int *depth);
inline TrNode trie_put_entry(TrEngine engine, TrNode node, YAP_Term entry, YAP_Int *depth);
inline TrNode trie_check_entry(TrNode node, YAP_Term entry);
inline YAP_Term trie_get_entry(TrNode node);
inline void trie_remove_entry(TrEngine engine, TrNode node, void (*destruct_function)(TrNode));
inline void trie_remove_subtree(TrEngine engine, TrNode node, void (*destruct_function)(TrNode));
inline void trie_join(TrEngine engine, TrNode node_dest, TrNode node_source, void (*add_function)(TrNode, TrNode));
inline void trie_add(TrNode node_dest, TrNode node_source, void (*add_function)(TrNode, TrNode));
inline void trie_join(TrEngine engine, TrNode node_dest, TrNode node_source, void (*add_function)(TrNode, TrNode), void (*construct_function)(TrNode, TrNode));
inline void trie_intersect(TrEngine engine, TrNode node_dest, TrNode node_source, void (*add_function)(TrNode, TrNode), void (*destruct_function)(TrNode));
inline YAP_Int trie_count_join(TrNode node1, TrNode node2);
inline YAP_Int trie_count_intersect(TrNode node1, TrNode node2);
inline void trie_save(TrNode node, FILE *file, void (*save_function)(TrNode, FILE *));
inline TrNode trie_load(TrEngine engine, FILE *file, void (*load_function)(TrNode, YAP_Int, FILE *));
inline void trie_stats(TrEngine engine, YAP_Int *memory, YAP_Int *tries, YAP_Int *entries, YAP_Int *nodes);

View File

@ -38,9 +38,12 @@ static int p_itrie_traverse_init(void);
static int p_itrie_traverse_cont(void);
static int p_itrie_remove_entry(void);
static int p_itrie_remove_subtree(void);
static int p_itrie_join(void);
static int p_itrie_add(void);
static int p_itrie_subtract(void);
static int p_itrie_join(void);
static int p_itrie_intersect(void);
static int p_itrie_count_join(void);
static int p_itrie_count_intersect(void);
static int p_itrie_save(void);
static int p_itrie_load(void);
static int p_itrie_stats(void);
@ -70,9 +73,12 @@ void init_itries(void) {
YAP_UserBackCPredicate("itrie_traverse", p_itrie_traverse_init, p_itrie_traverse_cont, 2, 0);
YAP_UserCPredicate("itrie_remove_entry", p_itrie_remove_entry, 1);
YAP_UserCPredicate("itrie_remove_subtree", p_itrie_remove_subtree, 1);
YAP_UserCPredicate("itrie_join", p_itrie_join, 2);
YAP_UserCPredicate("itrie_add", p_itrie_add, 2);
YAP_UserCPredicate("itrie_subtract", p_itrie_subtract, 2);
YAP_UserCPredicate("itrie_join", p_itrie_join, 2);
YAP_UserCPredicate("itrie_intersect", p_itrie_intersect, 2);
YAP_UserCPredicate("itrie_count_join", p_itrie_count_join, 3);
YAP_UserCPredicate("itrie_count_intersect", p_itrie_count_intersect, 3);
YAP_UserCPredicate("itrie_save", p_itrie_save, 2);
YAP_UserCPredicate("itrie_load", p_itrie_load, 2);
YAP_UserCPredicate("itrie_stats", p_itrie_stats, 4);
@ -376,24 +382,6 @@ static int p_itrie_remove_subtree(void) {
#undef arg_ref
/* itrie_join(-ItrieDest,-ItrieSource) */
#define arg_itrie_dest YAP_ARG1
#define arg_itrie_source YAP_ARG2
static int p_itrie_join(void) {
/* check args */
if (!YAP_IsIntTerm(arg_itrie_dest))
return FALSE;
if (!YAP_IsIntTerm(arg_itrie_source))
return FALSE;
/* join itrie */
itrie_join((TrEntry) YAP_IntOfTerm(arg_itrie_dest), (TrEntry) YAP_IntOfTerm(arg_itrie_source));
return TRUE;
}
#undef arg_itrie_dest
#undef arg_itrie_source
/* itrie_add(-ItrieDest,-ItrieSource) */
#define arg_itrie_dest YAP_ARG1
#define arg_itrie_source YAP_ARG2
@ -430,6 +418,86 @@ static int p_itrie_subtract(void) {
#undef arg_itrie_source
/* itrie_join(-ItrieDest,-ItrieSource) */
#define arg_itrie_dest YAP_ARG1
#define arg_itrie_source YAP_ARG2
static int p_itrie_join(void) {
/* check args */
if (!YAP_IsIntTerm(arg_itrie_dest))
return FALSE;
if (!YAP_IsIntTerm(arg_itrie_source))
return FALSE;
/* join itrie */
itrie_join((TrEntry) YAP_IntOfTerm(arg_itrie_dest), (TrEntry) YAP_IntOfTerm(arg_itrie_source));
return TRUE;
}
#undef arg_itrie_dest
#undef arg_itrie_source
/* itrie_intersect(-ItrieDest,-ItrieSource) */
#define arg_itrie_dest YAP_ARG1
#define arg_itrie_source YAP_ARG2
static int p_itrie_intersect(void) {
/* check args */
if (!YAP_IsIntTerm(arg_itrie_dest))
return FALSE;
if (!YAP_IsIntTerm(arg_itrie_source))
return FALSE;
/* intersect itrie */
itrie_intersect((TrEntry) YAP_IntOfTerm(arg_itrie_dest), (TrEntry) YAP_IntOfTerm(arg_itrie_source));
return TRUE;
}
#undef arg_itrie_dest
#undef arg_itrie_source
/* itrie_count_join(-Itrie1,-Itrie2,+Entries) */
#define arg_itrie1 YAP_ARG1
#define arg_itrie2 YAP_ARG2
#define arg_entries YAP_ARG3
static int p_itrie_count_join(void) {
YAP_Int entries;
/* check args */
if (!YAP_IsIntTerm(arg_itrie1))
return FALSE;
if (!YAP_IsIntTerm(arg_itrie2))
return FALSE;
/* count join itrie */
entries = itrie_count_join((TrEntry) YAP_IntOfTerm(arg_itrie1), (TrEntry) YAP_IntOfTerm(arg_itrie2));
return YAP_Unify(arg_entries, YAP_MkIntTerm(entries));
}
#undef arg_itrie1
#undef arg_itrie2
#undef arg_entries
/* itrie_count_intersect(-Itrie1,-Itrie2,+Entries) */
#define arg_itrie1 YAP_ARG1
#define arg_itrie2 YAP_ARG2
#define arg_entries YAP_ARG3
static int p_itrie_count_intersect(void) {
YAP_Int entries;
/* check args */
if (!YAP_IsIntTerm(arg_itrie1))
return FALSE;
if (!YAP_IsIntTerm(arg_itrie2))
return FALSE;
/* count intersect itrie */
entries = itrie_count_intersect((TrEntry) YAP_IntOfTerm(arg_itrie1), (TrEntry) YAP_IntOfTerm(arg_itrie2));
return YAP_Unify(arg_entries, YAP_MkIntTerm(entries));
}
#undef arg_itrie1
#undef arg_itrie2
#undef arg_entries
/* itrie_save(-Itrie,-FileName) */
#define arg_itrie YAP_ARG1
#define arg_file YAP_ARG2

View File

@ -40,6 +40,10 @@ static int p_trie_check_entry(void);
static int p_trie_get_entry(void);
static int p_trie_remove_entry(void);
static int p_trie_remove_subtree(void);
static int p_trie_join(void);
static int p_trie_intersect(void);
static int p_trie_count_join(void);
static int p_trie_count_intersect(void);
static int p_trie_save(void);
static int p_trie_load(void);
static int p_trie_stats(void);
@ -73,6 +77,10 @@ void init_tries(void) {
YAP_UserCPredicate("trie_get_entry", p_trie_get_entry, 2);
YAP_UserCPredicate("trie_remove_entry", p_trie_remove_entry, 1);
YAP_UserCPredicate("trie_remove_subtree", p_trie_remove_subtree, 1);
YAP_UserCPredicate("trie_join", p_trie_join, 2);
YAP_UserCPredicate("trie_intersect", p_trie_intersect, 2);
YAP_UserCPredicate("trie_count_join", p_trie_count_join, 3);
YAP_UserCPredicate("trie_count_intersect", p_trie_count_intersect, 3);
YAP_UserCPredicate("trie_save", p_trie_save, 2);
YAP_UserCPredicate("trie_load", p_trie_load, 2);
YAP_UserCPredicate("trie_usage", p_trie_usage, 4);
@ -354,6 +362,86 @@ static int p_trie_remove_subtree(void) {
#undef arg_ref
/* trie_join(-TrieDest,-TrieSource) */
#define arg_trie_dest YAP_ARG1
#define arg_trie_source YAP_ARG2
static int p_trie_join(void) {
/* check args */
if (!YAP_IsIntTerm(arg_trie_dest))
return FALSE;
if (!YAP_IsIntTerm(arg_trie_source))
return FALSE;
/* join trie */
trie_join(TRIE_ENGINE, (TrNode) YAP_IntOfTerm(arg_trie_dest), (TrNode) YAP_IntOfTerm(arg_trie_source), NULL, NULL);
return TRUE;
}
#undef arg_trie_dest
#undef arg_trie_source
/* trie_intersect(-TrieDest,-TrieSource) */
#define arg_trie_dest YAP_ARG1
#define arg_trie_source YAP_ARG2
static int p_trie_intersect(void) {
/* check args */
if (!YAP_IsIntTerm(arg_trie_dest))
return FALSE;
if (!YAP_IsIntTerm(arg_trie_source))
return FALSE;
/* intersect trie */
trie_intersect(TRIE_ENGINE, (TrNode) YAP_IntOfTerm(arg_trie_dest), (TrNode) YAP_IntOfTerm(arg_trie_source), NULL, NULL);
return TRUE;
}
#undef arg_trie_dest
#undef arg_trie_source
/* trie_count_join(-Trie1,-Trie2,+Entries) */
#define arg_trie1 YAP_ARG1
#define arg_trie2 YAP_ARG2
#define arg_entries YAP_ARG3
static int p_trie_count_join(void) {
YAP_Int entries;
/* check args */
if (!YAP_IsIntTerm(arg_trie1))
return FALSE;
if (!YAP_IsIntTerm(arg_trie2))
return FALSE;
/* count join trie */
entries = trie_count_join((TrNode) YAP_IntOfTerm(arg_trie1), (TrNode) YAP_IntOfTerm(arg_trie2));
return YAP_Unify(arg_entries, YAP_MkIntTerm(entries));
}
#undef arg_trie1
#undef arg_trie2
#undef arg_entries
/* trie_count_intersect(-Trie1,-Trie2,+Entries) */
#define arg_trie1 YAP_ARG1
#define arg_trie2 YAP_ARG2
#define arg_entries YAP_ARG3
static int p_trie_count_intersect(void) {
YAP_Int entries;
/* check args */
if (!YAP_IsIntTerm(arg_trie1))
return FALSE;
if (!YAP_IsIntTerm(arg_trie2))
return FALSE;
/* count intersect trie */
entries = trie_count_intersect((TrNode) YAP_IntOfTerm(arg_trie1), (TrNode) YAP_IntOfTerm(arg_trie2));
return YAP_Unify(arg_entries, YAP_MkIntTerm(entries));
}
#undef arg_trie1
#undef arg_trie2
#undef arg_entries
/* trie_save(-Trie,-FileName) */
#define arg_trie YAP_ARG1
#define arg_file YAP_ARG2

View File

@ -19,9 +19,12 @@
itrie_traverse/2,
itrie_remove_entry/1,
itrie_remove_subtree/1,
itrie_join/2,
itrie_add/2,
itrie_subtract/2,
itrie_join/2,
itrie_intersect/2,
itrie_count_join/3,
itrie_count_intersect/3,
itrie_save/2,
itrie_load/2,
itrie_stats/4,

View File

@ -15,6 +15,10 @@
trie_get_entry/2,
trie_remove_entry/1,
trie_remove_subtree/1,
trie_join/2,
trie_intersect/2,
trie_count_join/3,
trie_count_intersect/3,
trie_save/2,
trie_load/2,
trie_stats/4,