XEmacs 21.2.5
[chise/xemacs-chise.git.1] / src / hash.h
1 /* This file is part of XEmacs.
2
3 XEmacs is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2, or (at your option) any
6 later version.
7
8 XEmacs is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11 for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with XEmacs; see the file COPYING.  If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.  */
17
18 /* Synched up with: Not in FSF. */
19
20 #ifndef _HASH_H_
21 #define _HASH_H_
22
23 typedef struct
24 {
25   CONST void *key;
26   void       *contents;
27 } hentry;
28
29 typedef int           (*hash_table_test_function) (CONST void *, CONST void *);
30 typedef unsigned long (*hash_table_hash_function) (CONST void *);
31 typedef size_t hash_size_t;
32
33 struct hash_table
34 {
35   hentry        *harray;
36   long          zero_set;
37   void          *zero_entry;
38   hash_size_t   size;           /* size of the hasharray */
39   hash_size_t   fullness;       /* number of entries in the hash table */
40   hash_table_hash_function hash_function;
41   hash_table_test_function test_function;
42 };
43
44 /* SIZE is the number of initial entries. The hash table will be grown
45    automatically if the number of entries approaches the size */
46 struct hash_table *make_hash_table (hash_size_t size);
47
48 struct hash_table *
49 make_general_hash_table (hash_size_t size,
50                         hash_table_hash_function hash_function,
51                         hash_table_test_function test_function);
52
53 struct hash_table *make_strings_hash_table (hash_size_t size);
54
55 /* Clear HASH-TABLE. A freshly created hash table is already cleared up. */
56 void clrhash (struct hash_table *hash_table);
57
58 /* Free HASH-TABLE and its substructures */
59 void free_hash_table (struct hash_table *hash_table);
60
61 /* Returns a hentry whose key is 0 if the entry does not exist in HASH-TABLE */
62 CONST void *gethash (CONST void *key, struct hash_table *hash_table,
63                      CONST void **ret_value);
64
65 /* KEY should be different from 0 */
66 void puthash (CONST void *key, void *contents, struct hash_table *hash_table);
67
68 /* delete the entry with key KEY */
69 void remhash (CONST void *key, struct hash_table *hash_table);
70
71 typedef int (*maphash_function) (CONST void* key, void* contents, void* arg);
72
73 typedef int (*remhash_predicate) (CONST void* key, CONST void* contents,
74                                   void* arg);
75
76 typedef void (*generic_hash_table_op) (struct hash_table *hash_table,
77                                       void *arg1, void *arg2, void *arg3);
78
79 /* Call MF (key, contents, arg) for every entry in HASH-TABLE */
80 void maphash (maphash_function mf, struct hash_table *hash_table, void* arg);
81
82 /* Delete all objects from HASH-TABLE satisfying PREDICATE */
83 void map_remhash (remhash_predicate predicate,
84                   struct hash_table *hash_table, void *arg);
85
86 /* Copy all the entries from SRC into DEST -- DEST is modified as needed
87    so it is as big as SRC. */
88 void copy_hash (struct hash_table *dest, struct hash_table *src);
89
90 /* Make sure HASH-TABLE can hold at least NEEDED_SIZE entries */
91 void expand_hash_table (struct hash_table *hash_table, hash_size_t needed_size);
92
93 #endif /* _HASH_H_ */