2 This file is part of SXEmacs
4 SXEmacs 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 3 of the License, or
7 (at your option) any later version.
9 SXEmacs 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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Synched up with: Not in FSF. */
20 #ifndef INCLUDED_hash_h_
21 #define INCLUDED_hash_h_
28 typedef int (*hash_table_test_function) (const void *, const void *);
29 typedef unsigned long (*hash_table_hash_function) (const void *);
30 typedef size_t hash_size_t;
36 hash_size_t size; /* size of the hasharray */
37 hash_size_t fullness; /* number of entries in the hash table */
38 hash_table_hash_function hash_function;
39 hash_table_test_function test_function;
42 /* SIZE is the number of initial entries. The hash table will be grown
43 automatically if the number of entries approaches the size */
44 struct hash_table *make_hash_table(hash_size_t size);
46 struct hash_table *make_general_hash_table(hash_size_t size,
47 hash_table_hash_function
49 hash_table_test_function
52 /* Clear HASH-TABLE. A freshly created hash table is already cleared up. */
53 void clrhash(struct hash_table *hash_table);
55 /* Free HASH-TABLE and its substructures */
56 void free_hash_table(struct hash_table *hash_table);
58 /* Returns a chentry whose key is 0 if the entry does not exist in HASH-TABLE */
59 const void *gethash(const void *key, struct hash_table *hash_table,
60 const void **ret_value);
62 /* KEY should be different from 0 */
63 void puthash(const void *key, void *contents, struct hash_table *hash_table);
65 /* delete the entry with key KEY */
66 void remhash(const void *key, struct hash_table *hash_table);
68 typedef int (*maphash_function) (const void *key, void *contents, void *arg);
70 typedef int (*remhash_predicate) (const void *key, const void *contents,
73 /* Call MF (key, contents, arg) for every entry in HASH-TABLE */
74 void maphash(maphash_function mf, struct hash_table *hash_table, void *arg);
76 /* Delete all objects from HASH-TABLE satisfying PREDICATE */
77 void map_remhash(remhash_predicate predicate,
78 struct hash_table *hash_table, void *arg);
80 #endif /* INCLUDED_hash_h_ */