annotate src/hash.c @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents 8eaf7971accc
children f955c73f5258
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Hash tables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #define NULL_ENTRY (LISP_TO_VOID (Qnil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #else /* !emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #define NULL_ENTRY ((void *) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #endif /* !emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include "hash.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include "elhash.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
38 static CONST int
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 primes []={
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 13,
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
41 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631,
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
42 761, 919, 1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013,
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
43 8419, 10103, 12143, 14591, 17519, 21023, 25229, 30293, 36353, 43627, 52361,
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
44 62851, 75431, 90523, 108631, 130363, 156437, 187751, 225307, 270371, 324449,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263, 1674319,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 2009191, 2411033, 2893249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 /* strings code */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 /* from base/generic-hash.cc, and hence from Dragon book, p436 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 string_hash (CONST void *xv)
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
54 {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 unsigned int h = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 unsigned int g;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 unsigned CONST char *x = (unsigned CONST char *) xv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 if (!x) return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 while (*x != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 h = (h << 4) + *x++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 if ((g = h & 0xf0000000) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 h = (h ^ (g >> 24)) ^ g;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 return h;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 memory_hash (CONST void *xv, int size)
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
73 {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 unsigned int h = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 unsigned int g;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 unsigned CONST char *x = (unsigned CONST char *) xv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 if (!x) return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 while (size > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 h = (h << 4) + *x++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 if ((g = h & 0xf0000000) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 h = (h ^ (g >> 24)) ^ g;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 size--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 return h;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
91 static int
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
92 string_eq (CONST void *st1, CONST void *st2)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 if (!st1)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
95 return st2 ? 0 : 1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 else if (!st2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 else
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
99 return !strcmp ( (CONST char *) st1, (CONST char *) st2);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
103 static unsigned int
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 prime_size (unsigned int size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 unsigned int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 CONST int lim = countof (primes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 for (i = 0; i < lim; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 if (size <= primes [i]) return primes [i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 return primes [lim - 1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 static void rehash (hentry *harray, c_hashtable ht, unsigned int size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 #define KEYS_DIFFER_P(old, new, testfun) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ((testfun)?(((old) == (new))?0:(!(testfun ((old), new)))):((old) != (new)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 CONST void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 gethash (CONST void *key, c_hashtable hash, CONST void **ret_value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 hentry *harray = hash->harray;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 int (*test_function) (CONST void *, CONST void *) = hash->test_function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 unsigned int hsize = hash->size;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
124 unsigned int hcode_initial =
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (hash->hash_function)?(hash->hash_function(key)):((unsigned long) key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 unsigned int hcode = hcode_initial % hsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 hentry *e = &harray [hcode];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 CONST void *e_key = e->key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
130 if (!key)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 *ret_value = hash->zero_entry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 return (void *) hash->zero_set;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
135
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 if ((e_key)?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (KEYS_DIFFER_P (e_key, key, test_function)):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (e->contents == NULL_ENTRY))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 unsigned int h2 = hsize - 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 unsigned int incr = 1 + (hcode_initial % h2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 hcode = hcode + incr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 if (hcode >= hsize) hcode = hcode - hsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 e = &harray [hcode];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 e_key = e->key;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
148 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 while ((e_key)?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (KEYS_DIFFER_P (e_key, key, test_function)):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (e->contents == NULL_ENTRY));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 *ret_value = e->contents;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 return e->key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
158 void
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 clrhash (c_hashtable hash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 memset (hash->harray, 0, sizeof (hentry) * hash->size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 hash->zero_entry = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 hash->zero_set = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 hash->fullness = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 free_hashtable (c_hashtable hash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 if (!NILP (hash->elisp_table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 xfree (hash->harray);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 xfree (hash);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 c_hashtable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 make_hashtable (unsigned int hsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
181 c_hashtable res = xnew_and_zero (struct _C_hashtable);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 res->size = prime_size ((13 * hsize) / 10);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
183 res->harray = xnew_array (hentry, res->size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 res->elisp_table = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 clrhash (res);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 return res;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 c_hashtable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 make_general_hashtable (unsigned int hsize,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 unsigned long (*hash_function) (CONST void *),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 int (*test_function) (CONST void *, CONST void *))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
196 c_hashtable res = xnew_and_zero (struct _C_hashtable);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 res->size = prime_size ((13 * hsize) / 10);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
198 res->harray = xnew_array (hentry, res->size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 res->hash_function = hash_function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 res->test_function = test_function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 res->elisp_table = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 clrhash (res);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 return res;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
208 c_hashtable
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 make_strings_hashtable (unsigned int hsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 return make_general_hashtable (hsize, string_hash, string_eq);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 unsigned int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 compute_harray_size (unsigned int hsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 return prime_size ((13 * hsize) / 10);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 copy_hash (c_hashtable dest, c_hashtable src)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 /* if these are not the same, then we are losing here */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 if ((NILP (dest->elisp_table)) != (NILP (src->elisp_table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 error ("Incompatible hashtable types to copy_hash.");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 if (dest->size != src->size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 if (!NILP (dest->elisp_table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 elisp_hvector_free (dest->harray, dest->elisp_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 xfree (dest->harray);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 dest->size = src->size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 if (!NILP (dest->elisp_table))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
246 dest->harray = (hentry *)
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
247 elisp_hvector_malloc (sizeof (hentry) * dest->size,
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
248 dest->elisp_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 #endif
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
251 dest->harray = xnew_array (hentry, dest->size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 dest->fullness = src->fullness;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 dest->zero_entry = src->zero_entry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 dest->zero_set = src->zero_set;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 dest->hash_function = src->hash_function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 dest->test_function = src->test_function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 memcpy (dest->harray, src->harray, sizeof (hentry) * dest->size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
260
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 grow_hashtable (c_hashtable hash, unsigned int new_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 unsigned int old_hsize = hash->size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 hentry *old_harray = hash->harray;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 unsigned int new_hsize = prime_size (new_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 hentry *new_harray;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 /* We test for Qzero to facilitate free-hook.c. That module creates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 a hashtable very very early, at which point Qnil has not yet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 been set and is thus all zeroes. Qzero is "automatically"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 initialized at startup because its correct value is also all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 zeroes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 if (!NILP (hash->elisp_table) && !ZEROP (hash->elisp_table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 new_harray = (hentry *) elisp_hvector_malloc (sizeof (hentry) * new_hsize,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 hash->elisp_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 #endif
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
280 new_harray = (hentry *) xmalloc (sizeof (hentry) * new_hsize);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 hash->size = new_hsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 hash->harray = new_harray;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 /* do the rehash on the "grown" table */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 long old_zero_set = hash->zero_set;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 void *old_zero_entry = hash->zero_entry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 clrhash (hash);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 hash->zero_set = old_zero_set;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 hash->zero_entry = old_zero_entry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 rehash (old_harray, hash, old_hsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 if (!NILP (hash->elisp_table) && !ZEROP (hash->elisp_table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 elisp_hvector_free (old_harray, hash->elisp_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 xfree (old_harray);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 expand_hashtable (c_hashtable hash, unsigned int needed_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 unsigned int hsize = hash->size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 int comfortable_size = (13 * needed_size) / 10;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 if (hsize < comfortable_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 grow_hashtable (hash, comfortable_size + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
312 void
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 puthash (CONST void *key, void *cont, c_hashtable hash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 unsigned int hsize = hash->size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 int (*test_function) (CONST void *, CONST void *) = hash->test_function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 unsigned int fullness = hash->fullness;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 hentry *harray;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 CONST void *e_key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 hentry *e;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
321 unsigned int hcode_initial =
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (hash->hash_function)?(hash->hash_function(key)):((unsigned long) key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 unsigned int hcode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 unsigned int incr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 unsigned int h2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 CONST void *oldcontents;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
328 if (!key)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
330 hash->zero_entry = cont;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 hash->zero_set = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 if (hsize < (1 + ((13 * fullness) / 10)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 grow_hashtable (hash, hsize + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 hsize = hash->size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 fullness = hash->fullness;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 harray= hash->harray;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 h2 = hsize - 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 hcode = hcode_initial % hsize;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
346
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 e_key = harray [hcode].key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 if (e_key && (KEYS_DIFFER_P (e_key, key, test_function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 h2 = hsize - 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 incr = 1 + (hcode_initial % h2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 hcode = hcode + incr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 if (hcode >= hsize) hcode = hcode - hsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 e_key = harray [hcode].key;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
357 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 while (e_key && (KEYS_DIFFER_P (e_key, key, test_function)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 oldcontents = harray [hcode].contents;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 harray [hcode].key = key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 harray [hcode].contents = cont;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 /* if the entry that we used was a deleted entry,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 check for a non deleted entry of the same key,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 then delete it */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 if (!e_key && (oldcontents == NULL_ENTRY))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 if (!incr) incr = 1 + ((unsigned long) key % h2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 hcode = hcode + incr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 if (hcode >= hsize) hcode = hcode - hsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 e = &harray [hcode];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 e_key = e->key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 while ((e_key)?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (KEYS_DIFFER_P (e_key, key, test_function)):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (e->contents == NULL_ENTRY));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 if (e_key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 e->key = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 e->contents = NULL_ENTRY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 /* only increment the fullness when we used up a new hentry */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 if (!e_key || (KEYS_DIFFER_P (e_key, key, test_function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 hash->fullness++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 rehash (hentry *harray, c_hashtable hash, unsigned int size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 hentry *limit = harray + size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 hentry *e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 for (e = harray; e < limit; e++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 if (e->key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 puthash (e->key, e->contents, hash);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
405 void
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 remhash (CONST void *key, c_hashtable hash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 hentry *harray = hash->harray;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 int (*test_function) (CONST void*, CONST void*) = hash->test_function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 unsigned int hsize = hash->size;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
411 unsigned int hcode_initial =
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (hash->hash_function)?(hash->hash_function(key)):((unsigned long) key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 unsigned int hcode = hcode_initial % hsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 hentry *e = &harray [hcode];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 CONST void *e_key = e->key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
417 if (!key)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 hash->zero_entry = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 hash->zero_set = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 if ((e_key)?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (KEYS_DIFFER_P (e_key, key, test_function)):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (e->contents == NULL_ENTRY))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 unsigned int h2 = hsize - 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 unsigned int incr = 1 + (hcode_initial % h2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 hcode = hcode + incr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 if (hcode >= hsize) hcode = hcode - hsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 e = &harray [hcode];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 e_key = e->key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 while ((e_key)?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (KEYS_DIFFER_P (e_key, key, test_function)):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (e->contents == NULL_ENTRY));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 if (e_key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 e->key = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 e->contents = NULL_ENTRY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 /* Note: you can't do fullness-- here, it breaks the world. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
449 void
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 maphash (maphash_function mf, c_hashtable hash, void *arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 hentry *e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 hentry *limit;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
454
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
455 if (hash->zero_set)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ((*mf) (0, hash->zero_entry, arg));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 for (e = hash->harray, limit = e + hash->size; e < limit; e++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 if (e->key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 ((*mf) (e->key, e->contents, arg));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
465 void
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 map_remhash (remhash_predicate predicate, c_hashtable hash, void *arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 hentry *e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 hentry *limit;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
470
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 if (hash->zero_set && ((*predicate) (0, hash->zero_entry, arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 hash->zero_set = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 hash->zero_entry = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 for (e = hash->harray, limit = e + hash->size; e < limit; e++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 if ((*predicate) (e->key, e->contents, arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 e->key = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 e->contents = NULL_ENTRY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 }