Skip to content

Instantly share code, notes, and snippets.

@ruslander
Created February 22, 2013 14:36
Show Gist options
  • Save ruslander/5013846 to your computer and use it in GitHub Desktop.
Save ruslander/5013846 to your computer and use it in GitHub Desktop.
insert/find/delete with Ets
-module(sc_store).
-export([
init/0,
insert/2,
delete/1,
lookup/1
]).
-define(TABLE_ID, ?MODULE).
init() ->
ets:new(?TABLE_ID, [public, named_table]),
ok.
insert(Key, Pid) ->
ets:insert(?TABLE_ID, {Key, Pid}).
lookup(Key) ->
case ets:lookup(?TABLE_ID, Key) of
[{Key, Pid}] -> {ok, Pid};
[] -> {error, not_found}
end.
delete(Pid) ->
ets:match_delete(?TABLE_ID, {'_', Pid}).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment