hash_functions.cu 1.4 KB
Newer Older
traveller59's avatar
traveller59 committed
1
2
3
4
#include <cuhash/hash_table.h>
#include <cuhash/debugging.h>
#include <cassert>
#include <random>
5

traveller59's avatar
traveller59 committed
6
7
8
namespace cuhash {
  
std::random_device random_dev;
9

traveller59's avatar
traveller59 committed
10
11
std::mt19937 random_engine(random_dev());
std::uniform_int_distribution<unsigned> uint_distribution;
12

traveller59's avatar
traveller59 committed
13
14
15
unsigned generate_random_uint32(){
  return uint_distribution(random_engine);
}
16
17
18
19
20
21
22
23
24
25
26
27
28

void GenerateFunctions(const unsigned  N,
                       const unsigned  num_keys,
                       const unsigned *d_keys,
                       const unsigned  table_size,
                             uint2    *constants) {
  bool regenerate = true;

  while (regenerate) {
    regenerate = false;

    // Generate a set of hash function constants for this build attempt.
    for (unsigned i = 0 ; i < N; ++i) {
traveller59's avatar
traveller59 committed
29
30
31
      // uint_distribution(random_engine) % kPrimeDivisor;
      // genrand_int32() % kPrimeDivisor;
      unsigned new_a = generate_random_uint32() % kPrimeDivisor;
32
      constants[i].x = (1 > new_a ? 1 : new_a);
traveller59's avatar
traveller59 committed
33
      constants[i].y = generate_random_uint32() % kPrimeDivisor;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    }

#ifdef FORCEFULLY_GENERATE_NO_CYCLES
    // Ensure that every key gets N different slots.
    regenerate = CheckAssignedSameSlot(N, num_keys, d_keys, table_size, constants);
#endif
  }


#ifdef TAKE_HASH_FUNCTION_STATISTICS
  // Examine how well distributed the items are.
  TakeHashFunctionStatistics(num_keys, d_keys, table_size, constants, N);
#endif
}

}; // namespace CuckooHashing