From: Simon Wilkinson Date: Mon, 29 Oct 2012 19:02:03 +0000 (+0000) Subject: opr: Add opr_jhash_int2 function X-Git-Tag: openafs-stable-1_8_0pre1~1844 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=07372cf7e76acf62eb26908977e2682338c85ac1;hp=dce5e012fedb3efc9e7acd9c443b7ec2caaf47ae 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 Change-Id: I594848f64316fb459eff565933691f560512ca79 Reviewed-on: http://gerrit.openafs.org/8354 Reviewed-by: Jeffrey Altman Reviewed-by: Derrick Brashear Tested-by: BuildBot --- diff --git a/src/opr/jhash.h b/src/opr/jhash.h index 6e9bc79..5c6e3ad 100644 --- a/src/opr/jhash.h +++ b/src/opr/jhash.h @@ -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) { diff --git a/tests/opr/jhash-t.c b/tests/opr/jhash-t.c index c17a7fb..707cd06 100644 --- a/tests/opr/jhash-t.c +++ b/tests/opr/jhash-t.c @@ -39,7 +39,7 @@ int main(int argc, char **argv) { - plan(11); + plan(13); uint32_t test[] = {3526055646UL, 2064483663UL, 3234460805UL, 3963629775UL}; is_int(256, opr_jhash_size(8), "opr_jhash_size 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");