package Cache::Memcached::ConsistentHash;
use base Set::ConsistentHash;
use String::CRC32 qw(crc32);
use strict;
use vars qw($VERSION);
$VERSION = '0.90';

=head1 NAME

Cache::Memcached::ConsistentHash - library for doing consistent hashing
based on Set::ConsistentHash

=head1 SYNOPSIS

  my $set = Cache::Memcached::ConsistentHash->new;

=head1 OVERVIEW

Implements instances of L<Set::ConsistentHash> for L<Cache::Memcached>.
Specifically, sets the key hashing function to:

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

for consistency with other Memcached clients.


=head1 CLASS METHODS

=head2 new

  $set = Cache::Memcached::ConsistentHash->new;

Takes no options.  Creates a new consistent hashing set with no
targets.  You'll need to add them.

=cut

# creates a new consistent hashing set with no targets.  you'll need to add targets.
sub new {
    my $class = shift;
    croak("Unknown parameters") if @_;
    my $self = bless Set::ConsistentHash->new, $class;
    $self->set_hash_func( sub { return (crc32($_[0]) >> 16) & 0x7fff; } );
    return $self;
}

############################################################################

=head1 INSTANCE METHODS

For all instance methods see L<Set::ConsistentHash>.

=head1 AUTHOR

Larry Leszczynski -- larryl@cpan.org

=head1 COPYRIGHT & LICENSE

Copyright 2007, Larry Leszczynski.

You're granted permission to use this code under the same terms as Perl itself.

=head1 WARRANTY

This is free software.  It comes with no warranty of any kind.

=cut

1;
