1 |
/* An expandable hash tables datatype. |
/* An expandable hash tables datatype. |
2 |
Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc. |
Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc. |
3 |
Contributed by Vladimir Makarov (vmakarov@cygnus.com). |
Contributed by Vladimir Makarov (vmakarov@cygnus.com). |
4 |
|
|
5 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
76 |
/* We also need a free() routine. */ |
/* We also need a free() routine. */ |
77 |
typedef void (*htab_free) PARAMS ((PTR)); |
typedef void (*htab_free) PARAMS ((PTR)); |
78 |
|
|
79 |
|
/* Memory allocation and deallocation; variants which take an extra |
80 |
|
argument. */ |
81 |
|
typedef PTR (*htab_alloc_with_arg) PARAMS ((void *, size_t, size_t)); |
82 |
|
typedef void (*htab_free_with_arg) PARAMS ((void *, void *)); |
83 |
|
|
84 |
/* Hash tables are of the following type. The structure |
/* Hash tables are of the following type. The structure |
85 |
(implementation) of this type is not needed for using the hash |
(implementation) of this type is not needed for using the hash |
86 |
tables. All work with hash table should be executed only through |
tables. All work with hash table should be executed only through |
87 |
functions mentioned below. */ |
functions mentioned below. The size of this structure is subject to |
88 |
|
change. */ |
89 |
|
|
90 |
struct htab GTY(()) |
struct htab GTY(()) |
91 |
{ |
{ |
99 |
htab_del del_f; |
htab_del del_f; |
100 |
|
|
101 |
/* Table itself. */ |
/* Table itself. */ |
102 |
PTR * GTY ((use_param (""), length ("%h.size"))) entries; |
PTR * GTY ((use_param, length ("%h.size"))) entries; |
103 |
|
|
104 |
/* Current size (in entries) of the hash table */ |
/* Current size (in entries) of the hash table. */ |
105 |
size_t size; |
size_t size; |
106 |
|
|
107 |
/* Current number of elements including also deleted elements */ |
/* Current number of elements including also deleted elements. */ |
108 |
size_t n_elements; |
size_t n_elements; |
109 |
|
|
110 |
/* Current number of deleted elements in the table */ |
/* Current number of deleted elements in the table. */ |
111 |
size_t n_deleted; |
size_t n_deleted; |
112 |
|
|
113 |
/* The following member is used for debugging. Its value is number |
/* The following member is used for debugging. Its value is number |
121 |
/* Pointers to allocate/free functions. */ |
/* Pointers to allocate/free functions. */ |
122 |
htab_alloc alloc_f; |
htab_alloc alloc_f; |
123 |
htab_free free_f; |
htab_free free_f; |
124 |
|
|
125 |
|
/* Alternate allocate/free functions, which take an extra argument. */ |
126 |
|
PTR GTY((skip)) alloc_arg; |
127 |
|
htab_alloc_with_arg alloc_with_arg_f; |
128 |
|
htab_free_with_arg free_with_arg_f; |
129 |
|
|
130 |
|
/* Current size (in entries) of the hash table, as an index into the |
131 |
|
table of primes. */ |
132 |
|
unsigned int size_prime_index; |
133 |
}; |
}; |
134 |
|
|
135 |
typedef struct htab *htab_t; |
typedef struct htab *htab_t; |
143 |
htab_eq, htab_del, |
htab_eq, htab_del, |
144 |
htab_alloc, htab_free)); |
htab_alloc, htab_free)); |
145 |
|
|
146 |
|
extern htab_t htab_create_alloc_ex PARAMS ((size_t, htab_hash, |
147 |
|
htab_eq, htab_del, |
148 |
|
PTR, htab_alloc_with_arg, |
149 |
|
htab_free_with_arg)); |
150 |
|
|
151 |
/* Backward-compatibility functions. */ |
/* Backward-compatibility functions. */ |
152 |
extern htab_t htab_create PARAMS ((size_t, htab_hash, htab_eq, htab_del)); |
extern htab_t htab_create PARAMS ((size_t, htab_hash, htab_eq, htab_del)); |
153 |
extern htab_t htab_try_create PARAMS ((size_t, htab_hash, htab_eq, htab_del)); |
extern htab_t htab_try_create PARAMS ((size_t, htab_hash, htab_eq, htab_del)); |
154 |
|
|
155 |
|
extern void htab_set_functions_ex PARAMS ((htab_t, htab_hash, |
156 |
|
htab_eq, htab_del, |
157 |
|
PTR, htab_alloc_with_arg, |
158 |
|
htab_free_with_arg)); |
159 |
|
|
160 |
extern void htab_delete PARAMS ((htab_t)); |
extern void htab_delete PARAMS ((htab_t)); |
161 |
extern void htab_empty PARAMS ((htab_t)); |
extern void htab_empty PARAMS ((htab_t)); |
162 |
|
|
170 |
enum insert_option)); |
enum insert_option)); |
171 |
extern void htab_clear_slot PARAMS ((htab_t, void **)); |
extern void htab_clear_slot PARAMS ((htab_t, void **)); |
172 |
extern void htab_remove_elt PARAMS ((htab_t, void *)); |
extern void htab_remove_elt PARAMS ((htab_t, void *)); |
173 |
|
extern void htab_remove_elt_with_hash PARAMS ((htab_t, void *, hashval_t)); |
174 |
|
|
175 |
extern void htab_traverse PARAMS ((htab_t, htab_trav, void *)); |
extern void htab_traverse PARAMS ((htab_t, htab_trav, void *)); |
176 |
|
extern void htab_traverse_noresize PARAMS ((htab_t, htab_trav, void *)); |
177 |
|
|
178 |
extern size_t htab_size PARAMS ((htab_t)); |
extern size_t htab_size PARAMS ((htab_t)); |
179 |
extern size_t htab_elements PARAMS ((htab_t)); |
extern size_t htab_elements PARAMS ((htab_t)); |
188 |
/* A hash function for null-terminated strings. */ |
/* A hash function for null-terminated strings. */ |
189 |
extern hashval_t htab_hash_string PARAMS ((const PTR)); |
extern hashval_t htab_hash_string PARAMS ((const PTR)); |
190 |
|
|
191 |
|
/* An iterative hash function for arbitrary data. */ |
192 |
|
extern hashval_t iterative_hash PARAMS ((const PTR, size_t, hashval_t)); |
193 |
|
/* Shorthand for hashing something with an intrinsic size. */ |
194 |
|
#define iterative_hash_object(OB,INIT) iterative_hash (&OB, sizeof (OB), INIT) |
195 |
|
|
196 |
#ifdef __cplusplus |
#ifdef __cplusplus |
197 |
} |
} |
198 |
#endif /* __cplusplus */ |
#endif /* __cplusplus */ |