consistent hashing: in Perl, standards

Alex Stapleton alexs at
Thu Apr 26 12:03:14 UTC 2007

Re: Set::ConsistentHash, I can barely understand Perl code but it  
looks to me like collisions in the hashes of targets are simply  
ignored currently?

         foreach my $ptn (1..$num_pts) {
             my $key = "$target-$ptn";
             my $val = unpack("L", substr(sha1($key), 0, 4));
             $pts->{$val} = \$target;

If the 2 of the keys have the same first 4 bytes of an SHA1 hash then  
it will cause $pts->{$val} to be overwritten with the new target it's  
already there. Right? Also I don't think sha1 is a good choice of  
algorithm if you are just going to cast it to a uint32. crc32 would  
make more sense.

On 26 Apr 2007, at 07:47, Just Marc wrote:

> As for a standard memcache client library, I'm all for a pure C  
> version to be bundled with memcached.
> 3. The PHP memcache module uses the C library and I'm betting  
> that's the most popular users of memcache in general.
> 4. The extreme urgency in the need to replace libmemcache is shown  
> below:

Last weekend I wrote a C memcached client with UDP and TCP support,  
and yesterday I got the PHP wrapper working, just need to add a few  
extra features and do some testing before sticking it up somewhere.  
However it does use libevent for handling all of it's I/O and uses  
ketama for hashing so I'm not sure how much interest other people  
will have in it.

More information about the memcached mailing list