Merge branch 'master' of ssh://git.dcc.fc.up.pt/yap-6.3

This commit is contained in:
Vítor Santos Costa 2011-12-13 10:02:03 +00:00
commit 85c4d6673d
4 changed files with 99 additions and 94 deletions

View File

@ -179,17 +179,17 @@ static inline tg_sol_fr_ptr CUT_prune_tg_solution_frames(tg_sol_fr_ptr, int);
#define IS_INVALID_LEAF_NODE(NODE) ((unsigned long int) TrNode_parent(NODE) & 0x2) #define IS_INVALID_LEAF_NODE(NODE) ((unsigned long int) TrNode_parent(NODE) & 0x2)
/* trie hashes */ /* trie hashes */
#define MAX_NODES_PER_TRIE_LEVEL 8 #define MAX_NODES_PER_TRIE_LEVEL 8
#define MAX_NODES_PER_BUCKET (MAX_NODES_PER_TRIE_LEVEL / 2) #define MAX_NODES_PER_BUCKET (MAX_NODES_PER_TRIE_LEVEL / 2)
#define BASE_HASH_BUCKETS 64 #define BASE_HASH_BUCKETS 64
#define HASH_ENTRY(ENTRY, SEED) ((((unsigned long int) ENTRY) >> NumberOfLowTagBits) & (SEED)) #define HASH_ENTRY(ENTRY, NUM_BUCKETS) ((((unsigned long int) ENTRY) >> NumberOfLowTagBits) & (NUM_BUCKETS - 1))
#define SUBGOAL_TRIE_HASH_MARK ((Term) MakeTableVarTerm(MAX_TABLE_VARS)) #define SUBGOAL_TRIE_HASH_MARK ((Term) MakeTableVarTerm(MAX_TABLE_VARS))
#define IS_SUBGOAL_TRIE_HASH(NODE) (TrNode_entry(NODE) == SUBGOAL_TRIE_HASH_MARK) #define IS_SUBGOAL_TRIE_HASH(NODE) (TrNode_entry(NODE) == SUBGOAL_TRIE_HASH_MARK)
#define ANSWER_TRIE_HASH_MARK 0 #define ANSWER_TRIE_HASH_MARK 0
#define IS_ANSWER_TRIE_HASH(NODE) (TrNode_instr(NODE) == ANSWER_TRIE_HASH_MARK) #define IS_ANSWER_TRIE_HASH(NODE) (TrNode_instr(NODE) == ANSWER_TRIE_HASH_MARK)
#define GLOBAL_TRIE_HASH_MARK ((Term) MakeTableVarTerm(MAX_TABLE_VARS)) #define GLOBAL_TRIE_HASH_MARK ((Term) MakeTableVarTerm(MAX_TABLE_VARS))
#define IS_GLOBAL_TRIE_HASH(NODE) (TrNode_entry(NODE) == GLOBAL_TRIE_HASH_MARK) #define IS_GLOBAL_TRIE_HASH(NODE) (TrNode_entry(NODE) == GLOBAL_TRIE_HASH_MARK)
#define HASH_TRIE_LOCK(NODE) GLOBAL_trie_locks((((unsigned long int) (NODE)) >> 5) & (TRIE_LOCK_BUCKETS - 1)) #define HASH_TRIE_LOCK(NODE) GLOBAL_trie_locks((((unsigned long int) (NODE)) >> 5) & (TRIE_LOCK_BUCKETS - 1))
/* auxiliary stack */ /* auxiliary stack */
#define STACK_PUSH_UP(ITEM, STACK) *--(STACK) = (CELL)(ITEM) #define STACK_PUSH_UP(ITEM, STACK) *--(STACK) = (CELL)(ITEM)

View File

@ -148,9 +148,7 @@ typedef struct global_trie_hash {
#define Hash_mark(X) ((X)->mark) #define Hash_mark(X) ((X)->mark)
#define Hash_num_buckets(X) ((X)->number_of_buckets) #define Hash_num_buckets(X) ((X)->number_of_buckets)
#define Hash_seed(X) ((X)->number_of_buckets - 1)
#define Hash_buckets(X) ((X)->buckets) #define Hash_buckets(X) ((X)->buckets)
#define Hash_bucket(X,N) ((X)->buckets + N)
#define Hash_num_nodes(X) ((X)->number_of_nodes) #define Hash_num_nodes(X) ((X)->number_of_nodes)
#define Hash_previous(X) ((X)->previous) #define Hash_previous(X) ((X)->previous)
#define Hash_next(X) ((X)->next) #define Hash_next(X) ((X)->next)

View File

@ -456,7 +456,7 @@ static void free_global_trie_branch(gt_node_ptr current_node) {
child_node = TrNode_child(parent_node); child_node = TrNode_child(parent_node);
if (IS_GLOBAL_TRIE_HASH(child_node)) { if (IS_GLOBAL_TRIE_HASH(child_node)) {
gt_hash_ptr hash = (gt_hash_ptr) child_node; gt_hash_ptr hash = (gt_hash_ptr) child_node;
gt_node_ptr *bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(current_node), Hash_seed(hash))); gt_node_ptr *bucket = Hash_buckets(hash) + HASH_ENTRY(TrNode_entry(current_node), Hash_num_buckets(hash));
int num_nodes = --Hash_num_nodes(hash); int num_nodes = --Hash_num_nodes(hash);
child_node = *bucket; child_node = *bucket;
if (child_node != current_node) { if (child_node != current_node) {

View File

@ -95,7 +95,7 @@ static inline sg_node_ptr subgoal_trie_check_insert_entry(tab_ent_ptr tab_ent, s
new_subgoal_trie_hash(hash, count_nodes, tab_ent); new_subgoal_trie_hash(hash, count_nodes, tab_ent);
chain_node = child_node; chain_node = child_node;
do { do {
bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(chain_node), BASE_HASH_BUCKETS - 1)); bucket = Hash_buckets(hash) + HASH_ENTRY(TrNode_entry(chain_node), BASE_HASH_BUCKETS);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
@ -114,7 +114,7 @@ static inline sg_node_ptr subgoal_trie_check_insert_entry(tab_ent_ptr tab_ent, s
sg_node_ptr *bucket; sg_node_ptr *bucket;
int count_nodes = 0; int count_nodes = 0;
hash = (sg_hash_ptr) child_node; hash = (sg_hash_ptr) child_node;
bucket = Hash_bucket(hash, HASH_ENTRY(t, Hash_seed(hash))); bucket = Hash_buckets(hash) + HASH_ENTRY(t, Hash_num_buckets(hash));
child_node = *bucket; child_node = *bucket;
while (child_node) { while (child_node) {
if (TrNode_entry(child_node) == t) { if (TrNode_entry(child_node) == t) {
@ -130,26 +130,27 @@ static inline sg_node_ptr subgoal_trie_check_insert_entry(tab_ent_ptr tab_ent, s
count_nodes++; count_nodes++;
if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) { if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* expand current hash */ /* expand current hash */
sg_node_ptr chain_node, next_node, *first_old_bucket, *old_bucket; sg_node_ptr chain_node, next_node, *old_bucket, *hash_old_buckets, *hash_new_buckets;
int seed; int num_buckets;
first_old_bucket = Hash_buckets(hash); num_buckets = Hash_num_buckets(hash) * 2;
old_bucket = first_old_bucket + Hash_num_buckets(hash); ALLOC_HASH_BUCKETS(hash_new_buckets, num_buckets);
Hash_num_buckets(hash) *= 2; hash_old_buckets = Hash_buckets(hash);
ALLOC_HASH_BUCKETS(Hash_buckets(hash), Hash_num_buckets(hash)); old_bucket = hash_old_buckets + Hash_num_buckets(hash);
seed = Hash_seed(hash);
do { do {
if (*--old_bucket) { if (*--old_bucket) {
chain_node = *old_bucket; chain_node = *old_bucket;
do { do {
bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(chain_node), seed)); bucket = hash_new_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
chain_node = next_node; chain_node = next_node;
} while (chain_node); } while (chain_node);
} }
} while (old_bucket != first_old_bucket); } while (old_bucket != hash_old_buckets);
FREE_HASH_BUCKETS(first_old_bucket); FREE_HASH_BUCKETS(hash_old_buckets);
Hash_buckets(hash) = hash_new_buckets;
Hash_num_buckets(hash) = num_buckets;
} }
UNLOCK_SUBGOAL_NODE(parent_node); UNLOCK_SUBGOAL_NODE(parent_node);
return child_node; return child_node;
@ -252,7 +253,7 @@ static inline sg_node_ptr subgoal_trie_check_insert_entry(tab_ent_ptr tab_ent, s
new_subgoal_trie_hash(hash, count_nodes, tab_ent); new_subgoal_trie_hash(hash, count_nodes, tab_ent);
chain_node = child_node; chain_node = child_node;
do { do {
bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(chain_node), BASE_HASH_BUCKETS - 1)); bucket = Hash_buckets(hash) + HASH_ENTRY(TrNode_entry(chain_node), BASE_HASH_BUCKETS);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
@ -270,10 +271,10 @@ static inline sg_node_ptr subgoal_trie_check_insert_entry(tab_ent_ptr tab_ent, s
subgoal_trie_hash: subgoal_trie_hash:
{ /* trie nodes with hashing */ { /* trie nodes with hashing */
sg_node_ptr *bucket, first_node; sg_node_ptr *bucket, first_node;
int seed, count_nodes = 0; int num_buckets, count_nodes = 0;
seed = Hash_seed(hash); num_buckets = Hash_num_buckets(hash);
bucket = Hash_bucket(hash, HASH_ENTRY(t, seed)); bucket = Hash_buckets(hash) + HASH_ENTRY(t, num_buckets);
first_node = child_node = *bucket; first_node = child_node = *bucket;
while (child_node) { while (child_node) {
if (TrNode_entry(child_node) == t) if (TrNode_entry(child_node) == t)
@ -285,7 +286,7 @@ subgoal_trie_hash:
NEW_SUBGOAL_TRIE_NODE(child_node, t, NULL, parent_node, first_node); NEW_SUBGOAL_TRIE_NODE(child_node, t, NULL, parent_node, first_node);
#endif /* SUBGOAL_TRIE_ALLOC_BEFORE_CHECK */ #endif /* SUBGOAL_TRIE_ALLOC_BEFORE_CHECK */
LOCK_SUBGOAL_NODE(parent_node); LOCK_SUBGOAL_NODE(parent_node);
if (seed != Hash_seed(hash)) { if (num_buckets != Hash_num_buckets(hash)) {
/* the hash has been expanded */ /* the hash has been expanded */
#ifdef SUBGOAL_TRIE_ALLOC_BEFORE_CHECK #ifdef SUBGOAL_TRIE_ALLOC_BEFORE_CHECK
FREE_SUBGOAL_TRIE_NODE(child_node); FREE_SUBGOAL_TRIE_NODE(child_node);
@ -319,25 +320,26 @@ subgoal_trie_hash:
count_nodes++; count_nodes++;
if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) { if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* expand current hash */ /* expand current hash */
sg_node_ptr chain_node, next_node, *first_old_bucket, *old_bucket; sg_node_ptr chain_node, next_node, *old_bucket, *hash_old_buckets, *hash_new_buckets;
first_old_bucket = Hash_buckets(hash); num_buckets = Hash_num_buckets(hash) * 2;
old_bucket = first_old_bucket + Hash_num_buckets(hash); ALLOC_HASH_BUCKETS(hash_new_buckets, num_buckets);
Hash_num_buckets(hash) *= 2; hash_old_buckets = Hash_buckets(hash);
ALLOC_HASH_BUCKETS(Hash_buckets(hash), Hash_num_buckets(hash)); old_bucket = hash_old_buckets + Hash_num_buckets(hash);
seed = Hash_seed(hash);
do { do {
if (*--old_bucket) { if (*--old_bucket) {
chain_node = *old_bucket; chain_node = *old_bucket;
do { do {
bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(chain_node), seed)); bucket = hash_new_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
chain_node = next_node; chain_node = next_node;
} while (chain_node); } while (chain_node);
} }
} while (old_bucket != first_old_bucket); } while (old_bucket != hash_old_buckets);
FREE_HASH_BUCKETS(first_old_bucket); FREE_HASH_BUCKETS(hash_old_buckets);
Hash_buckets(hash) = hash_new_buckets;
Hash_num_buckets(hash) = num_buckets;
} }
UNLOCK_SUBGOAL_NODE(parent_node); UNLOCK_SUBGOAL_NODE(parent_node);
return child_node; return child_node;
@ -391,7 +393,7 @@ static inline ans_node_ptr answer_trie_check_insert_entry(sg_fr_ptr sg_fr, ans_n
new_answer_trie_hash(hash, count_nodes, sg_fr); new_answer_trie_hash(hash, count_nodes, sg_fr);
chain_node = child_node; chain_node = child_node;
do { do {
bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(chain_node), BASE_HASH_BUCKETS - 1)); bucket = Hash_buckets(hash) + HASH_ENTRY(TrNode_entry(chain_node), BASE_HASH_BUCKETS);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
@ -410,7 +412,7 @@ static inline ans_node_ptr answer_trie_check_insert_entry(sg_fr_ptr sg_fr, ans_n
ans_node_ptr *bucket; ans_node_ptr *bucket;
int count_nodes = 0; int count_nodes = 0;
hash = (ans_hash_ptr) child_node; hash = (ans_hash_ptr) child_node;
bucket = Hash_bucket(hash, HASH_ENTRY(t, Hash_seed(hash))); bucket = Hash_buckets(hash) + HASH_ENTRY(t, Hash_num_buckets(hash));
child_node = *bucket; child_node = *bucket;
while (child_node) { while (child_node) {
if (TrNode_entry(child_node) == t) { if (TrNode_entry(child_node) == t) {
@ -426,26 +428,27 @@ static inline ans_node_ptr answer_trie_check_insert_entry(sg_fr_ptr sg_fr, ans_n
count_nodes++; count_nodes++;
if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) { if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* expand current hash */ /* expand current hash */
ans_node_ptr chain_node, next_node, *first_old_bucket, *old_bucket; ans_node_ptr chain_node, next_node, *old_bucket, *hash_old_buckets, *hash_new_buckets;
int seed; int num_buckets;
first_old_bucket = Hash_buckets(hash); num_buckets = Hash_num_buckets(hash) * 2;
old_bucket = first_old_bucket + Hash_num_buckets(hash); ALLOC_HASH_BUCKETS(hash_new_buckets, num_buckets);
Hash_num_buckets(hash) *= 2; hash_old_buckets = Hash_buckets(hash);
ALLOC_HASH_BUCKETS(Hash_buckets(hash), Hash_num_buckets(hash)); old_bucket = hash_old_buckets + Hash_num_buckets(hash);
seed = Hash_seed(hash);
do { do {
if (*--old_bucket) { if (*--old_bucket) {
chain_node = *old_bucket; chain_node = *old_bucket;
do { do {
bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(chain_node), seed)); bucket = hash_new_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
chain_node = next_node; chain_node = next_node;
} while (chain_node); } while (chain_node);
} }
} while (old_bucket != first_old_bucket); } while (old_bucket != hash_old_buckets);
FREE_HASH_BUCKETS(first_old_bucket); FREE_HASH_BUCKETS(hash_old_buckets);
Hash_buckets(hash) = hash_new_buckets;
Hash_num_buckets(hash) = num_buckets;
} }
UNLOCK_ANSWER_NODE(parent_node); UNLOCK_ANSWER_NODE(parent_node);
return child_node; return child_node;
@ -549,7 +552,7 @@ static inline ans_node_ptr answer_trie_check_insert_entry(sg_fr_ptr sg_fr, ans_n
new_answer_trie_hash(hash, count_nodes, sg_fr); new_answer_trie_hash(hash, count_nodes, sg_fr);
chain_node = child_node; chain_node = child_node;
do { do {
bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(chain_node), BASE_HASH_BUCKETS - 1)); bucket = Hash_buckets(hash) + HASH_ENTRY(TrNode_entry(chain_node), BASE_HASH_BUCKETS);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
@ -567,10 +570,10 @@ static inline ans_node_ptr answer_trie_check_insert_entry(sg_fr_ptr sg_fr, ans_n
answer_trie_hash: answer_trie_hash:
{ /* trie nodes with hashing */ { /* trie nodes with hashing */
ans_node_ptr *bucket, first_node; ans_node_ptr *bucket, first_node;
int seed, count_nodes = 0; int num_buckets, count_nodes = 0;
seed = Hash_seed(hash); num_buckets = Hash_num_buckets(hash);
bucket = Hash_bucket(hash, HASH_ENTRY(t, seed)); bucket = Hash_buckets(hash) + HASH_ENTRY(t, num_buckets);
first_node = child_node = *bucket; first_node = child_node = *bucket;
while (child_node) { while (child_node) {
if (TrNode_entry(child_node) == t) if (TrNode_entry(child_node) == t)
@ -582,7 +585,7 @@ answer_trie_hash:
NEW_ANSWER_TRIE_NODE(child_node, instr, t, NULL, parent_node, first_node); NEW_ANSWER_TRIE_NODE(child_node, instr, t, NULL, parent_node, first_node);
#endif /* ANSWER_TRIE_ALLOC_BEFORE_CHECK */ #endif /* ANSWER_TRIE_ALLOC_BEFORE_CHECK */
LOCK_ANSWER_NODE(parent_node); LOCK_ANSWER_NODE(parent_node);
if (seed != Hash_seed(hash)) { if (num_buckets != Hash_num_buckets(hash)) {
/* the hash has been expanded */ /* the hash has been expanded */
#ifdef ANSWER_TRIE_ALLOC_BEFORE_CHECK #ifdef ANSWER_TRIE_ALLOC_BEFORE_CHECK
FREE_ANSWER_TRIE_NODE(child_node); FREE_ANSWER_TRIE_NODE(child_node);
@ -615,26 +618,27 @@ answer_trie_hash:
Hash_num_nodes(hash)++; Hash_num_nodes(hash)++;
count_nodes++; count_nodes++;
if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) { if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* expand current hash */ /* expand current hash */
ans_node_ptr chain_node, next_node, *first_old_bucket, *old_bucket; ans_node_ptr chain_node, next_node, *old_bucket, *hash_old_buckets, *hash_new_buckets;
first_old_bucket = Hash_buckets(hash); num_buckets = Hash_num_buckets(hash) * 2;
old_bucket = first_old_bucket + Hash_num_buckets(hash); ALLOC_HASH_BUCKETS(hash_new_buckets, num_buckets);
Hash_num_buckets(hash) *= 2; hash_old_buckets = Hash_buckets(hash);
ALLOC_HASH_BUCKETS(Hash_buckets(hash), Hash_num_buckets(hash)); old_bucket = hash_old_buckets + Hash_num_buckets(hash);
seed = Hash_seed(hash);
do { do {
if (*--old_bucket) { if (*--old_bucket) {
chain_node = *old_bucket; chain_node = *old_bucket;
do { do {
bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(chain_node), seed)); bucket = hash_new_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
chain_node = next_node; chain_node = next_node;
} while (chain_node); } while (chain_node);
} }
} while (old_bucket != first_old_bucket); } while (old_bucket != hash_old_buckets);
FREE_HASH_BUCKETS(first_old_bucket); FREE_HASH_BUCKETS(hash_old_buckets);
Hash_buckets(hash) = hash_new_buckets;
Hash_num_buckets(hash) = num_buckets;
} }
UNLOCK_ANSWER_NODE(parent_node); UNLOCK_ANSWER_NODE(parent_node);
return child_node; return child_node;
@ -686,7 +690,7 @@ static inline gt_node_ptr global_trie_check_insert_entry(gt_node_ptr parent_node
new_global_trie_hash(hash, count_nodes); new_global_trie_hash(hash, count_nodes);
chain_node = child_node; chain_node = child_node;
do { do {
bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(chain_node), BASE_HASH_BUCKETS - 1)); bucket = Hash_buckets(hash) + HASH_ENTRY(TrNode_entry(chain_node), BASE_HASH_BUCKETS);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
@ -705,7 +709,7 @@ static inline gt_node_ptr global_trie_check_insert_entry(gt_node_ptr parent_node
gt_node_ptr *bucket; gt_node_ptr *bucket;
int count_nodes = 0; int count_nodes = 0;
hash = (gt_hash_ptr) child_node; hash = (gt_hash_ptr) child_node;
bucket = Hash_bucket(hash, HASH_ENTRY(t, Hash_seed(hash))); bucket = Hash_buckets(hash) + HASH_ENTRY(t, Hash_num_buckets(hash));
child_node = *bucket; child_node = *bucket;
while (child_node) { while (child_node) {
if (TrNode_entry(child_node) == t) { if (TrNode_entry(child_node) == t) {
@ -721,26 +725,27 @@ static inline gt_node_ptr global_trie_check_insert_entry(gt_node_ptr parent_node
count_nodes++; count_nodes++;
if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) { if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* expand current hash */ /* expand current hash */
gt_node_ptr chain_node, next_node, *first_old_bucket, *old_bucket; gt_node_ptr chain_node, next_node, *old_bucket, *hash_old_buckets, *hash_new_buckets;
int seed; int num_buckets;
first_old_bucket = Hash_buckets(hash); num_buckets = Hash_num_buckets(hash) * 2;
old_bucket = first_old_bucket + Hash_num_buckets(hash); ALLOC_HASH_BUCKETS(hash_new_buckets, num_buckets);
Hash_num_buckets(hash) *= 2; hash_old_buckets = Hash_buckets(hash);
ALLOC_HASH_BUCKETS(Hash_buckets(hash), Hash_num_buckets(hash)); old_bucket = hash_old_buckets + Hash_num_buckets(hash);
seed = Hash_seed(hash);
do { do {
if (*--old_bucket) { if (*--old_bucket) {
chain_node = *old_bucket; chain_node = *old_bucket;
do { do {
bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(chain_node), seed)); bucket = hash_new_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
chain_node = next_node; chain_node = next_node;
} while (chain_node); } while (chain_node);
} }
} while (old_bucket != first_old_bucket); } while (old_bucket != hash_old_buckets);
FREE_HASH_BUCKETS(first_old_bucket); FREE_HASH_BUCKETS(hash_old_buckets);
Hash_buckets(hash) = hash_new_buckets;
Hash_num_buckets(hash) = num_buckets;
} }
UNLOCK_GLOBAL_NODE(parent_node); UNLOCK_GLOBAL_NODE(parent_node);
return child_node; return child_node;
@ -752,6 +757,7 @@ static inline gt_node_ptr global_trie_check_insert_gt_entry(gt_node_ptr parent_n
#else #else
static inline gt_node_ptr global_trie_check_insert_entry(gt_node_ptr parent_node, Term t) { static inline gt_node_ptr global_trie_check_insert_entry(gt_node_ptr parent_node, Term t) {
#endif /* MODE_GLOBAL_TRIE_ENTRY */ #endif /* MODE_GLOBAL_TRIE_ENTRY */
CACHE_REGS
gt_node_ptr child_node; gt_node_ptr child_node;
gt_hash_ptr hash; gt_hash_ptr hash;
@ -840,10 +846,10 @@ static inline gt_node_ptr global_trie_check_insert_entry(gt_node_ptr parent_node
if (count_nodes >= MAX_NODES_PER_TRIE_LEVEL) { if (count_nodes >= MAX_NODES_PER_TRIE_LEVEL) {
/* alloc a new hash */ /* alloc a new hash */
gt_node_ptr chain_node, next_node, *bucket; gt_node_ptr chain_node, next_node, *bucket;
new_answer_trie_hash(hash, count_nodes, sg_fr); new_global_trie_hash(hash, count_nodes);
chain_node = child_node; chain_node = child_node;
do { do {
bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(chain_node), BASE_HASH_BUCKETS - 1)); bucket = Hash_buckets(hash) + HASH_ENTRY(TrNode_entry(chain_node), BASE_HASH_BUCKETS);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
@ -861,10 +867,10 @@ static inline gt_node_ptr global_trie_check_insert_entry(gt_node_ptr parent_node
global_trie_hash: global_trie_hash:
{ /* trie nodes with hashing */ { /* trie nodes with hashing */
gt_node_ptr *bucket, first_node; gt_node_ptr *bucket, first_node;
int seed, count_nodes = 0; int num_buckets, count_nodes = 0;
seed = Hash_seed(hash); num_buckets = Hash_num_buckets(hash);
bucket = Hash_bucket(hash, HASH_ENTRY(t, seed)); bucket = Hash_buckets(hash) + HASH_ENTRY(t, num_buckets);
first_node = child_node = *bucket; first_node = child_node = *bucket;
while (child_node) { while (child_node) {
if (TrNode_entry(child_node) == t) if (TrNode_entry(child_node) == t)
@ -876,7 +882,7 @@ global_trie_hash:
NEW_GLOBAL_TRIE_NODE(child_node, t, NULL, parent_node, first_node); NEW_GLOBAL_TRIE_NODE(child_node, t, NULL, parent_node, first_node);
#endif /* GLOBAL_TRIE_ALLOC_BEFORE_CHECK */ #endif /* GLOBAL_TRIE_ALLOC_BEFORE_CHECK */
LOCK_GLOBAL_NODE(parent_node); LOCK_GLOBAL_NODE(parent_node);
if (seed != Hash_seed(hash)) { if (num_buckets != Hash_num_buckets(hash)) {
/* the hash has been expanded */ /* the hash has been expanded */
#ifdef GLOBAL_TRIE_ALLOC_BEFORE_CHECK #ifdef GLOBAL_TRIE_ALLOC_BEFORE_CHECK
FREE_GLOBAL_TRIE_NODE(child_node); FREE_GLOBAL_TRIE_NODE(child_node);
@ -910,25 +916,26 @@ global_trie_hash:
count_nodes++; count_nodes++;
if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) { if (count_nodes >= MAX_NODES_PER_BUCKET && Hash_num_nodes(hash) > Hash_num_buckets(hash)) {
/* expand current hash */ /* expand current hash */
gt_node_ptr chain_node, next_node, *first_old_bucket, *old_bucket; gt_node_ptr chain_node, next_node, *old_bucket, *hash_old_buckets, *hash_new_buckets;
first_old_bucket = Hash_buckets(hash); num_buckets = Hash_num_buckets(hash) * 2;
old_bucket = first_old_bucket + Hash_num_buckets(hash); ALLOC_HASH_BUCKETS(hash_new_buckets, num_buckets);
Hash_num_buckets(hash) *= 2; hash_old_buckets = Hash_buckets(hash);
ALLOC_HASH_BUCKETS(Hash_buckets(hash), Hash_num_buckets(hash)); old_bucket = hash_old_buckets + Hash_num_buckets(hash);
seed = Hash_seed(hash);
do { do {
if (*--old_bucket) { if (*--old_bucket) {
chain_node = *old_bucket; chain_node = *old_bucket;
do { do {
bucket = Hash_bucket(hash, HASH_ENTRY(TrNode_entry(chain_node), seed)); bucket = hash_new_buckets + HASH_ENTRY(TrNode_entry(chain_node), num_buckets);
next_node = TrNode_next(chain_node); next_node = TrNode_next(chain_node);
TrNode_next(chain_node) = *bucket; TrNode_next(chain_node) = *bucket;
*bucket = chain_node; *bucket = chain_node;
chain_node = next_node; chain_node = next_node;
} while (chain_node); } while (chain_node);
} }
} while (old_bucket != first_old_bucket); } while (old_bucket != hash_old_buckets);
FREE_HASH_BUCKETS(first_old_bucket); FREE_HASH_BUCKETS(hash_old_buckets);
Hash_buckets(hash) = hash_new_buckets;
Hash_num_buckets(hash) = num_buckets;
} }
UNLOCK_GLOBAL_NODE(parent_node); UNLOCK_GLOBAL_NODE(parent_node);
return child_node; return child_node;