Permalink
Browse files

use dict:new() as array default

would be interesting measure if this change acutally improves
performance or will make the sparse folds slower
  • Loading branch information...
1 parent de49848 commit 19fc7a4127da1b1f8d7ef7bae158bce9e4873231 @martinrehfeld committed May 14, 2012
Showing with 3 additions and 9 deletions.
  1. +3 −9 apps/countdown/src/cd_solver.erl
@@ -29,16 +29,15 @@ solutions(Target, Numbers) ->
%% [{DeltaToTargetValue, #solution}, ...]
initialize_solutions(Target, Numbers) ->
MapSize = 1 bsl length(Numbers),
- A = array:new(MapSize),
+ A = array:new(MapSize, {default, dict:new()}),
F = fun(Index, Array) ->
UsedBitmap = bitmap_for_index(Index),
Number = lists:nth(Index, Numbers),
Delta = abs(Target - Number),
Expression = list_to_binary(integer_to_list(Number)),
S = #solution{result=Number, expression=Expression},
- Dict = dict:new(),
- array:set(UsedBitmap, dict:store(Delta, S, Dict), Array)
+ array:set(UsedBitmap, dict:store(Delta, S, dict:new()), Array)
end,
lists:foldl(F, A, lists:seq(1, length(Numbers))).
@@ -112,12 +111,7 @@ combine_operators(I, J, S1, S2, A, Target) ->
Delta = abs(Target - Result),
Index = I bor J,
Entries = array:get(Index, Array),
- Dict =
- case Entries of
- undefined -> dict:new();
- Entries -> Entries
- end,
- NewEntries = dict:store(Delta, Solution, Dict),
+ NewEntries = dict:store(Delta, Solution, Entries),
array:set(Index, NewEntries, Array)
end
end,

0 comments on commit 19fc7a4

Please sign in to comment.