On Wed, 25 Apr 2007, Brad Fitzpatrick wrote:

Back in August I posted some consistent hashing code.  I finally got
around to putting it into a Perl library recently:

  http://search.cpan.org/~bradfitz/Set-ConsistentHash/

I agree with Dustin that a specification and a reference implementation would be useful - I think in effect that is what Brad's code is (or could evolve into).

FWIW, attached is a patch to Set::ConsistentHash that hides some implementation details and lets you change lookups from this:

   $selected_target = $set->buckets->[your_hash_func($your_key) % 1024];

to this:

   $set->set_hash_func(\&your_hash_func);   // optional

   $selected_target = $set->get_target($your_key);


Also attached, a quick first cut at Cache::Memcached::ConsistentHash, which simply subclasses Set::ConsistentHash and sets the hash func to the one currently used in the Memcached client, i.e.:

   crc32($_[0]) >> 16) & 0x7fff


Larry

Attachment: ConsistentHash.pm
Description: Cache-Memcached-ConsistentHash.pm

Attachment: patch-Set-ConsistentHash.patch
Description: patch-Set-ConsistentHash.patch

Reply via email to