Commit be11fcda authored by cdjgit's avatar cdjgit

add code comments && move brpc::policy::HashFunc to hasher.cpp

parent b1ed71ce
......@@ -104,7 +104,8 @@ public:
// Caller is responsible for Destroy() the instance after usage.
virtual LoadBalancer* New() const = 0;
// Set other
// Config user passed parameters to lb after constrction which
// make lb function more flexible.
virtual bool SetParameters(const butil::StringPairs& params) { return true; }
protected:
......
......@@ -35,7 +35,7 @@ namespace {
bool BuildReplicasDefault(const ServerId server,
const size_t num_replicas,
ConsistentHashingLoadBalancer::HashFunc hash,
HashFunc hash,
std::vector<ConsistentHashingLoadBalancer::Node>* replicas) {
SocketUniquePtr ptr;
if (Socket::AddressFailedAsWell(server.id, &ptr) == -1) {
......
......@@ -43,7 +43,6 @@ public:
return hash < code;
}
};
using HashFunc = uint32_t(*)(const void*, size_t);
using BuildReplicasFunc =
std::function<bool (const ServerId server, const size_t num_replicas, std::vector<Node>* replicas)>;
explicit ConsistentHashingLoadBalancer(const char* name);
......
......@@ -155,7 +155,7 @@ uint32_t CRCHash32(const void* key, size_t len) {
return ((~crc) >> 16) & 0x7fff;
}
const char *GetHashName(uint32_t (*hasher)(const void* key, size_t len)) {
const char *GetHashName(HashFunc hasher) {
if (hasher == MurmurHash32) {
return "murmurhash3";
}
......
......@@ -25,6 +25,8 @@
namespace brpc {
namespace policy {
using HashFunc = uint32_t(*)(const void*, size_t);
void MD5HashSignature(const void* key, size_t len, unsigned char* results);
uint32_t MD5Hash32(const void* key, size_t len);
uint32_t MD5Hash32V(const butil::StringPiece* keys, size_t num_keys);
......
......@@ -485,7 +485,7 @@ TEST_F(LoadBalancerTest, fairness) {
}
TEST_F(LoadBalancerTest, consistent_hashing) {
::brpc::policy::ConsistentHashingLoadBalancer::HashFunc hashs[] = {
::brpc::policy::HashFunc hashs[] = {
::brpc::policy::MurmurHash32,
::brpc::policy::MD5Hash32,
::brpc::policy::KetamaHash
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment