| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#ifndef HASH_H_ |
| 25 |
# define HASH_H_ |
| 26 |
|
| 27 |
# include <stdio.h> |
| 28 |
# include <stdbool.h> |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) |
| 33 |
# define _GL_ATTRIBUTE_WUR __attribute__ ((__warn_unused_result__)) |
| 34 |
# else |
| 35 |
# define _GL_ATTRIBUTE_WUR |
| 36 |
# endif |
| 37 |
|
| 38 |
# ifndef _GL_ATTRIBUTE_DEPRECATED |
| 39 |
|
| 40 |
|
| 41 |
# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1) |
| 42 |
# define _GL_ATTRIBUTE_DEPRECATED |
| 43 |
# else |
| 44 |
# define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__)) |
| 45 |
# endif |
| 46 |
# endif |
| 47 |
|
| 48 |
typedef size_t (*Hash_hasher) (const void *, size_t); |
| 49 |
typedef bool (*Hash_comparator) (const void *, const void *); |
| 50 |
typedef void (*Hash_data_freer) (void *); |
| 51 |
typedef bool (*Hash_processor) (void *, void *); |
| 52 |
|
| 53 |
struct hash_tuning |
| 54 |
{ |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
float shrink_threshold; |
| 59 |
float shrink_factor; |
| 60 |
float growth_threshold; |
| 61 |
float growth_factor; |
| 62 |
bool is_n_buckets; |
| 63 |
}; |
| 64 |
|
| 65 |
typedef struct hash_tuning Hash_tuning; |
| 66 |
|
| 67 |
struct hash_table; |
| 68 |
|
| 69 |
typedef struct hash_table Hash_table; |
| 70 |
|
| 71 |
|
| 72 |
size_t hash_get_n_buckets (const Hash_table *) _GL_ATTRIBUTE_PURE; |
| 73 |
size_t hash_get_n_buckets_used (const Hash_table *) _GL_ATTRIBUTE_PURE; |
| 74 |
size_t hash_get_n_entries (const Hash_table *) _GL_ATTRIBUTE_PURE; |
| 75 |
size_t hash_get_max_bucket_length (const Hash_table *) _GL_ATTRIBUTE_PURE; |
| 76 |
bool hash_table_ok (const Hash_table *) _GL_ATTRIBUTE_PURE; |
| 77 |
void hash_print_statistics (const Hash_table *, FILE *); |
| 78 |
void *hash_lookup (const Hash_table *, const void *); |
| 79 |
|
| 80 |
|
| 81 |
void *hash_get_first (const Hash_table *) _GL_ATTRIBUTE_PURE; |
| 82 |
void *hash_get_next (const Hash_table *, const void *); |
| 83 |
size_t hash_get_entries (const Hash_table *, void **, size_t); |
| 84 |
size_t hash_do_for_each (const Hash_table *, Hash_processor, void *); |
| 85 |
|
| 86 |
|
| 87 |
size_t hash_string (const char *, size_t) _GL_ATTRIBUTE_PURE; |
| 88 |
void hash_reset_tuning (Hash_tuning *); |
| 89 |
Hash_table *hash_initialize (size_t, const Hash_tuning *, |
| 90 |
Hash_hasher, Hash_comparator, |
| 91 |
Hash_data_freer) _GL_ATTRIBUTE_WUR; |
| 92 |
Hash_table *hash_xinitialize (size_t, const Hash_tuning *, |
| 93 |
Hash_hasher, Hash_comparator, |
| 94 |
Hash_data_freer) _GL_ATTRIBUTE_WUR; |
| 95 |
void hash_clear (Hash_table *); |
| 96 |
void hash_free (Hash_table *); |
| 97 |
|
| 98 |
|
| 99 |
bool hash_rehash (Hash_table *, size_t) _GL_ATTRIBUTE_WUR; |
| 100 |
void *hash_insert (Hash_table *, const void *) _GL_ATTRIBUTE_WUR; |
| 101 |
|
| 102 |
int hash_insert_if_absent (Hash_table *table, const void *entry, |
| 103 |
const void **matched_ent); |
| 104 |
void *hash_delete (Hash_table *, const void *); |
| 105 |
|
| 106 |
#endif |