Skip to content

Commit

Permalink
Fix bit sizes of the HAMT map.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlouis committed Feb 18, 2011
1 parent 7033e5d commit 7866d8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/bench_map.erl
Expand Up @@ -36,10 +36,8 @@ runs(F) ->
words() ->
Words = "/usr/share/dict/words",
{ok, Content} = file:read_file(Words),
Wrds = [binary_to_list(W) || W <- binary:split(Content, <<"\n">>, [global])],
{_, Taken1} = lists:split(250, Wrds),
{Taken, _} = lists:split(250, Taken1),
Taken.
[binary_to_list(W) || W <- binary:split(Content, <<"\n">>, [global])].



list_shuffle(L) ->
Expand Down
17 changes: 8 additions & 9 deletions src/hamt.erl
Expand Up @@ -6,8 +6,10 @@
| {leaf, integer(), [A]} | empty.

-define(SZ, 4).
-define(SZ_Mask, 31).
-define(FULL_THRESH, 16).
-define(SZ_Mask, 15).
-define(FULL_THRESH, 8).
-define(FULL_SZ, 16).
-define(BIT_SZ, 32).

hash(E) ->
erlang:phash2(E).
Expand All @@ -21,7 +23,7 @@ new() ->

insert(E, T) ->
H = hash(E),
insert(32, E, H, T).
insert(?BIT_SZ, E, H, T).

insert(_Bit, E, H, empty) ->
{leaf, H, [E]};
Expand All @@ -48,12 +50,9 @@ insert(Bit, E, H, {full, Tuple}) ->
N = search_mask(Bit, H),
{full, setelement(N, Tuple, insert(Bit - ?SZ, E, H, element(N, Tuple)))}.




is_element(E, T) ->
H = hash(E),
is_element(32, E, H, T).
is_element(?BIT_SZ, E, H, T).

is_element(_Bit, _E, _H, empty) ->
false;
Expand All @@ -79,9 +78,9 @@ mk_partial(Bit, Hash, Val) ->
{partial, 1, orddict:store(N, {leaf, Hash, Val}, orddict:new())}.

mk_tuple(D) ->
list_to_tuple(mk_tuple(0, orddict:to_list(D))).
list_to_tuple(mk_tuple(1, orddict:to_list(D))).

mk_tuple(32, _) -> [];
mk_tuple(?FULL_SZ+1, _) -> [];
mk_tuple(N, [{N, V} | Rest]) ->
[V | mk_tuple(N+1, Rest)];
mk_tuple(N, L) ->
Expand Down

0 comments on commit 7866d8f

Please sign in to comment.