Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix bit sizes of the HAMT map.

  • Loading branch information...
commit 7866d8f91ac401522a97d908aeed16f1064fbe7f 1 parent 7033e5d
Jesper Louis Andersen authored
Showing with 10 additions and 13 deletions.
  1. +2 −4 src/bench_map.erl
  2. +8 −9 src/hamt.erl
6 src/bench_map.erl
View
@@ -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) ->
17 src/hamt.erl
View
@@ -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).
@@ -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]};
@@ -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;
@@ -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) ->
Please sign in to comment.
Something went wrong with that request. Please try again.