File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < cstdio>
2
+ #include < cstdint>
3
+ #include < cmath>
4
+
5
+ uint32_t murmur_hash_11 (uint32_t src) {
6
+ const uint32_t M = 0x5bd1e995u ;
7
+ uint32_t h = 1190494759u ;
8
+ src *= M; src ^= src>>24 ; src *= M;
9
+ h *= M; h ^= src;
10
+ h ^= h>>13 ; h *= M; h ^= h>>15 ;
11
+ return h;
12
+ }
13
+
14
+ float sine_based_hash (float src) {
15
+ float i;
16
+ float f = modf (sin (src * 12.9898 ) * 43758.5453123 , &i);
17
+ if (f < 0.0 ) f += 1.0 ;
18
+ return f;
19
+ }
20
+
21
+ int main () {
22
+ std::puts (" hashes" );
23
+ int loop_count = 100000 ;
24
+ for (int i = 0 ; i < loop_count; ++i) {
25
+ union {
26
+ float f;
27
+ uint32_t u;
28
+ } hash;
29
+ hash.u = (murmur_hash_11 (i) & 0x007fffffu ) | 0x3f800000u ;
30
+ std::printf (" %.9f\n " , hash.f - 1.0 );
31
+ /*
32
+ std::printf("%.9f\n", sine_based_hash((float)i / loop_count));
33
+ */
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments