commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jack, Paul" <pj...@sfaf.org>
Subject RE: [Collections][SUBMIT] ReferenceMap...take 3...
Date Fri, 19 Jul 2002 20:10:15 GMT

> I prefer to call purge in map metods like "get", "pu" 
> (WeakHashMap doe's the same ). JVM runs some internal 
> thread itself for references.

Yeah, ReferenceMap should mimic WeakHashMap's semantics wherever
possible.  I thought for some reason that WeakHashMap only purged
on write operations (put, remove) but upon re-reviewing the code,
it seems that WeakHashMap purges on *every* method invocation,
even simple ones like size().

And if ReferenceMap does a purge() before every operation, then
there really isn't much point in providing autoPurge() at all,
since the stale entries would be removed every time the map
was accessed.  (Though I guess if the map sat idle for long 
periods of time then large amounts of stale entries could 
accumulate; but this seems rare and could be avoided with a 
manual purge).

Actually, there really isn't much point in providing a public
purge() either, as users could manually purge the entries 
by calling, say, isEmpty().  


> Some "good" algorithms  are "slow" itself  there are a lot of 
> algorithms, the most popular is this :
> 
>  hash := ( M - 2 - x) mod ( M - 2 )   
> // M and ( M - 2 ) are prime numbers "Twins"
> 
> prime numbers can be generated and hardcoded in static array, it is
> recomended to use exponent sequence fo this table:
> 
>  M(i + 1) >= M(i)*C  // C > 1, M(i) and ( M(i) - 2 ) are prime numbers

Actually, I was wrong about WeakHashMap.  It first multiplies the
key's hashCode() by -127 before getting the table index, which ReferenceMap
doesn't do...that would avoid the memory address problem Michael
mentioned.

Although if we hardcode the prime number then the above function
would probably be fast enough.  

 
> this is a good resource:
> http://pauillac.inria.fr/algo/AofA/

Hm.  I couldn't really find my way around the above page.  It definitely
has a lot of good stuff but it's organized chronologically, so I couldn't
find specific things related to hash functions... I'll keep looking.

-Paul



--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message