Permalink
Browse files

replace hashdict with maps

  • Loading branch information...
sasa1977 committed Jan 5, 2016
1 parent 061dd60 commit 51bc04bf48730bfbb6141ad781f8300cc6e91db5
Showing with 242 additions and 242 deletions.
  1. +4 −4 code_samples/ch04/simple_todo.ex
  2. +5 −5 code_samples/ch04/todo_builder.ex
  3. +5 −5 code_samples/ch04/todo_crud.ex
  4. +4 −4 code_samples/ch04/todo_entry_map.ex
  5. +5 −5 code_samples/ch04/todo_import.ex
  6. +4 −4 code_samples/ch04/todo_multi_dict.ex
  7. +5 −5 code_samples/ch05/registered_todo_server.ex
  8. +5 −5 code_samples/ch05/todo_server.ex
  9. +4 −4 code_samples/ch06/key_value_gen_server.ex
  10. +4 −4 code_samples/ch06/server_process.ex
  11. +4 −4 code_samples/ch06/server_process_cast.ex
  12. +5 −5 code_samples/ch06/server_process_todo.ex
  13. +5 −5 code_samples/ch06/todo_server.ex
  14. +3 −3 code_samples/ch07/persistable_todo_cache/lib/todo/cache.ex
  15. +6 −6 code_samples/ch07/persistable_todo_cache/lib/todo/list.ex
  16. +6 −6 code_samples/ch07/todo/lib/todo/list.ex
  17. +3 −3 code_samples/ch07/todo_cache/lib/todo/cache.ex
  18. +6 −6 code_samples/ch07/todo_cache/lib/todo/list.ex
  19. +3 −3 code_samples/ch07/todo_cache_pooling/lib/todo/cache.ex
  20. +5 −5 code_samples/ch07/todo_cache_pooling/lib/todo/database.ex
  21. +6 −6 code_samples/ch07/todo_cache_pooling/lib/todo/list.ex
  22. +3 −3 code_samples/ch08/supervised_todo_cache/lib/todo/cache.ex
  23. +5 −5 code_samples/ch08/supervised_todo_cache/lib/todo/database.ex
  24. +6 −6 code_samples/ch08/supervised_todo_cache/lib/todo/list.ex
  25. +3 −3 code_samples/ch08/todo_links/lib/todo/cache.ex
  26. +5 −5 code_samples/ch08/todo_links/lib/todo/database.ex
  27. +6 −6 code_samples/ch08/todo_links/lib/todo/list.ex
  28. +6 −6 code_samples/ch09/dynamic_workers/lib/todo/list.ex
  29. +7 −7 code_samples/ch09/dynamic_workers/lib/todo/process_registry.ex
  30. +3 −3 code_samples/ch09/pool_supervision/lib/todo/cache.ex
  31. +6 −6 code_samples/ch09/pool_supervision/lib/todo/list.ex
  32. +7 −7 code_samples/ch09/pool_supervision/lib/todo/process_registry.ex
  33. +6 −6 code_samples/ch09/proper_registry_supervision/lib/todo/list.ex
  34. +7 −7 code_samples/ch09/proper_registry_supervision/lib/todo/process_registry.ex
  35. +3 −3 code_samples/ch09/supervise_database/lib/todo/cache.ex
  36. +5 −5 code_samples/ch09/supervise_database/lib/todo/database.ex
  37. +6 −6 code_samples/ch09/supervise_database/lib/todo/list.ex
  38. +6 −6 code_samples/ch10/ets_registry/lib/todo/list.ex
  39. +4 −4 code_samples/ch10/profile_cache/lib/page_cache.ex
  40. +6 −6 code_samples/ch11/gproc_todo_app/lib/todo/list.ex
  41. +6 −6 code_samples/ch11/todo_app/lib/todo/list.ex
  42. +6 −6 code_samples/ch11/todo_env/lib/todo/list.ex
  43. +6 −6 code_samples/ch11/todo_web/lib/todo/list.ex
  44. +5 −5 code_samples/ch11/todo_web_optimized/lib/todo/database_worker.ex
  45. +4 −4 code_samples/ch11/todo_web_optimized/lib/todo/list.ex
  46. +6 −6 code_samples/ch12/todo_distributed/lib/todo/list.ex
  47. +6 −6 code_samples/ch13/todo_release/lib/todo/list.ex
  48. +6 −6 code_samples/ch13/todo_runtime/lib/todo/list.ex
@@ -1,8 +1,8 @@
defmodule TodoList do
def new, do: HashDict.new
def new, do: %{}
def add_entry(todo_list, date, title) do
HashDict.update(
Map.update(
todo_list,
date,
[title],
@@ -11,6 +11,6 @@ defmodule TodoList do
end
def entries(todo_list, date) do
HashDict.get(todo_list, date, [])
Map.get(todo_list, date, [])
end
end
end
@@ -1,5 +1,5 @@
defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}
def new(entries \\ []) do
Enum.reduce(
@@ -14,7 +14,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)
%TodoList{todo_list |
entries: new_entries,
@@ -48,7 +48,7 @@ defmodule TodoList do
old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -58,6 +58,6 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
end
@@ -1,5 +1,5 @@
defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}
def new, do: %TodoList{}
@@ -8,7 +8,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)
%TodoList{todo_list |
entries: new_entries,
@@ -42,7 +42,7 @@ defmodule TodoList do
old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -52,6 +52,6 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
end
@@ -1,8 +1,8 @@
defmodule MultiDict do
def new, do: HashDict.new
def new, do: %{}
def add(dict, key, value) do
HashDict.update(
Map.update(
dict,
key,
[value],
@@ -11,7 +11,7 @@ defmodule MultiDict do
end
def get(dict, key) do
HashDict.get(dict, key, [])
Map.get(dict, key, [])
end
end
@@ -25,4 +25,4 @@ defmodule TodoList do
def entries(todo_list, date) do
MultiDict.get(todo_list, date)
end
end
end
@@ -1,5 +1,5 @@
defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}
def new(entries \\ []) do
Enum.reduce(
@@ -14,7 +14,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)
%TodoList{todo_list |
entries: new_entries,
@@ -48,7 +48,7 @@ defmodule TodoList do
old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -58,7 +58,7 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
@@ -103,4 +103,4 @@ defmodule TodoList.CsvImporter do
defp create_entry({date, title}) do
%{date: date, title: title}
end
end
end
@@ -1,8 +1,8 @@
defmodule MultiDict do
def new, do: HashDict.new
def new, do: %{}
def add(dict, key, value) do
HashDict.update(
Map.update(
dict,
key,
[value],
@@ -11,7 +11,7 @@ defmodule MultiDict do
end
def get(dict, key) do
HashDict.get(dict, key, [])
Map.get(dict, key, [])
end
end
@@ -25,4 +25,4 @@ defmodule TodoList do
def entries(todo_list, date) do
MultiDict.get(todo_list, date)
end
end
end
@@ -46,7 +46,7 @@ end
defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}
def new(entries \\ []) do
Enum.reduce(
@@ -61,7 +61,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)
%TodoList{todo_list |
entries: new_entries,
@@ -95,7 +95,7 @@ defmodule TodoList do
old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -105,6 +105,6 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
end
@@ -43,7 +43,7 @@ end
defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}
def new(entries \\ []) do
Enum.reduce(
@@ -58,7 +58,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)
%TodoList{todo_list |
entries: new_entries,
@@ -92,7 +92,7 @@ defmodule TodoList do
old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -102,6 +102,6 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
end
@@ -14,14 +14,14 @@ defmodule KeyValueStore do
end
def init(_) do
{:ok, HashDict.new}
{:ok, %{}}
end
def handle_cast({:put, key, value}, state) do
{:noreply, HashDict.put(state, key, value)}
{:noreply, Map.put(state, key, value)}
end
def handle_call({:get, key}, _, state) do
{:reply, HashDict.get(state, key), state}
{:reply, Map.get(state, key), state}
end
end
end
@@ -44,14 +44,14 @@ defmodule KeyValueStore do
end
def init do
HashDict.new
%{}
end
def handle_call({:put, key, value}, state) do
{:ok, HashDict.put(state, key, value)}
{:ok, Map.put(state, key, value)}
end
def handle_call({:get, key}, state) do
{HashDict.get(state, key), state}
{Map.get(state, key), state}
end
end
end
@@ -56,14 +56,14 @@ defmodule KeyValueStore do
end
def init do
HashDict.new
%{}
end
def handle_cast({:put, key, value}, state) do
HashDict.put(state, key, value)
Map.put(state, key, value)
end
def handle_call({:get, key}, state) do
{HashDict.get(state, key), state}
{Map.get(state, key), state}
end
end
end
@@ -72,7 +72,7 @@ end
defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}
def new(entries \\ []) do
Enum.reduce(
@@ -87,7 +87,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)
%TodoList{todo_list |
entries: new_entries,
@@ -121,7 +121,7 @@ defmodule TodoList do
old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -131,6 +131,6 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
end
@@ -35,7 +35,7 @@ end
defmodule TodoList do
defstruct auto_id: 1, entries: HashDict.new
defstruct auto_id: 1, entries: %{}
def new(entries \\ []) do
Enum.reduce(
@@ -50,7 +50,7 @@ defmodule TodoList do
entry
) do
entry = Map.put(entry, :id, auto_id)
new_entries = HashDict.put(entries, auto_id, entry)
new_entries = Map.put(entries, auto_id, entry)
%TodoList{todo_list |
entries: new_entries,
@@ -84,7 +84,7 @@ defmodule TodoList do
old_entry ->
new_entry = updater_fun.(old_entry)
new_entries = HashDict.put(entries, new_entry.id, new_entry)
new_entries = Map.put(entries, new_entry.id, new_entry)
%TodoList{todo_list | entries: new_entries}
end
end
@@ -94,6 +94,6 @@ defmodule TodoList do
%TodoList{entries: entries} = todo_list,
entry_id
) do
%TodoList{todo_list | entries: HashDict.delete(entries, entry_id)}
%TodoList{todo_list | entries: Map.delete(entries, entry_id)}
end
end
end
Oops, something went wrong.

0 comments on commit 51bc04b

Please sign in to comment.