1
1
/* hash - hashing table processing.
2
Copyright (C) 1998-1999, 2001, 2003, 2009-2011 Free Software Foundation,
2
Copyright (C) 1998-1999, 2001, 2003, 2009-2012 Free Software Foundation,
4
4
Written by Jim Meyering <meyering@ascend.com>, 1998.
19
19
/* A generic hash table package. */
21
21
/* Make sure USE_OBSTACK is defined to 1 if you want the allocator to use
22
obstacks instead of malloc, and recompile `hash.c' with same setting. */
22
obstacks instead of malloc, and recompile 'hash.c' with same setting. */
35
35
# define _GL_ATTRIBUTE_WUR /* empty */
38
# ifndef _GL_ATTRIBUTE_DEPRECATED
39
/* The __attribute__((__deprecated__)) feature
40
is available in gcc versions 3.1 and newer. */
41
# if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1)
42
# define _GL_ATTRIBUTE_DEPRECATED /* empty */
44
# define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
38
48
typedef size_t (*Hash_hasher) (const void *, size_t);
39
49
typedef bool (*Hash_comparator) (const void *, const void *);
40
50
typedef void (*Hash_data_freer) (void *);
45
/* This structure is mainly used for `hash_initialize', see the block
46
documentation of `hash_reset_tuning' for more complete comments. */
55
/* This structure is mainly used for 'hash_initialize', see the block
56
documentation of 'hash_reset_tuning' for more complete comments. */
48
58
float shrink_threshold; /* ratio of used buckets to trigger a shrink */
49
59
float shrink_factor; /* ratio of new smaller size to original size */
59
69
typedef struct hash_table Hash_table;
61
71
/* Information and lookup. */
62
size_t hash_get_n_buckets (const Hash_table *);
63
size_t hash_get_n_buckets_used (const Hash_table *);
64
size_t hash_get_n_entries (const Hash_table *);
65
size_t hash_get_max_bucket_length (const Hash_table *);
66
bool hash_table_ok (const Hash_table *);
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;
67
77
void hash_print_statistics (const Hash_table *, FILE *);
68
78
void *hash_lookup (const Hash_table *, const void *);
71
void *hash_get_first (const Hash_table *);
81
void *hash_get_first (const Hash_table *) _GL_ATTRIBUTE_PURE;
72
82
void *hash_get_next (const Hash_table *, const void *);
73
83
size_t hash_get_entries (const Hash_table *, void **, size_t);
74
84
size_t hash_do_for_each (const Hash_table *, Hash_processor, void *);
76
86
/* Allocation and clean-up. */
77
size_t hash_string (const char *, size_t);
87
size_t hash_string (const char *, size_t) _GL_ATTRIBUTE_PURE;
78
88
void hash_reset_tuning (Hash_tuning *);
79
89
Hash_table *hash_initialize (size_t, const Hash_tuning *,
80
90
Hash_hasher, Hash_comparator,
85
95
/* Insertion and deletion. */
86
96
bool hash_rehash (Hash_table *, size_t) _GL_ATTRIBUTE_WUR;
87
97
void *hash_insert (Hash_table *, const void *) _GL_ATTRIBUTE_WUR;
88
int hash_insert0 (Hash_table *table, const void *entry,
89
const void **matched_ent);
99
/* Deprecate this interface. It has been renamed to hash_insert_if_absent. */
100
int hash_insert0 (Hash_table *table, /* FIXME: remove in 2013 */
102
const void **matched_ent) _GL_ATTRIBUTE_DEPRECATED;
103
int hash_insert_if_absent (Hash_table *table, const void *entry,
104
const void **matched_ent);
90
105
void *hash_delete (Hash_table *, const void *);