libmoost
moost::algorithm::ketama_partitioner< T > Class Template Reference

ketama_partitioner implements consistent hashing, such that the addition or removal of buckets does not significantly change the mapping of keys to buckets. By using consistent hashing, only K/n keys need to be remapped on average, where K is the number of keys, and n is the number of buckets. More...

#include <ketama_partitioner.hpp>

Inheritance diagram for moost::algorithm::ketama_partitioner< T >:
Collaboration diagram for moost::algorithm::ketama_partitioner< T >:

List of all members.

Classes

struct  bucket_hash

Public Member Functions

 ketama_partitioner (size_t num_buckets, size_t num_hashes=4096)
template<typename Y >
 ketama_partitioner (const std::vector< Y > &buckets, size_t num_hashes=4096)
 ketama_partitioner (const std::vector< std::string > &buckets, size_t num_hashes=4096)
 Specialization for bucket of strings.
size_t partition (const T &key) const
template<>
size_t partition (const std::string &key) const

Private Member Functions

unsigned int fnv_hash (const void *key, size_t len) const

Static Private Member Functions

static uint32_t default_seed ()

Private Attributes

std::vector< bucket_hashm_bhashes

Detailed Description

template<typename T>
class moost::algorithm::ketama_partitioner< T >

ketama_partitioner implements consistent hashing, such that the addition or removal of buckets does not significantly change the mapping of keys to buckets. By using consistent hashing, only K/n keys need to be remapped on average, where K is the number of keys, and n is the number of buckets.

Definition at line 45 of file ketama_partitioner.hpp.


Constructor & Destructor Documentation

template<typename T>
moost::algorithm::ketama_partitioner< T >::ketama_partitioner ( size_t  num_buckets,
size_t  num_hashes = 4096 
) [inline]

Definition at line 94 of file ketama_partitioner.hpp.

Here is the call graph for this function:

template<typename T>
template<typename Y >
moost::algorithm::ketama_partitioner< T >::ketama_partitioner ( const std::vector< Y > &  buckets,
size_t  num_hashes = 4096 
) [inline]

Definition at line 115 of file ketama_partitioner.hpp.

Here is the call graph for this function:

template<typename T>
moost::algorithm::ketama_partitioner< T >::ketama_partitioner ( const std::vector< std::string > &  buckets,
size_t  num_hashes = 4096 
) [inline]

Specialization for bucket of strings.

Definition at line 138 of file ketama_partitioner.hpp.

Here is the call graph for this function:


Member Function Documentation

template<typename T>
static uint32_t moost::algorithm::ketama_partitioner< T >::default_seed ( ) [inline, static, private]

Definition at line 59 of file ketama_partitioner.hpp.

Here is the caller graph for this function:

template<typename T>
unsigned int moost::algorithm::ketama_partitioner< T >::fnv_hash ( const void *  key,
size_t  len 
) const [inline, private]

Definition at line 81 of file ketama_partitioner.hpp.

Here is the caller graph for this function:

template<typename T>
size_t moost::algorithm::ketama_partitioner< T >::partition ( const T &  key) const [inline, virtual]

Returns a bucket for the given key, from 0 to num_buckets - 1. Must be overridden by implementing partitioners.

Implements moost::algorithm::partitioner< T >.

Definition at line 160 of file ketama_partitioner.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

template<>
size_t moost::algorithm::ketama_partitioner< std::string >::partition ( const std::string &  key) const [inline]

Definition at line 172 of file ketama_partitioner.hpp.


Member Data Documentation

template<typename T>
std::vector<bucket_hash> moost::algorithm::ketama_partitioner< T >::m_bhashes [private]

Definition at line 78 of file ketama_partitioner.hpp.


The documentation for this class was generated from the following file: