English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Request for weak functional map ...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-12-04 (16:05)
From: Stefan Monnier <monnier@i...>
Subject: Re: Request for weak functional map ...
> I wish a data structure similar to the Map provided by standard library
> (logarithmic insertion and deletion) ... but with a "weak key" behavior:

Of course you can implement it in the GC (although it can be tricky if you
data-structure is complex, as you mention).  But another way to do it is to
use a normal non-weak Map but using weak-references for the keys and then
"every once in a while" scan the map to remove entries whose weak-key has
been collected.

If you implement the Map yourself (rather than using the library version),
you can do the weak-key-sweep as part of the normal tree traversal done
during lookups and insertions.