Partially sync files.el from XEmacs 21.5 for wildcard support.
[sxemacs] / src / hash.h
1 /*
2 This file is part of SXEmacs
3
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.
8
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.
13
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/>. */
16
17
18 /* Synched up with: Not in FSF. */
19
20 #ifndef INCLUDED_hash_h_
21 #define INCLUDED_hash_h_
22
23 typedef struct {
24         const void *key;
25         void *contents;
26 } chentry;
27
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;
31
32 struct hash_table {
33         chentry *harray;
34         long zero_set;
35         void *zero_entry;
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;
40 };
41
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);
45
46 struct hash_table *make_general_hash_table(hash_size_t size,
47                                            hash_table_hash_function
48                                            hash_function,
49                                            hash_table_test_function
50                                            test_function);
51
52 /* Clear HASH-TABLE. A freshly created hash table is already cleared up. */
53 void clrhash(struct hash_table *hash_table);
54
55 /* Free HASH-TABLE and its substructures */
56 void free_hash_table(struct hash_table *hash_table);
57
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);
61
62 /* KEY should be different from 0 */
63 void puthash(const void *key, void *contents, struct hash_table *hash_table);
64
65 /* delete the entry with key KEY */
66 void remhash(const void *key, struct hash_table *hash_table);
67
68 typedef int (*maphash_function) (const void *key, void *contents, void *arg);
69
70 typedef int (*remhash_predicate) (const void *key, const void *contents,
71                                   void *arg);
72
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);
75
76 /* Delete all objects from HASH-TABLE satisfying PREDICATE */
77 void map_remhash(remhash_predicate predicate,
78                  struct hash_table *hash_table, void *arg);
79
80 #endif                          /* INCLUDED_hash_h_ */