Created
February 22, 2013 14:36
-
-
Save ruslander/5013846 to your computer and use it in GitHub Desktop.
insert/find/delete with Ets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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