[erlang-bugs] gb_trees:from_orddict loses data?

Jimmy Ruska <>
Fri Aug 10 19:17:25 CEST 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20120810/e386c2e2/attachment.html>


More information about the erlang-bugs mailing list