[erlang-questions] flat representation with erlang term order
Paul Mineiro
paul-trapexit@REDACTED
Fri May 30 18:57:31 CEST 2008
i'm trying to develop a disk based erlang term storage (dets replacement)
using tokyocabinet. i would like the b+tree to be sorted according to
erlang term order to make certain selects cheap.
i noticed that erlang:term_to_binary/1 does not preserve term order, i.e.,
comparing the resulting binaries with memcmp sometimes disagrees with
erlang term order.[1] so the easy way is out.
some questions:
* is there another flat representation of an erlang term available which
preserves erlang term order via memcmp?
* alternatively, is there a function i can call from a linked-in driver
to compare two binaries derived from erlang:term_to_binary/1 which
corresponds to erlang term order? tokyocabinet can use an arbitrary
comparison function (on bytes) so this could work.
other ideas would also be appreciated.
thanks,
-- p
[1]
6> A = 16#10000000ff01.
17592186109697
7> B = 16#100000000002.
17592186044418
8> A < B.
false
9> BA = term_to_binary (A).
<<131,110,6,0,1,255,0,0,0,16>>
10> BB = term_to_binary (B).
<<131,110,6,0,2,0,0,0,0,16>>
11> BA < BB.
true
In an artificial world, only extremists live naturally.
-- Paul Graham
More information about the erlang-questions
mailing list