[erlang-questions] Help on dictionary search
Bob Cowdery
Bob.Cowdery@REDACTED
Tue Nov 7 14:46:22 CET 2006
I wonder if someone could help me with what I guess must seem a fairly elementary problem.
I have a dictionary of the form [{class, [Pid, Pid, Pid ...]}, {class1[...]}, ...]. A given Pid can appear in one or more classes. Given a Pid I want to delete all instances of that Pid from the dictionary and if the class then has an empty list to remove the class. Generally I look up the dictionary by class and don't mind a linear search for the delete as its occational.
I think it's something like this, but I get lost on the details and don't know how to 'do something' with the head. Do I need to return a new dictionary.
search({_,[_, Pid, _]}, H|T) ->
%% we have a match of the Pid
%% do something with it!
search({_,[_, Pid, _]}, _|T) ->
%% no match so recurse with the rest
search ({_,[_, Pid, _]}, T);
search({_,[_, Pid, _]}, []) ->
ok
Thanks
Bob
More information about the erlang-questions
mailing list