]> granicus.if.org Git - ejabberd/commitdiff
treap.erl backport
authorEvgeniy Khramtsov <xramtsov@gmail.com>
Wed, 29 Jul 2009 03:42:23 +0000 (03:42 +0000)
committerEvgeniy Khramtsov <xramtsov@gmail.com>
Wed, 29 Jul 2009 03:42:23 +0000 (03:42 +0000)
SVN Revision: 2399

src/treap.erl

index 360f543dead4c47b5c46a28f397640dfe1fe8ae9..42438f2286844223376fec8cdd03b6a1ead8b13d 100644 (file)
@@ -44,7 +44,7 @@ insert(Key, Priority, Value, Tree) ->
 
 insert1(nil, HashKey, Priority, Value) ->
     {HashKey, Priority, Value, nil, nil};
-insert1({HashKey1, Priority1, Value1, Left, Right},
+insert1({HashKey1, Priority1, Value1, Left, Right} = Tree,
        HashKey, Priority, Value) ->
     if
        HashKey < HashKey1 ->
@@ -55,8 +55,10 @@ insert1({HashKey1, Priority1, Value1, Left, Right},
            heapify({HashKey1, Priority1, Value1,
                     Left,
                     insert1(Right, HashKey, Priority, Value)});
+       Priority == Priority1 ->
+           {HashKey, Priority, Value, Left, Right};
        true ->
-           erlang:error(key_exists)
+           insert1(delete_root(Tree), HashKey, Priority, Value)
     end.
 
 heapify(nil) ->