gb_trees:search/3

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Sun Sep 11 21:27:09 CEST 2005


Replying to my own post, the easier case 
is of course when just a resource (not a specific
number) is asked for:

reserve(Free) ->
    case gb_trees:take_smallest(Free) of
	{Min, Min, Free1} ->
	    {Min, Free1};
	{Min, Max, Free1} when Max > Min ->
	    {Min, gb_trees:insert(Min+1, Max, Free1)}
    end.

free/2 is more involved as it needs to de-fragment the
tree, but that would be done along the same lines as 
reserve/2, using the gb_trees:search/3 function.

/Uffe



More information about the erlang-questions mailing list