22 for (
auto it = nodes.begin(); it != nodes.end(); ++it) {
137 std::vector<size_t>* returnRankIds)
const {
138 size_t modRank = rank %
weights_.size();
142 double maxWeight = -1;
143 int maxWeightIndex = 0;
145 std::vector<std::pair<double, size_t>> scaledWeights;
147 scaledWeights.reserve(
weights_.size());
151 double combinedHash =
computeHash(entry->first + key);
154 double scaledWeight = 0;
155 if (entry->second != 0) {
156 scaledWeight = pow(scaledHash, (
double)1 / entry->second);
159 if (scaledWeight > maxWeight) {
160 maxWeight = scaledWeight;
164 scaledWeights.emplace_back(scaledWeight,
i);
170 rankIndex = maxWeightIndex;
172 std::nth_element(scaledWeights.begin(),
173 scaledWeights.begin() + modRank,
175 std::greater<std::pair<double, size_t>>());
176 rankIndex = scaledWeights[modRank].second;
181 returnRankIds->push_back(rankIndex);
183 returnRankIds->reserve(modRank);
184 for (
size_t i = 0;
i < modRank;
i++) {
185 returnRankIds->push_back(scaledWeights[
i].second);
200 const size_t rank)
const {
201 std::vector<size_t> selection;
204 selection = std::vector<size_t>(
weights_.size());
206 selection.begin(), selection.end(), [n = 0]()
mutable {
return n++; });
uint64_t fnv64_buf(const void *buf, size_t n, uint64_t hash=FNV_64_HASH_START) noexcept
uint64_t computeHash(const char *data, size_t len) const
void build(std::vector< std::pair< std::string, uint64_t >> &) override
size_t get(const uint64_t key, const size_t rank=0) const override
std::vector< size_t > selectNUnweighted(const uint64_t key, const size_t rank) const
#define FOR_EACH_ENUMERATE(count, i, c)
uint64_t twang_mix64(uint64_t key) noexcept
size_t getNthByWeightedHash(const uint64_t key, const size_t modRank, std::vector< size_t > *returnRankIds) const
static constexpr uint64_t data[1]
std::vector< std::pair< uint64_t, uint64_t > > weights_
double getMaxErrorRate() const override