[erlang-questions] Help on dictionary search

Bengt Kleberg bengt.kleberg@REDACTED
Tue Nov 7 15:13:57 CET 2006

On 2006-11-07 14:46, Bob Cowdery wrote:
> 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.

first do it right. if that is too slow, make it faster.

when you say dictionary, is that some erlang supported data structure? 
if that is the case you might want to disregard the following:

first remove Pid, then clean up the result:
remove( Pid, Dictionary_list ) ->
Fun = fun({Class, Pid_list}) ->
	{Class, lists:remove( Pid, Pid_list )}
lists:map( Fun, Dictionary_list ).

clean_up( Dictionary_list ) ->
Fun = fun({_Class, []}) -> false;
	(_Item) -> true
lists:filter( Fun, Dictionary_list ).

    EPO guidelines 1978: "If the contribution to the known art resides
    solely in a computer program then the subject matter is not
    patentable in whatever manner it may be presented in the claims."

More information about the erlang-questions mailing list