[erlang-questions] Re: No, really, please stop misinterpreting what I wrote

Paul Mineiro paul-trapexit@REDACTED
Thu Sep 17 18:18:57 CEST 2009


On Thu, 17 Sep 2009, James Hague wrote:

> Wow, this discussion has blown up :)
>
> Originally, what I wanted was a way to manually make sure that terms
> are shared. This is easy to do by having a data structure function
> that works like this:
>
>   {New_Tree, Item_in_Tree} = some_tree:insert(Tree, Item)
>
> None of the library functions have this, as far as I can tell. I pass
> in a some data item, like a string, and it gets searched for in a tree
> (or similar data structure). If it exists, the same tree and a pointer
> to the item already in the tree are passed back. I can use the
> returned item rather than the original, knowing that sharing is
> occurring if it's possible. If the item doesn't exist, then I get back
> the new tree and exactly the same item I passed in.

I did post a solution to this (hashcons:share/1).

Basically, (as I understand it) any of the standard associative maps you
can insert the same term as key and value and then use the value returned,
and that value will be shared with the associative map. (I'm not sure if
all of the standard *set* implementations have this property).

-- p


More information about the erlang-questions mailing list