Mercurial > hg > xemacs-beta
comparison src/hash.c @ 2515:de9952d2ed18
[xemacs-hg @ 2005-01-26 10:22:19 by ben]
Hash table cleanups, part 1 of 2
emacs-marshals.c, hash.c, hash.h, ui-gtk.c: Clean up and generalize creation of string hash tables.
ui-gtk.c, elhash.h, gccache-gtk.c, glyphs-gtk.c, lrecord.h, marker.c, objects-gtk.c, objects-msw.c, objects-tty.c, objects-x.c, objects.c, opaque.c, rangetab.c, specifier.c, specifier.h, xgccache.c: Use Hashcode rather than unsigned long.
author | ben |
---|---|
date | Wed, 26 Jan 2005 10:22:29 +0000 |
parents | a8d8f419b459 |
children | facf3239ba30 |
comparison
equal
deleted
inserted
replaced
2514:b49d38bc659d | 2515:de9952d2ed18 |
---|---|
1 /* Hash tables. | 1 /* Hash tables. |
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. | 2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. |
3 Copyright (C) 2003 Ben Wing. | 3 Copyright (C) 2003, 2004 Ben Wing. |
4 | 4 |
5 This file is part of XEmacs. | 5 This file is part of XEmacs. |
6 | 6 |
7 XEmacs is free software; you can redistribute it and/or modify it | 7 XEmacs is free software; you can redistribute it and/or modify it |
8 under the terms of the GNU General Public License as published by the | 8 under the terms of the GNU General Public License as published by the |
54 } | 54 } |
55 | 55 |
56 return h; | 56 return h; |
57 } | 57 } |
58 | 58 |
59 Hashcode | 59 static int |
60 string_hash (const char *xv) | 60 string_equal (const void *st1, const void *st2) |
61 { | |
62 if (!st1) | |
63 return st2 ? 0 : 1; | |
64 else if (!st2) | |
65 return 0; | |
66 else | |
67 return !strcmp ((const char *) st1, (const char *) st2); | |
68 } | |
69 | |
70 static Hashcode | |
71 string_hash (const void *xv) | |
61 { | 72 { |
62 Hashcode h = 0; | 73 Hashcode h = 0; |
63 unsigned const char *x = (unsigned const char *) xv; | 74 unsigned const char *x = (unsigned const char *) xv; |
64 | 75 |
65 if (!x) return 0; | 76 if (!x) return 0; |
165 { | 176 { |
166 xfree (hash_table->harray, hentry *); | 177 xfree (hash_table->harray, hentry *); |
167 xfree (hash_table, struct hash_table *); | 178 xfree (hash_table, struct hash_table *); |
168 } | 179 } |
169 | 180 |
170 struct hash_table* | 181 struct hash_table * |
171 make_hash_table (Elemcount size) | 182 make_hash_table (Elemcount size) |
172 { | 183 { |
173 struct hash_table *hash_table = xnew_and_zero (struct hash_table); | 184 struct hash_table *hash_table = xnew_and_zero (struct hash_table); |
174 hash_table->size = hash_table_size (COMFORTABLE_SIZE (size)); | 185 hash_table->size = hash_table_size (COMFORTABLE_SIZE (size)); |
175 hash_table->harray = xnew_array (hentry, hash_table->size); | 186 hash_table->harray = xnew_array (hentry, hash_table->size); |
176 clrhash (hash_table); | 187 clrhash (hash_table); |
177 return hash_table; | 188 return hash_table; |
189 } | |
190 | |
191 struct hash_table * | |
192 make_string_hash_table (Elemcount size) | |
193 { | |
194 return make_general_hash_table (size, string_hash, string_equal); | |
178 } | 195 } |
179 | 196 |
180 struct hash_table * | 197 struct hash_table * |
181 make_general_hash_table (Elemcount size, | 198 make_general_hash_table (Elemcount size, |
182 hash_table_hash_function hash_function, | 199 hash_table_hash_function hash_function, |