libmoost
|
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>
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_hash > | m_bhashes |
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.
moost::algorithm::ketama_partitioner< T >::ketama_partitioner | ( | size_t | num_buckets, |
size_t | num_hashes = 4096 |
||
) | [inline] |
moost::algorithm::ketama_partitioner< T >::ketama_partitioner | ( | const std::vector< Y > & | buckets, |
size_t | num_hashes = 4096 |
||
) | [inline] |
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.
static uint32_t moost::algorithm::ketama_partitioner< T >::default_seed | ( | ) | [inline, static, private] |
unsigned int moost::algorithm::ketama_partitioner< T >::fnv_hash | ( | const void * | key, |
size_t | len | ||
) | const [inline, private] |
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.
size_t moost::algorithm::ketama_partitioner< std::string >::partition | ( | const std::string & | key | ) | const [inline] |
Definition at line 172 of file ketama_partitioner.hpp.
std::vector<bucket_hash> moost::algorithm::ketama_partitioner< T >::m_bhashes [private] |
Definition at line 78 of file ketama_partitioner.hpp.