can't remember
This commit is contained in:
parent
c67bcc32e7
commit
fa63ea104b
9 changed files with 53 additions and 6 deletions
22
src/key_value_store.erl
Normal file
22
src/key_value_store.erl
Normal file
|
@ -0,0 +1,22 @@
|
|||
-module(key_value_store).
|
||||
-export(start/0,stop/0,set_item/2,get_item/1,get/1,length(0,clean/0).
|
||||
|
||||
start() ->
|
||||
spawn_link(fun() -> loop([]) end).
|
||||
|
||||
stop() ->
|
||||
self() ! {stop}
|
||||
|
||||
loop(Touples) ->
|
||||
receive ->
|
||||
{set_item, Key, Value} ->
|
||||
Touple = find(Touples, Key)
|
||||
{stop} ->
|
||||
{'EXIT', normal}
|
||||
|
||||
find([], _) -> false;
|
||||
find([{Key, _}|Tuples], Match) ->
|
||||
case Key == Match of
|
||||
true -> true;
|
||||
false -> find(Tuples, Match)
|
||||
end.
|
Reference in a new issue