annotate intl/hash-string.h @ 300:e35b0290f77c trunk

[svn] Squash 3 warnings by compiling as C99 code. Remove round_trick kludge.
author chainsaw
date Fri, 16 Dec 2005 18:25:18 -0800
parents cb178e5ad177
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* Description of GNU message catalog format: string hashing function.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 Copyright (C) 1995, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify it
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 under the terms of the GNU Library General Public License as published
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 by the Free Software Foundation; either version 2, or (at your option)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 Library General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 You should have received a copy of the GNU Library General Public
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 License along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 USA. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 /* @@ end of prolog @@ */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 #ifndef PARAMS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 # if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 # define PARAMS(Args) Args
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 # else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 # define PARAMS(Args) ()
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 # endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 /* We assume to have `unsigned long int' value with at least 32 bits. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 #define HASHWORDBITS 32
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 /* Defines the so called `hashpjw' function by P.J. Weinberger
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 1986, 1987 Bell Telephone Laboratories, Inc.] */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 static unsigned long int hash_string PARAMS ((const char *__str_param));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 static inline unsigned long int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 hash_string (str_param)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 const char *str_param;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 unsigned long int hval, g;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 const char *str = str_param;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 /* Compute the hash value for the given string. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 hval = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 while (*str != '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 hval <<= 4;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 hval += (unsigned long int) *str++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 g = hval & ((unsigned long int) 0xf << (HASHWORDBITS - 4));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 if (g != 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 hval ^= g >> (HASHWORDBITS - 8);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 hval ^= g;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 return hval;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 }