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

traveller59's avatar
traveller59 committed
6
namespace cuhash {
7
8
9
10

void GenerateFunctions(const unsigned N, const unsigned num_keys,
                       const unsigned *d_keys, const unsigned table_size,
                       uint2 *constants) {
11
12
13
14
15
16
  bool regenerate = true;

  while (regenerate) {
    regenerate = false;

    // Generate a set of hash function constants for this build attempt.
17
    for (unsigned i = 0; i < N; ++i) {
traveller59's avatar
traveller59 committed
18
19
20
      // uint_distribution(random_engine) % kPrimeDivisor;
      // genrand_int32() % kPrimeDivisor;
      unsigned new_a = generate_random_uint32() % kPrimeDivisor;
21
      constants[i].x = (1 > new_a ? 1 : new_a);
traveller59's avatar
traveller59 committed
22
      constants[i].y = generate_random_uint32() % kPrimeDivisor;
23
24
25
26
    }

#ifdef FORCEFULLY_GENERATE_NO_CYCLES
    // Ensure that every key gets N different slots.
27
28
    regenerate =
        CheckAssignedSameSlot(N, num_keys, d_keys, table_size, constants);
29
30
31
32
33
34
35
36
37
#endif
  }

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

38
}; // namespace cuhash