Improve documentation
[sxemacs] / src / elhash.h
1 /* Lisp interface to hash tables -- include file.
2    Copyright (C) 1995, 1996 Ben Wing.
3
4 This file is part of SXEmacs
5
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
18
19
20 /* Synched up with: Not in FSF. */
21
22 #ifndef INCLUDED_elhash_h_
23 #define INCLUDED_elhash_h_
24
25 typedef struct hash_table_s *hash_table_t;
26 typedef struct hentry_s *hentry_t;
27
28 extern void elhash_reinit(void);
29
30 typedef int (*hash_table_test_f)(Lisp_Object obj1, Lisp_Object obj2);
31 typedef long unsigned int (*hash_table_hash_f)(Lisp_Object obj);
32 typedef int (*maphash_f)(Lisp_Object key, Lisp_Object value, void*);
33
34 DECLARE_LRECORD(hash_table, struct hash_table_s);
35
36 #define XHASH_TABLE(x)          XRECORD(x, hash_table, struct hash_table_s)
37 #define XSETHASH_TABLE(x, p)    XSETRECORD(x, p, hash_table)
38 #define HASH_TABLEP(x)          RECORDP(x, hash_table)
39 #define CHECK_HASH_TABLE(x)     CHECK_RECORD(x, hash_table)
40 #define CONCHECK_HASH_TABLE(x)  CONCHECK_RECORD(x, hash_table)
41
42 enum hash_table_weakness {
43         HASH_TABLE_NON_WEAK,
44         HASH_TABLE_KEY_WEAK,
45         HASH_TABLE_VALUE_WEAK,
46         HASH_TABLE_KEY_VALUE_WEAK,
47         HASH_TABLE_KEY_CAR_WEAK,
48         HASH_TABLE_VALUE_CAR_WEAK,
49         HASH_TABLE_KEY_CAR_VALUE_WEAK,
50         HASH_TABLE_WEAK
51 };
52
53 enum hash_table_test {
54         HASH_TABLE_EQ,
55         HASH_TABLE_EQL,
56         HASH_TABLE_EQUAL
57 };
58
59 \f
60 struct hentry_s {
61         Lisp_Object key;
62         Lisp_Object value;
63 };
64
65 struct hash_table_s {
66         struct lcrecord_header header;
67
68         /* the sequence category */
69         void *si;
70         /* the dict (aset) category */
71         void *di;
72
73         size_t size;
74         size_t count;
75         size_t rehash_count;
76         fpfloat rehash_size;
77         fpfloat rehash_threshold;
78         size_t golden_ratio;
79         hash_table_hash_f hash_function;
80         hash_table_test_f test_function;
81         hentry_t hentries;
82         enum hash_table_weakness weakness;
83         Lisp_Object next_weak;  /* Used to chain together all of the weak
84                                    hash tables.  Don't mark through this. */
85 };
86
87 #if 0
88 #define HENTRY_CLEAR_P(hentry) ((*(EMACS_UINT*)(&((hentry)->key))) == 0)
89 #else
90 extern_inline int
91 HENTRY_CLEAR_P(const hentry_t h);
92 extern_inline int
93 HENTRY_CLEAR_P(const hentry_t h)
94 {
95         return h->key == Qnull_pointer;
96 }
97 #endif
98 #define CLEAR_HENTRY(hentry)   \
99   ((*(EMACS_UINT*)(&((hentry)->key)))   = 0, \
100    (*(EMACS_UINT*)(&((hentry)->value))) = 0)
101
102 extern const struct lrecord_description hash_table_description[];
103
104 EXFUN(Fcopy_hash_table, 1);
105 EXFUN(Fhash_table_count, 1);
106 EXFUN(Fgethash, 3);
107 EXFUN(Fputhash, 3);
108 EXFUN(Fremhash, 2);
109 EXFUN(Fclrhash, 1);
110
111 Lisp_Object make_standard_lisp_hash_table(enum hash_table_test test,
112                                           size_t size,
113                                           fpfloat rehash_size,
114                                           fpfloat rehash_threshold,
115                                           enum hash_table_weakness weakness);
116
117 Lisp_Object make_general_lisp_hash_table(
118         hash_table_hash_f hash_function,
119         hash_table_test_f test_function,
120         size_t size, fpfloat rehash_size, fpfloat rehash_threshold,
121         enum hash_table_weakness weakness);
122
123 Lisp_Object make_lisp_hash_table(
124         size_t size,
125         enum hash_table_weakness weakness,
126         enum hash_table_test test);
127
128 void elisp_maphash(maphash_f function, Lisp_Object ht, void *extra_arg);
129 void elisp_map_remhash(maphash_f predicate, Lisp_Object ht, void *extra_arg);
130
131 int finish_marking_weak_hash_tables(void);
132 void prune_weak_hash_tables(void);
133
134 void pdump_reorganize_hash_table(Lisp_Object);
135
136 #endif                          /* INCLUDED_elhash_h_ */