libmoost
|
00001 /* vim:set ts=3 sw=3 sts=3 et: */ 00028 #ifndef MOOST_ALGORITHM_MODULO_PARTITIONER_HPP__ 00029 #define MOOST_ALGORITHM_MODULO_PARTITIONER_HPP__ 00030 00031 #include <boost/functional/hash.hpp> 00032 #include "partitioner.hpp" 00033 00034 namespace moost { namespace algorithm { 00035 00038 template <typename T> 00039 class modulo_partitioner : public partitioner<T> 00040 { 00041 private: 00042 00043 boost::hash<T> m_hasher; 00044 00045 public: 00046 00049 basic_partitioner(size_t num_buckets) 00050 : partitioner<T>(num_buckets) 00051 { 00052 } 00053 00055 size_t partition(const T & key) const 00056 { 00057 return m_hasher(key) % this->getNumBuckets(); 00058 } 00059 }; 00060 00061 }} // moost::partition 00062 00063 #endif // MOOST_ALGORITHM_MODULO_PARTITIONER_HPP__