Mercurial > hg > xemacs-beta
diff 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 |
line wrap: on
line diff
--- a/src/hash.c Wed Jan 26 10:09:20 2005 +0000 +++ b/src/hash.c Wed Jan 26 10:22:29 2005 +0000 @@ -1,6 +1,6 @@ /* Hash tables. Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. - Copyright (C) 2003 Ben Wing. + Copyright (C) 2003, 2004 Ben Wing. This file is part of XEmacs. @@ -56,8 +56,19 @@ return h; } -Hashcode -string_hash (const char *xv) +static int +string_equal (const void *st1, const void *st2) +{ + if (!st1) + return st2 ? 0 : 1; + else if (!st2) + return 0; + else + return !strcmp ((const char *) st1, (const char *) st2); +} + +static Hashcode +string_hash (const void *xv) { Hashcode h = 0; unsigned const char *x = (unsigned const char *) xv; @@ -167,7 +178,7 @@ xfree (hash_table, struct hash_table *); } -struct hash_table* +struct hash_table * make_hash_table (Elemcount size) { struct hash_table *hash_table = xnew_and_zero (struct hash_table); @@ -178,6 +189,12 @@ } struct hash_table * +make_string_hash_table (Elemcount size) +{ + return make_general_hash_table (size, string_hash, string_equal); +} + +struct hash_table * make_general_hash_table (Elemcount size, hash_table_hash_function hash_function, hash_table_test_function test_function)