1 Star 0 Fork 0

khiphop / cGroupCache

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
consistent_hash.hpp 832 Bytes
一键复制 编辑 原始数据 按行查看 历史
khiphop 提交于 2022-01-12 16:48 . Initial commit
#ifndef consistent_hash_hpp
#define consistent_hash_hpp
#include <stdio.h>
#include <set>
#include <string>
#include <map>
class ConsistentHash {
private:
std::map<uint32_t, std::string> hashRing; // {key: hashVal, value: real ip}
int virtualNodeCount; // count of virtual nodes for physical node
public:
ConsistentHash(int vnc) : virtualNodeCount(vnc) {};
~ConsistentHash() {
hashRing.clear();
};
static uint32_t HashHandler(std::string key);
void RegisterNode(const std::string &node);
void ComposeElementToRing(const std::string &node, const std::string &key);
void DelElementFromRing(const std::string &key);
void RemoveNode(const std::string &node);
std::string ChooseNode(const std::string &key);
};
#endif /* consistent_hash_hpp */
C++
1
https://gitee.com/khiphop/cGroupCache.git
git@gitee.com:khiphop/cGroupCache.git
khiphop
cGroupCache
cGroupCache
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891