2009-07-08 13:19:16 -07:00
|
|
|
/*
|
2015-02-26 09:54:00 -08:00
|
|
|
* Copyright (c) 2009, 2012, 2014, 2015 Nicira, Inc.
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-07-08 13:19:16 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2014-10-29 11:34:40 -07:00
|
|
|
#undef NDEBUG
|
|
|
|
#include "hash.h"
|
|
|
|
#include <assert.h>
|
2009-07-08 13:19:16 -07:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
hash: Replace primary hash functions by murmurhash.
murmurhash is faster than Jenkins and slightly higher quality, so switch to
it for hashing words.
The best timings I got for hashing for data lengths of the following
numbers of 32-bit words, in seconds per 1,000,000,000 hashes, were:
words murmurhash Jenkins hash
----- ---------- ------------
1 8.4 10.4
2 10.3 10.3
3 11.2 10.7
4 12.6 18.0
5 13.9 18.3
6 15.2 18.7
In other words, murmurhash outperforms Jenkins for all input lengths other
than exactly 3 32-bit words (12 bytes). (It's understandable that Jenkins
would have a best case at 12 bytes, because Jenkins works in 12-byte
chunks.) Even in the case where Jenkins is faster, it's only by 5%. On
average within this data set, murmurhash is 15% faster, and for 4-word
input it is 30% faster.
We retain Jenkins for flow_hash_symmetric_l4() and flow_hash_fields(),
which are cases where the hash value is exposed externally.
This commit appears to improve "ovs-benchmark rate" results slightly by
a few hundred connections per second (under 1%), when used with an NVP
controller.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-01-16 16:14:42 -08:00
|
|
|
#include "jhash.h"
|
2014-04-01 00:47:01 -07:00
|
|
|
#include "ovstest.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
set_bit(uint32_t array[3], int bit)
|
|
|
|
{
|
|
|
|
assert(bit >= 0 && bit <= 96);
|
|
|
|
memset(array, 0, sizeof(uint32_t) * 3);
|
|
|
|
if (bit < 96) {
|
|
|
|
array[bit / 32] = UINT32_C(1) << (bit % 32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 09:54:00 -08:00
|
|
|
/* When bit == n_bits, the function just 0 sets the 'values'. */
|
2014-08-12 11:12:12 +12:00
|
|
|
static void
|
2015-02-26 09:54:00 -08:00
|
|
|
set_bit128(ovs_u128 *values, int bit, int n_bits)
|
2014-08-12 11:12:12 +12:00
|
|
|
{
|
|
|
|
assert(bit >= 0 && bit <= 2048);
|
2015-02-26 09:54:00 -08:00
|
|
|
memset(values, 0, n_bits/8);
|
|
|
|
if (bit < n_bits) {
|
2014-08-12 11:12:12 +12:00
|
|
|
int b = bit % 128;
|
|
|
|
|
|
|
|
if (b < 64) {
|
2015-02-26 09:54:00 -08:00
|
|
|
values[bit / 128].u64.lo = UINT64_C(1) << (b % 64);
|
2014-08-12 11:12:12 +12:00
|
|
|
} else {
|
2015-02-26 09:54:00 -08:00
|
|
|
values[bit / 128].u64.hi = UINT64_C(1) << (b % 64);
|
2014-08-12 11:12:12 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 09:54:00 -08:00
|
|
|
static uint64_t
|
|
|
|
get_range128(ovs_u128 *value, int ofs, uint64_t mask)
|
|
|
|
{
|
2022-04-11 13:37:38 +02:00
|
|
|
if (ofs == 0) {
|
|
|
|
return value->u64.lo & mask;
|
|
|
|
}
|
2015-02-26 09:54:00 -08:00
|
|
|
return ((ofs < 64 ? (value->u64.lo >> ofs) : 0) & mask)
|
|
|
|
| ((ofs <= 64 ? (value->u64.hi << (64 - ofs)) : (value->u64.hi >> (ofs - 64)) & mask));
|
|
|
|
}
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
static uint32_t
|
|
|
|
hash_words_cb(uint32_t input)
|
|
|
|
{
|
|
|
|
return hash_words(&input, 1, 0);
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:26:23 -07:00
|
|
|
static uint32_t
|
hash: Replace primary hash functions by murmurhash.
murmurhash is faster than Jenkins and slightly higher quality, so switch to
it for hashing words.
The best timings I got for hashing for data lengths of the following
numbers of 32-bit words, in seconds per 1,000,000,000 hashes, were:
words murmurhash Jenkins hash
----- ---------- ------------
1 8.4 10.4
2 10.3 10.3
3 11.2 10.7
4 12.6 18.0
5 13.9 18.3
6 15.2 18.7
In other words, murmurhash outperforms Jenkins for all input lengths other
than exactly 3 32-bit words (12 bytes). (It's understandable that Jenkins
would have a best case at 12 bytes, because Jenkins works in 12-byte
chunks.) Even in the case where Jenkins is faster, it's only by 5%. On
average within this data set, murmurhash is 15% faster, and for 4-word
input it is 30% faster.
We retain Jenkins for flow_hash_symmetric_l4() and flow_hash_fields(),
which are cases where the hash value is exposed externally.
This commit appears to improve "ovs-benchmark rate" results slightly by
a few hundred connections per second (under 1%), when used with an NVP
controller.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-01-16 16:14:42 -08:00
|
|
|
jhash_words_cb(uint32_t input)
|
2012-08-21 14:26:23 -07:00
|
|
|
{
|
hash: Replace primary hash functions by murmurhash.
murmurhash is faster than Jenkins and slightly higher quality, so switch to
it for hashing words.
The best timings I got for hashing for data lengths of the following
numbers of 32-bit words, in seconds per 1,000,000,000 hashes, were:
words murmurhash Jenkins hash
----- ---------- ------------
1 8.4 10.4
2 10.3 10.3
3 11.2 10.7
4 12.6 18.0
5 13.9 18.3
6 15.2 18.7
In other words, murmurhash outperforms Jenkins for all input lengths other
than exactly 3 32-bit words (12 bytes). (It's understandable that Jenkins
would have a best case at 12 bytes, because Jenkins works in 12-byte
chunks.) Even in the case where Jenkins is faster, it's only by 5%. On
average within this data set, murmurhash is 15% faster, and for 4-word
input it is 30% faster.
We retain Jenkins for flow_hash_symmetric_l4() and flow_hash_fields(),
which are cases where the hash value is exposed externally.
This commit appears to improve "ovs-benchmark rate" results slightly by
a few hundred connections per second (under 1%), when used with an NVP
controller.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-01-16 16:14:42 -08:00
|
|
|
return jhash_words(&input, 1, 0);
|
2012-08-21 14:26:23 -07:00
|
|
|
}
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
static uint32_t
|
|
|
|
hash_int_cb(uint32_t input)
|
|
|
|
{
|
|
|
|
return hash_int(input, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_word_hash(uint32_t (*hash)(uint32_t), const char *name,
|
|
|
|
int min_unique)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i <= 32; i++) {
|
|
|
|
uint32_t in1 = i < 32 ? UINT32_C(1) << i : 0;
|
|
|
|
for (j = i + 1; j <= 32; j++) {
|
|
|
|
uint32_t in2 = j < 32 ? UINT32_C(1) << j : 0;
|
|
|
|
uint32_t out1 = hash(in1);
|
|
|
|
uint32_t out2 = hash(in2);
|
|
|
|
const uint32_t unique_mask = (UINT32_C(1) << min_unique) - 1;
|
|
|
|
int ofs;
|
|
|
|
for (ofs = 0; ofs < 32 - min_unique; ofs++) {
|
|
|
|
uint32_t bits1 = (out1 >> ofs) & unique_mask;
|
|
|
|
uint32_t bits2 = (out2 >> ofs) & unique_mask;
|
|
|
|
if (bits1 == bits2) {
|
|
|
|
printf("Partial collision for '%s':\n", name);
|
|
|
|
printf("%s(%08"PRIx32") = %08"PRIx32"\n", name, in1, out1);
|
|
|
|
printf("%s(%08"PRIx32") = %08"PRIx32"\n", name, in2, out2);
|
|
|
|
printf("%d bits of output starting at bit %d "
|
|
|
|
"are both 0x%"PRIx32"\n", min_unique, ofs, bits1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-21 14:26:23 -07:00
|
|
|
static void
|
|
|
|
check_3word_hash(uint32_t (*hash)(const uint32_t[], size_t, uint32_t),
|
|
|
|
const char *name)
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2012-08-21 14:26:23 -07:00
|
|
|
for (i = 0; i <= 96; i++) {
|
|
|
|
for (j = i + 1; j <= 96; j++) {
|
2014-07-11 05:57:11 -07:00
|
|
|
uint32_t in0[3], in1[3], in2[3];
|
|
|
|
uint32_t out0,out1, out2;
|
2012-08-21 14:26:23 -07:00
|
|
|
const int min_unique = 12;
|
|
|
|
const uint32_t unique_mask = (UINT32_C(1) << min_unique) - 1;
|
|
|
|
|
2014-07-11 05:57:11 -07:00
|
|
|
set_bit(in0, i);
|
2012-08-21 14:26:23 -07:00
|
|
|
set_bit(in1, i);
|
|
|
|
set_bit(in2, j);
|
2014-07-11 05:57:11 -07:00
|
|
|
out0 = hash(in0, 3, 0);
|
2012-08-21 14:26:23 -07:00
|
|
|
out1 = hash(in1, 3, 0);
|
|
|
|
out2 = hash(in2, 3, 0);
|
2014-07-11 05:57:11 -07:00
|
|
|
|
|
|
|
if (out0 != out1) {
|
|
|
|
printf("%s hash not the same for non-64 aligned data "
|
|
|
|
"%08"PRIx32" != %08"PRIx32"\n", name, out0, out1);
|
|
|
|
}
|
2012-08-21 14:26:23 -07:00
|
|
|
if ((out1 & unique_mask) == (out2 & unique_mask)) {
|
|
|
|
printf("%s has a partial collision:\n", name);
|
|
|
|
printf("hash(1 << %d) == %08"PRIx32"\n", i, out1);
|
|
|
|
printf("hash(1 << %d) == %08"PRIx32"\n", j, out2);
|
|
|
|
printf("The low-order %d bits of output are both "
|
|
|
|
"0x%"PRIx32"\n", min_unique, out1 & unique_mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 09:54:00 -08:00
|
|
|
static void
|
|
|
|
check_hash_bytes128(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *),
|
|
|
|
const char *name, const int min_unique)
|
|
|
|
{
|
|
|
|
const uint64_t unique_mask = (UINT64_C(1) << min_unique) - 1;
|
|
|
|
const int n_bits = sizeof(ovs_u128) * 8;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i <= n_bits; i++) {
|
|
|
|
OVS_PACKED(struct offset_ovs_u128 {
|
|
|
|
uint32_t a;
|
|
|
|
ovs_u128 b;
|
2017-05-26 14:11:31 -07:00
|
|
|
}) in0;
|
|
|
|
ovs_u128 in1;
|
2015-02-26 09:54:00 -08:00
|
|
|
ovs_u128 out0, out1;
|
|
|
|
|
|
|
|
set_bit128(&in1, i, n_bits);
|
2017-05-26 14:11:31 -07:00
|
|
|
in0.b = in1;
|
|
|
|
hash(&in0.b, sizeof(ovs_u128), 0, &out0);
|
2015-02-26 09:54:00 -08:00
|
|
|
hash(&in1, sizeof(ovs_u128), 0, &out1);
|
2016-05-03 18:20:51 -07:00
|
|
|
if (!ovs_u128_equals(out0, out1)) {
|
2015-02-26 09:54:00 -08:00
|
|
|
printf("%s hash not the same for non-64 aligned data "
|
|
|
|
"%016"PRIx64"%016"PRIx64" != %016"PRIx64"%016"PRIx64"\n",
|
|
|
|
name, out0.u64.lo, out0.u64.hi, out1.u64.lo, out1.u64.hi);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = i + 1; j <= n_bits; j++) {
|
|
|
|
ovs_u128 in2;
|
|
|
|
ovs_u128 out2;
|
|
|
|
int ofs;
|
|
|
|
|
|
|
|
set_bit128(&in2, j, n_bits);
|
|
|
|
hash(&in2, sizeof(ovs_u128), 0, &out2);
|
|
|
|
for (ofs = 0; ofs < 128 - min_unique; ofs++) {
|
|
|
|
uint64_t bits1 = get_range128(&out1, ofs, unique_mask);
|
|
|
|
uint64_t bits2 = get_range128(&out2, ofs, unique_mask);
|
|
|
|
|
|
|
|
if (bits1 == bits2) {
|
|
|
|
printf("%s has a partial collision:\n", name);
|
|
|
|
printf("hash(1 << %d) == %016"PRIx64"%016"PRIx64"\n",
|
|
|
|
i, out1.u64.hi, out1.u64.lo);
|
|
|
|
printf("hash(1 << %d) == %016"PRIx64"%016"PRIx64"\n",
|
|
|
|
j, out2.u64.hi, out2.u64.lo);
|
|
|
|
printf("%d bits of output starting at bit %d "
|
|
|
|
"are both 0x%016"PRIx64"\n", min_unique, ofs, bits1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-12 11:12:12 +12:00
|
|
|
static void
|
|
|
|
check_256byte_hash(void (*hash)(const void *, size_t, uint32_t, ovs_u128 *),
|
|
|
|
const char *name, const int min_unique)
|
|
|
|
{
|
|
|
|
const uint64_t unique_mask = (UINT64_C(1) << min_unique) - 1;
|
2015-02-26 09:54:00 -08:00
|
|
|
const int n_bits = sizeof(ovs_u128) * 8 * 16;
|
2014-08-12 11:12:12 +12:00
|
|
|
int i, j;
|
|
|
|
|
2015-02-25 15:08:51 -08:00
|
|
|
for (i = 0; i <= n_bits; i++) {
|
2015-02-25 16:12:23 -08:00
|
|
|
OVS_PACKED(struct offset_ovs_u128 {
|
|
|
|
uint32_t a;
|
|
|
|
ovs_u128 b[16];
|
2017-05-26 14:11:31 -07:00
|
|
|
}) in0;
|
|
|
|
ovs_u128 in1[16];
|
2015-02-25 16:12:23 -08:00
|
|
|
ovs_u128 out0, out1;
|
|
|
|
|
2015-02-26 09:54:00 -08:00
|
|
|
set_bit128(in1, i, n_bits);
|
2017-05-26 14:11:31 -07:00
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
in0.b[j] = in1[j];
|
|
|
|
}
|
|
|
|
hash(&in0.b, sizeof(ovs_u128) * 16, 0, &out0);
|
2015-02-25 16:12:23 -08:00
|
|
|
hash(in1, sizeof(ovs_u128) * 16, 0, &out1);
|
2016-05-03 18:20:51 -07:00
|
|
|
if (!ovs_u128_equals(out0, out1)) {
|
2015-02-25 16:12:23 -08:00
|
|
|
printf("%s hash not the same for non-64 aligned data "
|
|
|
|
"%016"PRIx64"%016"PRIx64" != %016"PRIx64"%016"PRIx64"\n",
|
|
|
|
name, out0.u64.lo, out0.u64.hi, out1.u64.lo, out1.u64.hi);
|
|
|
|
}
|
|
|
|
|
2015-02-25 15:08:51 -08:00
|
|
|
for (j = i + 1; j <= n_bits; j++) {
|
2015-02-25 16:12:23 -08:00
|
|
|
ovs_u128 in2[16];
|
|
|
|
ovs_u128 out2;
|
|
|
|
|
2015-02-26 09:54:00 -08:00
|
|
|
set_bit128(in2, j, n_bits);
|
2014-08-12 11:12:12 +12:00
|
|
|
hash(in2, sizeof(ovs_u128) * 16, 0, &out2);
|
|
|
|
if ((out1.u64.lo & unique_mask) == (out2.u64.lo & unique_mask)) {
|
|
|
|
printf("%s has a partial collision:\n", name);
|
|
|
|
printf("hash(1 << %4d) == %016"PRIx64"%016"PRIx64"\n", i,
|
|
|
|
out1.u64.hi, out1.u64.lo);
|
|
|
|
printf("hash(1 << %4d) == %016"PRIx64"%016"PRIx64"\n", j,
|
|
|
|
out2.u64.hi, out2.u64.lo);
|
|
|
|
printf("The low-order %d bits of output are both "
|
|
|
|
"0x%"PRIx64"\n", min_unique, out1.u64.lo & unique_mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 00:47:01 -07:00
|
|
|
static void
|
|
|
|
test_hash_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
|
2012-08-21 14:26:23 -07:00
|
|
|
{
|
2015-02-28 22:27:35 -08:00
|
|
|
/*
|
|
|
|
* The following tests check that all hashes computed with hash_function
|
|
|
|
* with one 1-bit (or no 1-bits) set within a X-bit word have different
|
|
|
|
* values in all N-bit consecutive comparisons.
|
|
|
|
*
|
|
|
|
* test_function(hash_function, test_name, N)
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
|
|
|
* Given a random distribution, the probability of at least one collision
|
2015-02-28 22:27:35 -08:00
|
|
|
* in any set of N bits is approximately
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2015-02-28 22:27:35 -08:00
|
|
|
* 1 - (prob of no collisions)
|
|
|
|
* **(combination of all possible comparisons)
|
|
|
|
* == 1 - ((2**N - 1)/2**N)**C(X+1,2)
|
|
|
|
* == p
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2015-02-28 22:27:35 -08:00
|
|
|
* There are (X-N) ways to pick N consecutive bits in a X-bit word, so if we
|
2009-07-08 13:19:16 -07:00
|
|
|
* assumed independence then the chance of having no collisions in any of
|
2015-02-28 22:27:35 -08:00
|
|
|
* those X-bit runs would be (1-p)**(X-N) == q. If this q is very small
|
|
|
|
* and we can also find a relatively small 'magic number' N such that there
|
|
|
|
* is no collision in any comparison, then it means we have a pretty good
|
|
|
|
* hash function.
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2015-02-28 22:27:35 -08:00
|
|
|
* The values of each parameters mentioned above for the tested hash
|
|
|
|
* functions are summarized as follow:
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2015-02-28 22:27:35 -08:00
|
|
|
* hash_function X N p q
|
|
|
|
* ------------- --- --- ------- -------
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2015-02-28 22:27:35 -08:00
|
|
|
* hash_words_cb 32 11 0.22 0.0044
|
|
|
|
* jhash_words_cb 32 11 0.22 0.0044
|
|
|
|
* hash_int_cb 32 12 0.12 0.0078
|
|
|
|
* hash_bytes128 128 19 0.0156 0.174
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
|
|
|
*/
|
2015-02-28 22:27:35 -08:00
|
|
|
check_word_hash(hash_words_cb, "hash_words", 11);
|
|
|
|
check_word_hash(jhash_words_cb, "jhash_words", 11);
|
hash: Replace primary hash functions by murmurhash.
murmurhash is faster than Jenkins and slightly higher quality, so switch to
it for hashing words.
The best timings I got for hashing for data lengths of the following
numbers of 32-bit words, in seconds per 1,000,000,000 hashes, were:
words murmurhash Jenkins hash
----- ---------- ------------
1 8.4 10.4
2 10.3 10.3
3 11.2 10.7
4 12.6 18.0
5 13.9 18.3
6 15.2 18.7
In other words, murmurhash outperforms Jenkins for all input lengths other
than exactly 3 32-bit words (12 bytes). (It's understandable that Jenkins
would have a best case at 12 bytes, because Jenkins works in 12-byte
chunks.) Even in the case where Jenkins is faster, it's only by 5%. On
average within this data set, murmurhash is 15% faster, and for 4-word
input it is 30% faster.
We retain Jenkins for flow_hash_symmetric_l4() and flow_hash_fields(),
which are cases where the hash value is exposed externally.
This commit appears to improve "ovs-benchmark rate" results slightly by
a few hundred connections per second (under 1%), when used with an NVP
controller.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-01-16 16:14:42 -08:00
|
|
|
check_word_hash(hash_int_cb, "hash_int", 12);
|
2015-02-28 22:27:35 -08:00
|
|
|
check_hash_bytes128(hash_bytes128, "hash_bytes128", 19);
|
2014-08-12 11:12:12 +12:00
|
|
|
|
2015-02-28 22:27:35 -08:00
|
|
|
/*
|
|
|
|
* The following tests check that all hashes computed with hash_function
|
|
|
|
* with one 1-bit (or no 1-bits) set within Y X-bit word have different
|
|
|
|
* values in their lowest N bits.
|
|
|
|
*
|
|
|
|
* test_function(hash_function, test_name, N)
|
2015-02-26 09:54:00 -08:00
|
|
|
*
|
|
|
|
* Given a random distribution, the probability of at least one collision
|
2015-02-28 22:27:35 -08:00
|
|
|
* in any set of N bits is approximately
|
2015-02-26 09:54:00 -08:00
|
|
|
*
|
2015-02-28 22:27:35 -08:00
|
|
|
* 1 - (prob of no collisions)
|
|
|
|
* **(combination of all possible comparisons)
|
|
|
|
* == 1 - ((2**N - 1)/2**N)**C(Y*X+1,2)
|
|
|
|
* == p
|
2015-02-26 09:54:00 -08:00
|
|
|
*
|
2015-02-28 22:27:35 -08:00
|
|
|
* If this p is not very small and we can also find a relatively small
|
|
|
|
* 'magic number' N such that there is no collision in any comparison,
|
|
|
|
* then it means we have a pretty good hash function.
|
2014-08-12 11:12:12 +12:00
|
|
|
*
|
2015-02-28 22:27:35 -08:00
|
|
|
* The values of each parameters mentioned above for the tested hash
|
|
|
|
* functions are summarized as follow:
|
2014-08-12 11:12:12 +12:00
|
|
|
*
|
2015-02-28 22:27:35 -08:00
|
|
|
* hash_function Y X N p
|
|
|
|
* ------------- --- --- --- -------
|
|
|
|
*
|
|
|
|
* hash_words 3 32 12 0.68
|
|
|
|
* jhash_words 3 32 12 0.68
|
|
|
|
* hash_bytes128 16 128 23 0.22
|
2014-08-12 11:12:12 +12:00
|
|
|
*
|
|
|
|
*/
|
2015-02-28 22:27:35 -08:00
|
|
|
check_3word_hash(hash_words, "hash_words");
|
|
|
|
check_3word_hash(jhash_words, "jhash_words");
|
2014-08-12 11:12:12 +12:00
|
|
|
check_256byte_hash(hash_bytes128, "hash_bytes128", 23);
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
2014-04-01 00:47:01 -07:00
|
|
|
|
|
|
|
OVSTEST_REGISTER("test-hash", test_hash_main);
|