-module(htbl). % imperative thread-safe hashtable % API follows that of dict; when in doubt, look at dict -export([new/1, % returns new hashtable, given number of processes store/3, % store key-value pair, replacing old key mapping update/4, % update value of a key-value pair find/2, % return mapped value, or error erase/2, % erase key, value pair fetch_keys/1, % return all keys unit_test/0 ]). %% ----------------------------------------------------------------------------- %% In: %% Nprocs: number of processes to allocate %% Out: a new hashtable that is implemented as some number of processes (you %% choose) parameterized by Nprocs, allowing concurrent access similar to %% that which we defined for arrays in iarray.erl %% Note: look at the erlang:phash2 built-in function %% ----------------------------------------------------------------------------- new(Nprocs) -> . %% ----------------------------------------------------------------------------- %% In: %% Key, Val: key-value pair to add to hashtable %% H: the hashtable %% Out: (none) %% Replaces current Key mapping if one exists. %% ----------------------------------------------------------------------------- store(Key, Val, H) -> ok. %% ----------------------------------------------------------------------------- %% In: %% Key: a key %% Fun: function value -> value to apply to existing value mapped by Key %% Initial: initial value if key is not mapped %% H: the hashtable %% Out: (none) %% ----------------------------------------------------------------------------- update(Key, Fun, Initial, H) -> ok. %% ----------------------------------------------------------------------------- %% In: %% Key: a key %% H: the hashtable %% Out: {ok, Value} for Value mapped by Key; or error if Key is unmapped %% ----------------------------------------------------------------------------- find(Key, H) -> . %% ----------------------------------------------------------------------------- %% In: %% Key: a key %% H: the hashtable %% Out: (none) %% Erase all key-value pairs for given Key. %% ----------------------------------------------------------------------------- erase(Key, H) -> ok. %% ----------------------------------------------------------------------------- %% In: %% H: the hashtable %% Out: list of all currently mapped keys %% ----------------------------------------------------------------------------- fetch_keys(H) -> . unit_test() -> ok.