proxygen
RendezvousHash.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #pragma once
11 
12 #include <string>
13 #include <vector>
15 
16 namespace proxygen {
17 /*
18  * Weighted Rendezvous Hash is a way to consistently route requests to
19  * candidates.
20  * Unlike ConsistentHash, Weighted Rendezvous Hash supports the action to
21  * reduce the relative weight of a candidate while incurring minimum data
22  * movement.
23  */
25  public:
26  double getMaxErrorRate() const override;
27 
28  void build(std::vector<std::pair<std::string, uint64_t>>&) override;
29 
30  size_t get(const uint64_t key, const size_t rank = 0) const override;
31 
32  std::vector<size_t> selectNUnweighted(const uint64_t key,
33  const size_t rank) const;
34 
35  private:
36  size_t getNthByWeightedHash(const uint64_t key,
37  const size_t modRank,
38  std::vector<size_t>* returnRankIds) const;
39  uint64_t computeHash(const char* data, size_t len) const;
40 
42 
43  std::vector<std::pair<uint64_t, uint64_t>> weights_;
44 };
45 
46 } // proxygen
uint64_t computeHash(const char *data, size_t len) const
void build(std::vector< std::pair< std::string, uint64_t >> &) override
std::vector< size_t > selectNUnweighted(const uint64_t key, const size_t rank) const
size_t getNthByWeightedHash(const uint64_t key, const size_t modRank, std::vector< size_t > *returnRankIds) const
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
std::vector< std::pair< uint64_t, uint64_t > > weights_
double getMaxErrorRate() const override