Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 19fc7a4127da1b1f8d7ef7bae158bce9e4873231 1 parent de49848
Martin Rehfeld authored May 14, 2012

Showing 1 changed file with 3 additions and 9 deletions. Show diff stats Hide diff stats

  1. 12  apps/countdown/src/cd_solver.erl
12  apps/countdown/src/cd_solver.erl
@@ -29,7 +29,7 @@ solutions(Target, Numbers) ->
29 29
 %% [{DeltaToTargetValue, #solution}, ...]
30 30
 initialize_solutions(Target, Numbers) ->
31 31
     MapSize = 1 bsl length(Numbers),
32  
-    A = array:new(MapSize),
  32
+    A = array:new(MapSize, {default, dict:new()}),
33 33
 
34 34
     F = fun(Index, Array) ->
35 35
             UsedBitmap = bitmap_for_index(Index),
@@ -37,8 +37,7 @@ initialize_solutions(Target, Numbers) ->
37 37
             Delta = abs(Target - Number),
38 38
             Expression = list_to_binary(integer_to_list(Number)),
39 39
             S = #solution{result=Number, expression=Expression},
40  
-            Dict = dict:new(),
41  
-            array:set(UsedBitmap, dict:store(Delta, S, Dict), Array)
  40
+            array:set(UsedBitmap, dict:store(Delta, S, dict:new()), Array)
42 41
         end,
43 42
     lists:foldl(F, A, lists:seq(1, length(Numbers))).
44 43
 
@@ -112,12 +111,7 @@ combine_operators(I, J, S1, S2, A, Target) ->
112 111
                     Delta = abs(Target - Result),
113 112
                     Index = I bor J,
114 113
                     Entries = array:get(Index, Array),
115  
-                    Dict =
116  
-                        case Entries of
117  
-                            undefined -> dict:new();
118  
-                            Entries -> Entries
119  
-                        end,
120  
-                    NewEntries = dict:store(Delta, Solution, Dict),
  114
+                    NewEntries = dict:store(Delta, Solution, Entries),
121 115
                     array:set(Index, NewEntries, Array)
122 116
             end
123 117
         end,

0 notes on commit 19fc7a4

Please sign in to comment.
Something went wrong with that request. Please try again.