raw
vtools_genesis          1 
vtools_genesis 2 /* A generic hash table package. */
vtools_genesis 3
vtools_genesis 4 /* Make sure |use_obstack| is defined to 1 if you want the allocator
vtools_genesis 5 to use obstacks instead of malloc, and recompile |hash.c| with same
vtools_genesis 6 setting. */
vtools_genesis 7
vtools_genesis 8 #ifndef HASH_H_
vtools_genesis 9 # define HASH_H_
vtools_genesis 10
vtools_genesis 11 # include <stdio.h>
vtools_genesis 12 # include <stdbool.h>
vtools_genesis 13
vtools_genesis 14 typedef size_t (*Hash_hasher)(const void *, size_t);
vtools_genesis 15
vtools_genesis 16 typedef bool (*Hash_comparator)(const void *, const void *);
vtools_genesis 17
vtools_genesis 18 typedef void (*Hash_data_freer)(void *);
vtools_genesis 19
vtools_genesis 20 typedef bool (*Hash_processor)(void *, void *);
vtools_genesis 21
vtools_genesis 22 struct hash_tuning {
vtools_genesis 23 /* This structure is mainly used for |hash_initialize|, see the
vtools_genesis 24 block documentation of |hash_reset_tuning| for more complete
vtools_genesis 25 comments. */
vtools_genesis 26
vtools_genesis 27 float shrink_threshold; /* ratio of used buckets to trigger a shrink */
vtools_genesis 28 float shrink_factor; /* ratio of new smaller size to original size */
vtools_genesis 29 float growth_threshold; /* ratio of used buckets to trigger a growth */
vtools_genesis 30 float growth_factor; /* ratio of new bigger size to original size */
vtools_genesis 31 bool is_n_buckets; /* if |candidate| really means table size */
vtools_genesis 32 };
vtools_genesis 33
vtools_genesis 34 typedef struct hash_tuning Hash_tuning;
vtools_genesis 35
vtools_genesis 36 struct hash_table;
vtools_genesis 37
vtools_genesis 38 typedef struct hash_table Hash_table;
vtools_genesis 39
vtools_genesis 40 /* Information and lookup. */
vtools_genesis 41 size_t hash_get_n_buckets(const Hash_table *);
vtools_genesis 42
vtools_genesis 43 size_t hash_get_n_buckets_used(const Hash_table *);
vtools_genesis 44
vtools_genesis 45 size_t hash_get_n_entries(const Hash_table *);
vtools_genesis 46
vtools_genesis 47 size_t hash_get_max_bucket_length(const Hash_table *);
vtools_genesis 48
vtools_genesis 49 bool hash_table_ok(const Hash_table *);
vtools_genesis 50
vtools_genesis 51 void hash_print_statistics(const Hash_table *, FILE *);
vtools_genesis 52
vtools_genesis 53 void *hash_lookup(const Hash_table *, const void *);
vtools_genesis 54
vtools_genesis 55 /* Walking. */
vtools_genesis 56 void *hash_get_first(const Hash_table *);
vtools_genesis 57
vtools_genesis 58 void *hash_get_next(const Hash_table *, const void *);
vtools_genesis 59
vtools_genesis 60 size_t hash_get_entries(const Hash_table *, void **, size_t);
vtools_genesis 61
vtools_genesis 62 size_t hash_do_for_each(const Hash_table *, Hash_processor, void *);
vtools_genesis 63
vtools_genesis 64 /* Allocation and clean-up. */
vtools_genesis 65 size_t hash_string(const char *, size_t);
vtools_genesis 66
vtools_genesis 67 void hash_reset_tuning(Hash_tuning *);
vtools_genesis 68
vtools_genesis 69 Hash_table *hash_initialize(size_t, const Hash_tuning *,
vtools_genesis 70 Hash_hasher, Hash_comparator,
vtools_genesis 71 Hash_data_freer);
vtools_genesis 72
vtools_genesis 73 void hash_clear(Hash_table *);
vtools_genesis 74
vtools_genesis 75 void hash_free(Hash_table *);
vtools_genesis 76
vtools_genesis 77 /* Insertion and deletion. */
vtools_genesis 78 bool hash_rehash(Hash_table *, size_t);
vtools_genesis 79
vtools_genesis 80 void *hash_insert(Hash_table *, const void *);
vtools_genesis 81
vtools_genesis 82 int hash_insert_if_absent(Hash_table *table, const void *entry,
vtools_genesis 83 const void **matched_ent);
vtools_genesis 84
vtools_genesis 85 void *hash_delete(Hash_table *, const void *);
vtools_genesis 86
vtools_genesis 87 #endif