What about something like that:
-module(unidict).
-export([
new/0,
find/2,
store/3
]).
new() ->
dict:new().
find(Key, Dict) ->
dict:find({key, Key}, Dict).
store(K, V, Dict) ->
Key = {key, K},
case dict:is_key(Key, Dict) of
true ->
erlang:error(badarg);
false ->
Value = {value, V},
case dict:is_key(Value, Dict) of
true ->
erlang:error(badarg);
false ->
dict:store(Value, K, dict:store(Key, V, Dict))
end
end.
Example shell session:
1> c(unidict).
{ok,unidict}
2> D = unidict:new().
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}
3> D1 = unidict:store(key, value, D).
{dict,2,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],
[[{key,key}|value],[{value,...}|{...}]],
[]}}}
4> D2 = unidict:store(key, value, D1).
** exception error: bad argument
in function unidict:store/3
5> D2 = unidict:store(key2, value, D1).
** exception error: bad argument
in function unidict:store/3
6> D2 = unidict:store(key, value2, D1).
** exception error: bad argument
in function unidict:store/3
7> D2 = unidict:store(key2, value2, D1).
{dict,4,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],
[[{key,key2}|value2]],
[],[],[],[],[],[],[],[],[],[],[],
[[{value,value2}|{key,key2}]],
[[{key,key}|value],[{value,...}|{...}]],
[]}}}
8> unidict:find(key, D2).
{ok,value}
9> unidict:find(key2, D2).
{ok,value2}