From: Ted Lemon Date: Sat, 24 Jun 2000 06:19:13 +0000 (+0000) Subject: Make the hash functions work usefully for hash table sizes >255. X-Git-Tag: V3-BETA-2-PATCH-1~126 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5ef29468a1f410750d60ae5505911c32aa1f4eb;p=thirdparty%2Fdhcp.git Make the hash functions work usefully for hash table sizes >255. --- diff --git a/common/hash.c b/common/hash.c index 0588a150e..371b0e03f 100644 --- a/common/hash.c +++ b/common/hash.c @@ -43,7 +43,7 @@ #ifndef lint static char copyright[] = -"$Id: hash.c,v 1.24 2000/06/06 23:46:31 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n"; +"$Id: hash.c,v 1.25 2000/06/24 06:19:13 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -90,10 +90,11 @@ static int do_case_hash (name, len, size) c = tolower (c); /* Add the character in... */ - accum += c; + accum = (accum << 1) + c; + /* Add carry back in... */ - while (accum > 255) { - accum = (accum & 255) + (accum >> 8); + while (accum > 65535) { + accum = (accum & 65535) + (accum >> 16); } } return accum % size; @@ -110,10 +111,11 @@ static int do_hash (name, len, size) while (i--) { /* Add the character in... */ - accum += *s++; + accum = (accum << 1) + *s++; + /* Add carry back in... */ - while (accum > 255) { - accum = (accum & 255) + (accum >> 8); + while (accum > 65535) { + accum = (accum & 65535) + (accum >> 16); } } return accum % size;