-
+ 861F7244DB30BFBA8540A2E1D615A4226E0CB4E7D177B1850149E6829B23D84B56482EF4DD5D04DB6AA6F8DDA409EF8043A7612670DF5F87A89BD7B3F46F8037
vtools/lib/hash.h
(0 . 0)(1 . 87)
2127
2128 /* A generic hash table package. */
2129
2130 /* Make sure |use_obstack| is defined to 1 if you want the allocator
2131 to use obstacks instead of malloc, and recompile |hash.c| with same
2132 setting. */
2133
2134 #ifndef HASH_H_
2135 # define HASH_H_
2136
2137 # include <stdio.h>
2138 # include <stdbool.h>
2139
2140 typedef size_t (*Hash_hasher)(const void *, size_t);
2141
2142 typedef bool (*Hash_comparator)(const void *, const void *);
2143
2144 typedef void (*Hash_data_freer)(void *);
2145
2146 typedef bool (*Hash_processor)(void *, void *);
2147
2148 struct hash_tuning {
2149 /* This structure is mainly used for |hash_initialize|, see the
2150 block documentation of |hash_reset_tuning| for more complete
2151 comments. */
2152
2153 float shrink_threshold; /* ratio of used buckets to trigger a shrink */
2154 float shrink_factor; /* ratio of new smaller size to original size */
2155 float growth_threshold; /* ratio of used buckets to trigger a growth */
2156 float growth_factor; /* ratio of new bigger size to original size */
2157 bool is_n_buckets; /* if |candidate| really means table size */
2158 };
2159
2160 typedef struct hash_tuning Hash_tuning;
2161
2162 struct hash_table;
2163
2164 typedef struct hash_table Hash_table;
2165
2166 /* Information and lookup. */
2167 size_t hash_get_n_buckets(const Hash_table *);
2168
2169 size_t hash_get_n_buckets_used(const Hash_table *);
2170
2171 size_t hash_get_n_entries(const Hash_table *);
2172
2173 size_t hash_get_max_bucket_length(const Hash_table *);
2174
2175 bool hash_table_ok(const Hash_table *);
2176
2177 void hash_print_statistics(const Hash_table *, FILE *);
2178
2179 void *hash_lookup(const Hash_table *, const void *);
2180
2181 /* Walking. */
2182 void *hash_get_first(const Hash_table *);
2183
2184 void *hash_get_next(const Hash_table *, const void *);
2185
2186 size_t hash_get_entries(const Hash_table *, void **, size_t);
2187
2188 size_t hash_do_for_each(const Hash_table *, Hash_processor, void *);
2189
2190 /* Allocation and clean-up. */
2191 size_t hash_string(const char *, size_t);
2192
2193 void hash_reset_tuning(Hash_tuning *);
2194
2195 Hash_table *hash_initialize(size_t, const Hash_tuning *,
2196 Hash_hasher, Hash_comparator,
2197 Hash_data_freer);
2198
2199 void hash_clear(Hash_table *);
2200
2201 void hash_free(Hash_table *);
2202
2203 /* Insertion and deletion. */
2204 bool hash_rehash(Hash_table *, size_t);
2205
2206 void *hash_insert(Hash_table *, const void *);
2207
2208 int hash_insert_if_absent(Hash_table *table, const void *entry,
2209 const void **matched_ent);
2210
2211 void *hash_delete(Hash_table *, const void *);
2212
2213 #endif