Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: h_files */ |
2 | ||
0527e687 DH |
3 | #ifndef SCM_HASHTAB_H |
4 | #define SCM_HASHTAB_H | |
5 | ||
711a9fd7 | 6 | /* Copyright (C) 1995,1996,1999,2000,2001, 2003, 2004 Free Software Foundation, Inc. |
0527e687 | 7 | * |
73be1d9e MV |
8 | * This library is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2.1 of the License, or (at your option) any later version. | |
0527e687 | 12 | * |
73be1d9e | 13 | * This library is distributed in the hope that it will be useful, |
0f2d19dd | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
73be1d9e MV |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. | |
0527e687 | 17 | * |
73be1d9e MV |
18 | * You should have received a copy of the GNU Lesser General Public |
19 | * License along with this library; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | */ | |
0527e687 | 22 | |
0f2d19dd | 23 | \f |
0527e687 | 24 | |
5e044c02 | 25 | #include "libguile/__scm.h" |
0f2d19dd | 26 | |
c35738c1 MD |
27 | #include "weaks.h" |
28 | ||
29 | \f | |
30 | ||
31 | #define SCM_HASHTABLEF_WEAK_CAR SCM_WVECTF_WEAK_KEY | |
32 | #define SCM_HASHTABLEF_WEAK_CDR SCM_WVECTF_WEAK_VALUE | |
33 | ||
cdc5f676 MV |
34 | extern scm_t_bits scm_tc16_hashtable; |
35 | ||
f5710d53 | 36 | #define SCM_HASHTABLE_P(x) SCM_SMOB_PREDICATE (scm_tc16_hashtable, x) |
c35738c1 MD |
37 | #define SCM_VALIDATE_HASHTABLE(pos, arg) \ |
38 | SCM_MAKE_VALIDATE_MSG (pos, arg, HASHTABLE_P, "hash-table") | |
f5710d53 MV |
39 | #define SCM_HASHTABLE_VECTOR(h) SCM_SMOB_OBJECT (h) |
40 | #define SCM_SET_HASHTABLE_VECTOR(x, v) SCM_SET_SMOB_OBJECT ((x), (v)) | |
41 | #define SCM_HASHTABLE(x) ((scm_t_hashtable *) SCM_SMOB_DATA_2 (x)) | |
42 | #define SCM_HASHTABLE_NEXT(x) SCM_SMOB_OBJECT_3 (x) | |
43 | #define SCM_HASHTABLE_NEXTLOC(x) SCM_SMOB_OBJECT_3_LOC (x) | |
44 | #define SCM_SET_HASHTABLE_NEXT(x, n) SCM_SET_SMOB_OBJECT_3 ((x), (n)) | |
c35738c1 MD |
45 | #define SCM_HASHTABLE_FLAGS(x) (SCM_HASHTABLE (x)->flags) |
46 | #define SCM_HASHTABLE_WEAK_KEY_P(x) \ | |
47 | (SCM_HASHTABLE_FLAGS (x) & SCM_HASHTABLEF_WEAK_CAR) | |
48 | #define SCM_HASHTABLE_WEAK_VALUE_P(x) \ | |
49 | (SCM_HASHTABLE_FLAGS (x) & SCM_HASHTABLEF_WEAK_CDR) | |
50 | #define SCM_HASHTABLE_DOUBLY_WEAK_P(x) \ | |
51 | ((SCM_HASHTABLE_FLAGS (x) \ | |
52 | & (SCM_HASHTABLEF_WEAK_CAR | SCM_HASHTABLEF_WEAK_CDR)) \ | |
53 | == (SCM_HASHTABLEF_WEAK_CAR | SCM_HASHTABLEF_WEAK_CDR)) | |
54 | #define SCM_HASHTABLE_WEAK_P(x) SCM_HASHTABLE_FLAGS (x) | |
55 | #define SCM_HASHTABLE_N_ITEMS(x) (SCM_HASHTABLE (x)->n_items) | |
56 | #define SCM_SET_HASHTABLE_N_ITEMS(x, n) (SCM_HASHTABLE (x)->n_items = n) | |
57 | #define SCM_HASHTABLE_INCREMENT(x) (SCM_HASHTABLE_N_ITEMS(x)++) | |
a54a94b3 | 58 | #if 0 |
c35738c1 | 59 | #define SCM_HASHTABLE_DECREMENT(x) (SCM_HASHTABLE_N_ITEMS(x)--) |
a54a94b3 MV |
60 | #else |
61 | SCM_API void scm_i_hashtable_decrement (SCM h); | |
62 | #define SCM_HASHTABLE_DECREMENT(x) scm_i_hashtable_decrement(x) | |
63 | #endif | |
c35738c1 MD |
64 | #define SCM_HASHTABLE_UPPER(x) (SCM_HASHTABLE (x)->upper) |
65 | #define SCM_HASHTABLE_LOWER(x) (SCM_HASHTABLE (x)->lower) | |
66 | ||
67 | #define SCM_HASHTABLE_N_BUCKETS(h) \ | |
3ebc1832 MV |
68 | SCM_SIMPLE_VECTOR_LENGTH (SCM_HASHTABLE_VECTOR (h)) |
69 | #define SCM_HASHTABLE_BUCKET(h, i) \ | |
70 | SCM_SIMPLE_VECTOR_REF (SCM_HASHTABLE_VECTOR (h), i) | |
c35738c1 | 71 | #define SCM_SET_HASHTABLE_BUCKET(h, i, x) \ |
3ebc1832 | 72 | SCM_SIMPLE_VECTOR_SET (SCM_HASHTABLE_VECTOR (h), i, x) |
c35738c1 MD |
73 | |
74 | typedef struct scm_t_hashtable { | |
75 | int flags; /* properties of table */ | |
76 | unsigned long n_items; /* number of items in table */ | |
77 | unsigned long lower; /* when to shrink */ | |
78 | unsigned long upper; /* when to grow */ | |
79 | int size_index; /* index into hashtable_size */ | |
80 | int min_size_index; /* minimum size_index */ | |
81 | unsigned long (*hash_fn) (); | |
82 | void *closure; | |
83 | } scm_t_hashtable; | |
84 | ||
0f2d19dd | 85 | \f |
0f2d19dd | 86 | |
1cc91f1b | 87 | #if 0 |
92c2555f MV |
88 | typedef unsigned int scm_t_hash_fn (SCM obj, unsigned int d, void *closure); |
89 | typedef SCM scm_t_assoc_fn (SCM key, SCM alist, void *closure); | |
90 | typedef SCM scm_t_delete_fn (SCM elt, SCM list); | |
1cc91f1b | 91 | #endif |
0f2d19dd | 92 | |
f59a096e | 93 | SCM_API SCM scm_vector_to_hash_table (SCM vector); |
33b001fd | 94 | SCM_API SCM scm_c_make_hash_table (unsigned long k); |
f59a096e | 95 | SCM_API SCM scm_make_hash_table (SCM n); |
c35738c1 MD |
96 | SCM_API SCM scm_make_weak_key_hash_table (SCM k); |
97 | SCM_API SCM scm_make_weak_value_hash_table (SCM k); | |
98 | SCM_API SCM scm_make_doubly_weak_hash_table (SCM k); | |
99 | ||
100 | SCM_API SCM scm_hash_table_p (SCM h); | |
101 | SCM_API SCM scm_weak_key_hash_table_p (SCM h); | |
102 | SCM_API SCM scm_weak_value_hash_table_p (SCM h); | |
103 | SCM_API SCM scm_doubly_weak_hash_table_p (SCM h); | |
104 | ||
105 | SCM_API void scm_i_rehash (SCM table, unsigned long (*hash_fn)(), void *closure, const char*func_name); | |
00ffa0e7 | 106 | |
33b001fd MV |
107 | SCM_API SCM scm_hash_fn_get_handle (SCM table, SCM obj, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure); |
108 | SCM_API SCM scm_hash_fn_create_handle_x (SCM table, SCM obj, SCM init, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure); | |
109 | SCM_API SCM scm_hash_fn_ref (SCM table, SCM obj, SCM dflt, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure); | |
110 | SCM_API SCM scm_hash_fn_set_x (SCM table, SCM obj, SCM val, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure); | |
111 | SCM_API SCM scm_hash_fn_remove_x (SCM table, SCM obj, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), SCM (*delete_fn) (), void * closure); | |
112 | SCM_API SCM scm_internal_hash_fold (SCM (*fn) (), void *closure, SCM init, SCM table); | |
711a9fd7 | 113 | SCM_API void scm_internal_hash_for_each_handle (SCM (*fn) (), void *closure, SCM table); |
c35738c1 | 114 | SCM_API SCM scm_hash_clear_x (SCM table); |
0f2d19dd | 115 | |
33b001fd MV |
116 | SCM_API SCM scm_hashq_get_handle (SCM table, SCM obj); |
117 | SCM_API SCM scm_hashq_create_handle_x (SCM table, SCM obj, SCM init); | |
118 | SCM_API SCM scm_hashq_ref (SCM table, SCM obj, SCM dflt); | |
119 | SCM_API SCM scm_hashq_set_x (SCM table, SCM obj, SCM val); | |
120 | SCM_API SCM scm_hashq_remove_x (SCM table, SCM obj); | |
121 | SCM_API SCM scm_hashv_get_handle (SCM table, SCM obj); | |
122 | SCM_API SCM scm_hashv_create_handle_x (SCM table, SCM obj, SCM init); | |
123 | SCM_API SCM scm_hashv_ref (SCM table, SCM obj, SCM dflt); | |
124 | SCM_API SCM scm_hashv_set_x (SCM table, SCM obj, SCM val); | |
125 | SCM_API SCM scm_hashv_remove_x (SCM table, SCM obj); | |
126 | SCM_API SCM scm_hash_get_handle (SCM table, SCM obj); | |
127 | SCM_API SCM scm_hash_create_handle_x (SCM table, SCM obj, SCM init); | |
128 | SCM_API SCM scm_hash_ref (SCM table, SCM obj, SCM dflt); | |
129 | SCM_API SCM scm_hash_set_x (SCM table, SCM obj, SCM val); | |
130 | SCM_API SCM scm_hash_remove_x (SCM table, SCM obj); | |
131 | SCM_API SCM scm_hashx_get_handle (SCM hash, SCM assoc, SCM table, SCM obj); | |
132 | SCM_API SCM scm_hashx_create_handle_x (SCM hash, SCM assoc, SCM table, SCM obj, SCM init); | |
133 | SCM_API SCM scm_hashx_ref (SCM hash, SCM assoc, SCM table, SCM obj, SCM dflt); | |
134 | SCM_API SCM scm_hashx_set_x (SCM hash, SCM assoc, SCM table, SCM obj, SCM val); | |
135 | SCM_API SCM scm_hashx_remove_x (SCM hash, SCM assoc, SCM del, SCM table, SCM obj); | |
136 | SCM_API SCM scm_hash_fold (SCM proc, SCM init, SCM hash); | |
c35738c1 | 137 | SCM_API SCM scm_hash_for_each (SCM proc, SCM hash); |
711a9fd7 MD |
138 | SCM_API SCM scm_hash_for_each_handle (SCM proc, SCM hash); |
139 | SCM_API SCM scm_hash_map_to_list (SCM proc, SCM hash); | |
c35738c1 | 140 | SCM_API void scm_hashtab_prehistory (void); |
33b001fd | 141 | SCM_API void scm_init_hashtab (void); |
0f2d19dd | 142 | |
0527e687 | 143 | #endif /* SCM_HASHTAB_H */ |
89e00824 ML |
144 | |
145 | /* | |
146 | Local Variables: | |
147 | c-file-style: "gnu" | |
148 | End: | |
149 | */ |