mirror of
https://github.com/coreutils/coreutils.git
synced 2025-01-19 14:33:22 +08:00
(hash_string): Rewrite to avoid cast.
This commit is contained in:
parent
28730b8b36
commit
d5905bb653
14
lib/hash.c
14
lib/hash.c
@ -1,7 +1,7 @@
|
|||||||
/* hash - hashing table processing.
|
/* hash - hashing table processing.
|
||||||
|
|
||||||
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software
|
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free
|
||||||
Foundation, Inc.
|
Software Foundation, Inc.
|
||||||
|
|
||||||
Written by Jim Meyering, 1992.
|
Written by Jim Meyering, 1992.
|
||||||
|
|
||||||
@ -400,9 +400,10 @@ hash_string (const char *string, size_t n_buckets)
|
|||||||
((Byte) + ROTATE_LEFT (Value, 7))
|
((Byte) + ROTATE_LEFT (Value, 7))
|
||||||
|
|
||||||
size_t value = 0;
|
size_t value = 0;
|
||||||
|
unsigned char ch;
|
||||||
|
|
||||||
for (; *string; string++)
|
for (; (ch = *string); string++)
|
||||||
value = HASH_ONE_CHAR (value, (unsigned char) *string);
|
value = HASH_ONE_CHAR (value, ch);
|
||||||
return value % n_buckets;
|
return value % n_buckets;
|
||||||
|
|
||||||
# undef ROTATE_LEFT
|
# undef ROTATE_LEFT
|
||||||
@ -420,9 +421,10 @@ size_t
|
|||||||
hash_string (const char *string, size_t n_buckets)
|
hash_string (const char *string, size_t n_buckets)
|
||||||
{
|
{
|
||||||
size_t value = 0;
|
size_t value = 0;
|
||||||
|
unsigned char ch;
|
||||||
|
|
||||||
while (*string)
|
for (; (ch = *string); string++)
|
||||||
value = (value * 31 + (unsigned char) *string++) % n_buckets;
|
value = (value * 31 + ch) % n_buckets;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user