[erlang-questions] Extending term external format to support shared substructures

Bjorn Gustavsson <>
Tue Mar 31 11:27:11 CEST 2009


On Tue, Mar 31, 2009 at 3:19 AM, Matthew Dempsky <> wrote:

>
> I haven't thought of a good way to extend term_to_binary to support
> generating such tags yet.  My best idea currently is to add an option
> like {dictionary, Escape, ListOfTerms}, and then encode terms in
> ListOfTerms in order as the dictionary, and to detect when encoding
> {Escape, Index} and create a WORD tag instead of a tuple tag.  (I
> imagine Escape would generally be a reference.)

What everybody wants and expects is:

term_to_binary(Term, [preserve_sharing])

where sub-terms (even parts of lists) are automatically detected and preserved.

It can be implemented with a hash table, with a mapping from a tagged pointer to
the index in the term dictionary. The hash table would be created and
filled in by the
same routine that calculates the size of the external format, and used
when encoding
the term.

/Bjorn

-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list