mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
delete/2 now does not crash when there is nothing to delete. fold/1 added
SVN Revision: 2383
This commit is contained in:
parent
fef762243c
commit
94a638da85
@ -32,7 +32,8 @@
|
|||||||
delete_root/1,
|
delete_root/1,
|
||||||
get_root/1,
|
get_root/1,
|
||||||
lookup/2,
|
lookup/2,
|
||||||
is_empty/1]).
|
is_empty/1,
|
||||||
|
fold/3]).
|
||||||
|
|
||||||
empty() ->
|
empty() ->
|
||||||
nil.
|
nil.
|
||||||
@ -105,6 +106,8 @@ delete(Key, Tree) ->
|
|||||||
HashKey = {erlang:phash2(Key), Key},
|
HashKey = {erlang:phash2(Key), Key},
|
||||||
delete1(HashKey, Tree).
|
delete1(HashKey, Tree).
|
||||||
|
|
||||||
|
delete1(_HashKey, nil) ->
|
||||||
|
nil;
|
||||||
delete1(HashKey, {HashKey1, Priority1, Value1, Left, Right} = Tree) ->
|
delete1(HashKey, {HashKey1, Priority1, Value1, Left, Right} = Tree) ->
|
||||||
if
|
if
|
||||||
HashKey < HashKey1 ->
|
HashKey < HashKey1 ->
|
||||||
@ -162,3 +165,9 @@ lookup1({HashKey1, Priority1, Value1, Left, Right}, HashKey) ->
|
|||||||
{ok, Priority1, Value1}
|
{ok, Priority1, Value1}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
fold(_F, Acc, nil) ->
|
||||||
|
Acc;
|
||||||
|
fold(F, Acc, {{_Hash, Key}, Priority, Value, Left, Right}) ->
|
||||||
|
Acc1 = F({Key, Priority, Value}, Acc),
|
||||||
|
Acc2 = fold(F, Acc1, Left),
|
||||||
|
fold(F, Acc2, Right).
|
||||||
|
Loading…
Reference in New Issue
Block a user