X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fhash.c;h=f85bd519bf5a1d259de8dfb22fdff73df7c1b2d3;hb=1b85e216d2ceb6d219d509b0471242d5b3dd88eb;hp=19e593fef42f04dc106adcdb68255f3964154f7b;hpb=0c0be7e546a53f280dfedc98099cf82b6d316e8d;p=gnulib.git diff --git a/lib/hash.c b/lib/hash.c index 19e593fef..f85bd519b 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -1,7 +1,7 @@ /* hash - hashing table processing. - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software - Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free + Software Foundation, Inc. Written by Jim Meyering, 1992. @@ -17,18 +17,19 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* A generic hash table package. */ /* Define USE_OBSTACK to 1 if you want the allocator to use obstacks instead of malloc. If you change USE_OBSTACK, you have to recompile! */ -#if HAVE_CONFIG_H +#ifdef HAVE_CONFIG_H # include #endif #include "hash.h" +#include "xalloc.h" #include #include @@ -399,9 +400,10 @@ hash_string (const char *string, size_t n_buckets) ((Byte) + ROTATE_LEFT (Value, 7)) size_t value = 0; + unsigned char ch; - for (; *string; string++) - value = HASH_ONE_CHAR (value, (unsigned char) *string); + for (; (ch = *string); string++) + value = HASH_ONE_CHAR (value, ch); return value % n_buckets; # undef ROTATE_LEFT @@ -419,9 +421,10 @@ size_t hash_string (const char *string, size_t n_buckets) { size_t value = 0; + unsigned char ch; - while (*string) - value = (value * 31 + (unsigned char) *string++) % n_buckets; + for (; (ch = *string); string++) + value = (value * 31 + ch) % n_buckets; return value; }