1
0
mirror of https://github.com/Zygo/bees.git synced 2025-06-17 01:56:16 +02:00

hash: move the random generator out of bees-hash.cc

We need random numbers in more places, so centralize the engines.
Initialize with a proper random seed so every worker thread gets
different behavior.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell
2021-11-16 00:55:58 -05:00
parent 73f94750ec
commit ba694b4881
3 changed files with 14 additions and 4 deletions

View File

@ -5,7 +5,6 @@
#include "crucible/string.h"
#include <algorithm>
#include <random>
#include <sys/mman.h>
@ -538,6 +537,8 @@ BeesHashTable::push_front_hash_addr(HashType hash, AddrType addr)
return found;
}
thread_local uniform_int_distribution<size_t> BeesHashTable::tl_distribution(0, c_cells_per_bucket - 1);
/// Insert a hash entry at some unspecified point in the list.
/// If entry is already present in list, returns true and does not
/// modify list. If entry is not present in list, returns false and
@ -555,9 +556,7 @@ BeesHashTable::push_random_hash_addr(HashType hash, AddrType addr)
Cell *ip = find(er.first, er.second, mv);
bool found = (ip < er.second);
thread_local default_random_engine generator;
thread_local uniform_int_distribution<int> distribution(0, c_cells_per_bucket - 1);
auto pos = distribution(generator);
const auto pos = tl_distribution(bees_generator);
int case_cond = 0;
#if 0