opr: Add opr_jhash_int2 function

Add a function to jhash that can be used to hash a pair of unsigned
integers (or other stuff that can cast to them) without having to build
up an array.

Provide a couple of tests for the new function

Reviewed-on: http://gerrit.openafs.org/8354
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
(cherry picked from commit 07372cf7e7)

Change-Id: I944d8308dbda1cf1989b1d8497486f8463d1aacb
Reviewed-on: http://gerrit.openafs.org/10630
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
This commit is contained in:
Simon Wilkinson 2012-10-29 19:02:03 +00:00 committed by Jeffrey Altman
parent 6ead1f600d
commit 19b1c4f922
2 changed files with 22 additions and 2 deletions

View File

@ -103,6 +103,21 @@ opr_jhash_int(afs_uint32 a, afs_uint32 initval) {
return c;
}
/* and one to do two ints */
static_inline afs_uint32
opr_jhash_int2(afs_uint32 a, afs_uint32 b, afs_uint32 initval)
{
afs_uint32 c;
a += 0xdeadbeef + 8 + initval;
b += 0xdeadbeef + 8 + initval;
c = 0xdeadbeef + 8 + initval;
opr_jhash_final(a, b, c);
return c;
}
static_inline afs_uint32
opr_jhash_opaque(const void *val, size_t length, afs_uint32 initval)
{

View File

@ -39,8 +39,8 @@
int
main(int argc, char **argv)
{
plan(11);
uint32_t test[] = {3526055646, 2064483663, 3234460805, 3963629775};
plan(13);
uint32_t test[] = {3526055646UL, 2064483663UL, 3234460805UL, 3963629775UL};
is_int(256, opr_jhash_size(8), "opr_jhash_size returns expected value");
is_int(255, opr_jhash_mask(8), "opr_jhash_mask returns expected value");
@ -57,6 +57,11 @@ main(int argc, char **argv)
is_int(1100796964, opr_jhash_int(test[0], 0),
"single value works through jhash_int");
is_int(3704403432, opr_jhash(test, 2, 0),
"Hashing two values works");
is_int(3704403432, opr_jhash_int2(test[0], test[1], 0),
"jhash_int2 gives same result");
is_int(0xdeadbeef, opr_jhash_opaque("", 0, 0),
"Hashing an empty string works");