[Gc] Weak hash tables and cycles

Bruce Hoult bruce at hoult.org
Mon Nov 3 16:15:37 PST 2008


On Tue, Nov 4, 2008 at 11:30 AM, Ludovic Courtès <ludo at gnu.org> wrote:
> Hi,
>
> Is it possible to implement a weak-key hash table that can deal with
> cycles using disappearing links?
>
> I'm in particular concerned with the following corner case: K is a key
> in a weak-key hash table, V is its associated value, and V references K.
> This leads to the following object graph, where the dotted arrow denotes
> a disappearing link:
>
>  .---.      .---.
>  | K |<-----| V |
>  `---'      `---'
>    ^          ^
>    :          |
>    :          |
>  .--------------.
>  |   weak-key   |
>  |  hash table  |
>  `--------------'
>
> Neither K nor V can become unreachable in such a case, even if none of
> them is referenced elsewhere.

But surely this is the behaviour you want, as otherwise you would use
a  hash table where both keys and values are weak.



More information about the Gc mailing list