--- libaitcrc/src/hash.c 2012/07/04 14:53:43 1.3 +++ libaitcrc/src/hash.c 2012/08/29 09:00:44 1.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: hash.c,v 1.3 2012/07/04 14:53:43 misho Exp $ +* $Id: hash.c,v 1.4 2012/08/29 09:00:44 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -181,4 +181,45 @@ hash_reddragon(const char *csStr, int nStrLen) } return hash; +} + +/* + * hash_jenkins32() - Fast Jenkins hash function + * + * @buf = Input buffer + * @len = Length of buffer + * @prevhash = Previous hash, if participate in continuing hash + * return: Hash value + */ +u_int +hash_jenkins32(const u_int *buf, int len, u_int prevhash) +{ + register u_int a, b, c; + + assert(buf); + + a = b = c = INIT_JENKINS32 + (((u_int) len) << 2) + prevhash; + + while (len > 3) { + a += buf[0]; + b += buf[1]; + c += buf[2]; + MIX32(a, b, c); + len -= 3; + buf += 3; + } + + switch (len) { + case 3: + c += buf[2]; + case 2: + b += buf[1]; + case 1: + a += buf[0]; + FINAL32(a, b, c); + case 0: + break; + } + + return c; }