From: Willy Tarreau Date: Fri, 6 Mar 2026 18:14:06 +0000 (+0100) Subject: MINOR: tools: add a new pointer hash function that also takes an argument X-Git-Tag: v3.4-dev7~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b4275b0724479717af9efcf254604d21b3ef766;p=thirdparty%2Fhaproxy.git MINOR: tools: add a new pointer hash function that also takes an argument The purpose here is to combine two pointers and a long argument instead of having the caller perform the mixing. Also it's cleaner and more efficient this was as the arg is mixed after the multiplications, and modern processors are efficient at multiplying then adding. --- diff --git a/include/haproxy/tools.h b/include/haproxy/tools.h index 7b876f49b..2e266621d 100644 --- a/include/haproxy/tools.h +++ b/include/haproxy/tools.h @@ -1368,6 +1368,18 @@ static forceinline ullong _ptr2_hash(const void *p1, const void *p2) return x ^ y; } +/* two-pointer plus arg version, low-level, use ptr2_hash_arg() instead */ +static forceinline ullong _ptr2_hash_arg(const void *p1, const void *p2, ulong arg) +{ + unsigned long long x = (unsigned long)p1; + unsigned long long y = (unsigned long)p2; + + x *= 0xacd1be85U; + x += arg; + y *= 0x9d28e4e9U; + return x ^ y; +} + /* returns a hash on bits of pointer

that is suitable for being used * to compute statistic buckets, in that it's fast and reasonably distributed * thanks to mixing the bits via a multiplication by a prime number and using @@ -1392,6 +1404,14 @@ static forceinline uint ptr2_hash(const void *p1, const void *p2, const int bits return _ptr_hash_reduce(_ptr2_hash(p1, p2), bits); } +/* Same as above but works on two pointers and a long argument. It will return + * the same values if the second pointer is NULL. + */ +static forceinline uint ptr2_hash_arg(const void *p1, const void *p2, ulong arg, const int bits) +{ + return _ptr_hash_reduce(_ptr2_hash_arg(p1, p2, arg), bits); +} + /* Update array with the character transition to . If * is zero, it's assumed that is the first character. If is zero