[erlang-bugs] gb_trees:from_orddict loses data?

Hunter Morris <>
Fri Aug 10 19:23:47 CEST 2012


>From the gb_trees:from_orddict/1 documentation:

    "Turns an ordered list List of key-value tuples into a tree. The
list must not contain duplicate keys."

None of the failing examples you provide are of ordered lists. If you
modify your first example like so:

    1> gb_trees:lookup(6619, gb_trees:from_orddict([ {N, N} || N <-
lists:sort([6619, 1])])).
    {value,6619}

It behaves as expected for your other examples as well.

Best,
Hunter

On Fri, Aug 10, 2012 at 6:17 PM, Jimmy Ruska <> wrote:
> I was benchmarking different things and I came across this weird behavior.
>
> 1> gb_trees:lookup(6619,gb_trees:from_orddict([ {N,N} || N <- [6619,1]])).
> none
>
> 2> gb_trees:lookup(6619,gb_trees:from_orddict([ {N,N} || N <- [1,6619,2]])).
> {value,6619}
>
> 3> gb_trees:from_orddict([ {N,N} || N <- [6619,1]]).
> {2,{1,1,{6619,6619,nil,nil},nil}}
>
> It's supposed to be {Size, {Key, Val, Smaller, Bigger}} but the value that's
> bigger is in the smaller part. It's still in there but it doesn't find it.
>
> If I insert manually it's no problem. The Tree is structured differently.
>
> 4> gb_trees:lookup(6619,lists:foldl(fun(N,T) -> gb_trees:enter(N,N,T)
> end,gb_trees:empty(),[6619,1])).
> {value,6619}
>
> 5> lists:foldr(fun(N,T) -> gb_trees:enter(N,N,T)
> end,gb_trees:empty(),[6619,1]).
> {2,{1,1,nil,{6619,6619,nil,nil}}}
>
> The number 6619 has no relevance, switch in any number.
>
> 6> gb_trees:lookup(2,gb_trees:from_orddict([{2, 2}, {1, 1}])).
> none
>
> It also doesn't matter how many elements are in the list.
>
> - Jimmy
>
>
>
> _______________________________________________
> erlang-bugs mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-bugs
>


More information about the erlang-bugs mailing list