Skip to content

Instantly share code, notes, and snippets.

@faust45
Created February 9, 2011 14:07
Show Gist options
  • Select an option

  • Save faust45/818530 to your computer and use it in GitHub Desktop.

Select an option

Save faust45/818530 to your computer and use it in GitHub Desktop.
Erlang snipets
% Dict
lookup(Key, [{Key,Value}|Rest]) ->
{value,Value};
lookup(Key, [Pair|Rest]) ->
lookup(Key, Rest);
lookup(Key, []) ->
undefined.
% Tree
lookup(Key, nil) ->
not_found;
lookup(Key, {Key,Value,_,_}) ->
{found,Value};
lookup(Key, {Key1,_,Smaller,_}) when Key < Key1 ->
lookup(Key, Smaller);
lookup(Key, {Key1,_,_,Bigger}) when Key > Key1 ->
lookup(Key, Bigger).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment