Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/hash-pjw.c @ 6170:a10e4460ad4c
* lib/regex_internal.h (re_sub_match_top_t): Remove unused member
next_last_offset.
(struct re_dfa_t): Remove unused member states_alloc.
* lib/regcomp.c (init_dfa): Don't initialize unused members.
* config/srclist.txt: Add glibc bug 1273.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 31 Aug 2005 18:08:34 +0000 |
parents | a48fb0e98c8c |
children | 96c32553b4c6 |
rev | line source |
---|---|
3541 | 1 /* hash-pjw.c -- compute a hash value from a NUL-terminated string. |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
2 Copyright (C) 2001, 2003 Free Software Foundation, Inc. |
3541 | 3 |
4 This program is free software; you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 2, or (at your option) | |
7 any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program; if not, write to the Free Software Foundation, | |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
4813
diff
changeset
|
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
3541 | 17 |
18 #if HAVE_CONFIG_H | |
19 # include <config.h> | |
20 #endif | |
21 | |
22 #include "hash-pjw.h" | |
23 | |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
24 #include <limits.h> |
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
25 |
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
26 #define SIZE_BITS (sizeof (size_t) * CHAR_BIT) |
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
27 |
3541 | 28 /* A hash function for NUL-terminated char* strings using |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
29 the method described by Bruno Haible. |
4177
6a34d03dc4e3
Add comment about low quality of this function.
Bruno Haible <bruno@clisp.org>
parents:
3541
diff
changeset
|
30 See http://www.haible.de/bruno/hashfunc.html. */ |
3541 | 31 |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
32 size_t |
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
33 hash_pjw (const void *x, size_t tablesize) |
3541 | 34 { |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
35 const char *s; |
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
36 size_t h = 0; |
3541 | 37 |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
38 for (s = x; *s; s++) |
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
39 h = *s + ((h << 9) | (h >> (SIZE_BITS - 9))); |
3541 | 40 |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4177
diff
changeset
|
41 return h % tablesize; |
3541 | 42 } |