From: Jeff Garzik Date: Sat, 23 Apr 2005 20:33:19 GMT Subject: Re: Hash collision count Message-ID: <426AB10F.9050300@pobox.com> In-Reply-To: <426AAFC3.800@pobox.com> Jeff Garzik wrote: > > Ideally a hash + collision-count pair would make the best key, rather > than just hash alone. > > A collision -will- occur eventually, and it is trivial to avoid this > problem: > > $n = 0 > attempt to store as $hash-$n > if $hash-$n exists (unlikely) > $n++ > goto restart > key = $hash-$n This of course presumes that you know that your new data does not exist in the cache. Otherwise, you would need to hash the on-disk $hash-0 to determine if its a collision or a reference. Jeff