Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Another q about many types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christophe Raffalli <raffalli@u...>
Subject: Re: [Caml-list] Weak hash table
Dave Mason a écrit :
> 
> A while ago I bugged Xavier about this.  He agreed it would be nice to
> have weak hash tables, so if anyone volunteered an implementation, I
> suspect it would quickly make its way into the standard library.
> 
> I haven't thought hard about it, but I think it needs some additional
> hooks in the garbage collector.  (Without even *considering* the whole
> heirarchy of weakness in Java!)
> 
> ../Dave

If you want key or value weak hashtable (that is entry are kept in the
hash table is the key of the value 
are pointed from somewhere outside the hashtable), it can be done with
just the Weak module
of Caml (you can almost do it by regexp query replace in hashtbl.ml). 

If you just want value (resp. key) weak hashtable (that is entry are
kept in the hash table if the value 
is pointed from somewhere outside the hashtable), It is possible also,
you just need to do a shallow copy of the key (resp. the value) before
insertion in the table. If you do not want to loose a little memory, you
need help from the GC.

Anyway if your key are integers or floats both are equivalent !

if you key are strings possibly long, the cost of shallow copy may be a
problem.

Just one trouble: if you want hashtabl with unique key all this is true.

If you want hashtable with multiple key (as in module Hashtbl) you need
a weak array of weak array ... it starts
to be a bit complex and may be help from the GC would be useful to get a
nicer code.

-- 
Christophe Raffalli
Université de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tél: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners