projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix indentation.
[gnulib.git]
/
lib
/
hash.c
diff --git
a/lib/hash.c
b/lib/hash.c
index
ad4599e
..
f4ab12f
100644
(file)
--- a/
lib/hash.c
+++ b/
lib/hash.c
@@
-1,7
+1,7
@@
/* hash - hashing table processing.
/* hash - hashing table processing.
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
Free Softwar
e
- Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
, 2004, 2006 Fre
e
+
Software
Foundation, Inc.
Written by Jim Meyering, 1992.
Written by Jim Meyering, 1992.
@@
-17,18
+17,17
@@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
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., 5
9 Temple Place - Suite 330, Boston, MA 02111-1307
, USA. */
+ Inc., 5
1 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! */
/* 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
-# include <config.h>
-#endif
+#include <config.h>
#include "hash.h"
#include "hash.h"
+#include "xalloc.h"
#include <limits.h>
#include <stdio.h>
#include <limits.h>
#include <stdio.h>
@@
-399,9
+398,10
@@
hash_string (const char *string, size_t n_buckets)
((Byte) + ROTATE_LEFT (Value, 7))
size_t value = 0;
((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
return value % n_buckets;
# undef ROTATE_LEFT
@@
-419,9
+419,10
@@
size_t
hash_string (const char *string, size_t n_buckets)
{
size_t value = 0;
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;
}
return value;
}
@@
-568,10
+569,10
@@
hash_initialize (size_t candidate, const Hash_tuning *tuning,
candidate = new_candidate;
}
candidate = new_candidate;
}
- if (
SIZE_MAX / sizeof *table->bucket < candidate
)
+ if (
xalloc_oversized (candidate, sizeof *table->bucket)
)
goto fail;
table->n_buckets = next_prime (candidate);
goto fail;
table->n_buckets = next_prime (candidate);
- if (
SIZE_MAX / sizeof *table->bucket < table->n_buckets
)
+ if (
xalloc_oversized (table->n_buckets, sizeof *table->bucket)
)
goto fail;
table->bucket = calloc (table->n_buckets, sizeof *table->bucket);
goto fail;
table->bucket = calloc (table->n_buckets, sizeof *table->bucket);