XEmacs 21.2-b1
[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 struct _C_hashtable
30 {
31   hentry        *harray;
32   long          zero_set;
33   void          *zero_entry;
34   size_t        size;           /* size of the hasharray */
35   unsigned int  fullness;       /* number of entries in the hashtable */
36   unsigned long (*hash_function) (CONST void *);
37   int           (*test_function) (CONST void *, CONST void *);
38 #ifdef emacs
39   Lisp_Object elisp_table;
40 #endif
41 };
42
43 typedef struct _C_hashtable *c_hashtable;
44
45 /* size is the number of initial entries. The hashtable will be grown
46    automatically if the number of entries approaches the size */
47 c_hashtable make_hashtable (unsigned int size);
48
49 c_hashtable make_general_hashtable (unsigned int hsize,
50                                     unsigned long (*hash_function)
51                                     (CONST void *),
52                                     int (*test_function) (CONST void *,
53                                                           CONST void *));
54
55 c_hashtable make_strings_hashtable (unsigned int hsize);
56
57 /* clears the hash table. A freshly created hashtable is already cleared up */
58 void clrhash (c_hashtable hash);
59
60 /* frees the table and substructures */
61 void free_hashtable (c_hashtable hash);
62
63 /* returns a hentry whose key is 0 if the entry does not exist in hashtable */
64 CONST void *gethash (CONST void *key, c_hashtable hash,
65                      CONST void **ret_value);
66
67 /* key should be different from 0 */
68 void puthash (CONST void *key, void *contents, c_hashtable hash);
69
70 /* delete the entry which key is key */
71 void remhash (CONST void *key, c_hashtable hash);
72
73 typedef int (*maphash_function) (CONST void* key, void* contents, void* arg);
74
75 typedef int (*remhash_predicate) (CONST void* key, CONST void* contents,
76                                   void* arg);
77
78 typedef void (*generic_hashtable_op) (c_hashtable table,
79                                       void *arg1, void *arg2, void *arg3);
80
81 /* calls mf with the following arguments:  key, contents, arg; for every
82    entry in the hashtable */
83 void maphash (maphash_function fn, c_hashtable hash, void* arg);
84
85 /* delete objects from the table which satisfy the predicate */
86 void map_remhash (remhash_predicate predicate, c_hashtable hash, void *arg);
87
88 /* copies all the entries of src into dest -- dest is modified as needed
89    so it is as big as src. */
90 void copy_hash (c_hashtable dest, c_hashtable src);
91
92 /* makes sure that hashtable can hold at least needed_size entries */
93 void expand_hashtable (c_hashtable hash, unsigned int needed_size);
94
95 #ifdef emacs    /* for elhash.c */
96 unsigned int compute_harray_size (unsigned int);
97 #endif
98
99 #endif /* _HASH_H_ */