commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael A. Smith" <>
Subject RE: [collections] SoftRefHashMap (was RE: Avalon excalibur collec tions migration status)
Date Tue, 16 Jul 2002 03:26:03 GMT
On Mon, 15 Jul 2002, Jack, Paul wrote:
> > It is possible to find a lot of patches in archyve for this 
> > class, some I
> > posted myself a half  year ago.
> I'll go hunting for them (Btw, the mail archive seems broken).

which archive?  

> Still, in the context of a Map, if you surround the keys or values
> with PhantomReferences, those keys or values disappear.  A Map whose
> keys or values aren't visible isn't much of a Map, so I don't see a
> use for PhantomKeyMap or PhantomValueMap.

agreed.  Phantom references are pretty much useless in this case.  At 
least, I really don't see a use for them.

> Now I'm thinking that ReferenceMap is useful for weak keys (in a pre-JDK1.3
> application), weak values, soft keys, soft values...One class for four
> cases. 

As long as it sits over a hash based map, this should work.

> So, maybe we should just eliminate its ability to use phantom references
> and submit it...but I still like Stephen's idea of using decorators for 
> the soft and weak values.

I like the idea of using a decorator as well.  Unfortunately, it doesn't
work -- at least for the soft/weak key cases.  You absolutely need
control over the map when dealing with the keys.  

Consider passing in a Tree based map to a weak key decorator, a TreeMap,
for example.  You want to add an object to the map, so you wrap it in a
reference, but then, the map doesn't know how to handle the key because
its no longer comparable.  You could pass through the implementation of
compareTo to the underlying object, but as soon as the reference is
cleared, there's no way to tell without traversing *both* sides of the
tree to figure out which direction to go (not to mention that you also
need to clean up the tree because there's a removed node in the middle
of it).

At least with a hash based map, you can cache the hash code so that you
get to the correct bucket (and passing the equals method through to the
underlying object in the reference object shouldn't effect things too

So, as much as I'd like to see decorators for all four cases, it is 
really only partially practical in the weak/soft value case.  


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message