fixes to hashing code.

This commit is contained in:
Vitor Santos Costa 2008-11-18 11:29:08 +00:00
parent 99c5cb3e36
commit abf9691282

View File

@ -29,7 +29,7 @@ b_hash_new(hash(Keys, Vals, Size, N, _)) :-
array(Vals, Size), array(Vals, Size),
create_mutable(0, N). create_mutable(0, N).
b_hash_new(hash(Keys,Vals, Size, N, _), Size) :- b_hash_new(hash(Keys, Vals, Size, N, _), Size) :-
array(Keys, Size), array(Keys, Size),
array(Vals, Size), array(Vals, Size),
create_mutable(0, N). create_mutable(0, N).
@ -39,9 +39,8 @@ b_hash_new(hash(Keys,Vals, Size, N, HashF), Size, HashF) :-
array(Vals, Size), array(Vals, Size),
create_mutable(0, N). create_mutable(0, N).
b_hash_lookup(Key, Val, hash(Keys, Vals, Size, F)):- b_hash_lookup(Key, Val, hash(Keys, Vals, Size, _, F)):-
hash_f(Key, Size, Index, F), hash_f(Key, Size, Index, F),
term_hash(Key,-1,Size,Index),
fetch_key(Keys, Index, Size, Key, ActualIndex), fetch_key(Keys, Index, Size, Key, ActualIndex),
array_element(Vals, ActualIndex, Mutable), array_element(Vals, ActualIndex, Mutable),
get_mutable(Val, Mutable). get_mutable(Val, Mutable).
@ -90,7 +89,7 @@ find_or_insert(Keys, Index, Size, N, Vals, Key, NewVal, Hash) :-
% do rb_update % do rb_update
array_element(Vals, Index, Mutable), array_element(Vals, Index, Mutable),
update_mutable(NewVal, Mutable) update_mutable(NewVal, Mutable)
; ;
I1 is (Index+1) mod Size, I1 is (Index+1) mod Size,
find_or_insert(Keys, I1, Size, N, Vals, Key, NewVal, Hash) find_or_insert(Keys, I1, Size, N, Vals, Key, NewVal, Hash)
). ).
@ -100,7 +99,7 @@ add_element(Keys, Index, Size, N, Vals, Key, NewVal, Hash) :-
NN is NEls+1, NN is NEls+1,
update_mutable(NN, N), update_mutable(NN, N),
( (
NN > 3*Size/4 NN > Size/3
-> ->
expand_array(Key, NewVal, Hash) expand_array(Key, NewVal, Hash)
; ;
@ -154,7 +153,7 @@ find_free(Index, Size, Keys, NewIndex) :-
NewIndex = Index NewIndex = Index
; ;
I1 is (Index+1) mod Size, I1 is (Index+1) mod Size,
find_free(I1, Keys, NewIndex) find_free(I1, Size, Keys, NewIndex)
). ).
hash_f(Key, Size, Index, F) :- hash_f(Key, Size, Index, F) :-