15 # ifndef HAVE_DECL_FREE
19 # ifndef HAVE_DECL_MALLOC
24 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
25 # define PARAMS(Args) Args
27 # define PARAMS(Args) ()
36 # define obstack_chunk_alloc malloc
37 # define obstack_chunk_free free
42 struct hash_ent
*next
;
44 typedef struct hash_ent HASH_ENT
;
46 /* This is particularly useful to cast uses in hash_initialize of the
47 system free function. */
48 typedef void (*Hash_key_freer_type
) PARAMS((void *key
));
52 /* User-supplied function for freeing keys. It is specified in
53 hash_initialize. If non-null, it is used by hash_free and
54 hash_clear. You should specify `free' here only if you want
55 these functions to free all of your `key' data. This is typically
56 the case when your key is simply an auxilliary struct that you
57 have malloc'd to aggregate several values. */
58 Hash_key_freer_type hash_key_freer
;
60 /* User-supplied hash function that hashes entry E to an integer
61 in the range 0..TABLE_SIZE-1. */
62 unsigned int (*hash_hash
) PARAMS((const void *e
, unsigned int table_size
));
64 /* User-supplied function that determines whether a new entry is
65 unique by comparing the new entry to entries that hashed to the
66 same bucket index. It should return zero for a pair of entries
67 that compare equal, non-zero otherwise. */
69 int (*hash_key_comparator
) PARAMS((const void *, const void *));
71 HASH_ENT
**hash_table
;
72 unsigned int hash_table_size
;
73 unsigned int hash_n_slots_used
;
74 unsigned int hash_max_chain_length
;
76 /* Gets set when an entry is deleted from a chain of length
77 hash_max_chain_length. Indicates that hash_max_chain_length
78 may no longer be valid. */
79 unsigned int hash_dirty_max_chain_length
;
81 /* Sum of lengths of all chains (not counting any dummy
83 unsigned int hash_n_keys
;
85 /* A linked list of freed HASH_ENT structs.
86 FIXME: Perhaps this is unnecessary and we should simply free
87 and reallocate such structs. */
88 HASH_ENT
*hash_free_entry_list
;
92 struct obstack ht_obstack
;
99 hash_get_n_slots_used
PARAMS((const HT
*ht
));
102 hash_get_max_chain_length
PARAMS((HT
*ht
));
105 hash_rehash
PARAMS((HT
*ht
, unsigned int new_table_size
));
108 hash_get_table_size
PARAMS((const HT
*ht
));
111 hash_initialize
PARAMS((unsigned int table_size
,
112 void (*key_freer
) PARAMS((void *key
)),
113 unsigned int (*hash
) PARAMS((const void *,
115 int (*equality_tester
) PARAMS((const void *,
119 hash_get_n_keys
PARAMS((const HT
*ht
));
122 hash_query_in_table
PARAMS((const HT
*ht
, const void *e
));
125 hash_lookup
PARAMS((const HT
*ht
, const void *e
));
128 hash_insert_if_absent
PARAMS((HT
*ht
,
133 hash_delete_if_present
PARAMS((HT
*ht
, const void *e
));
136 hash_print_statistics
PARAMS((const HT
*ht
, FILE *stream
));
139 hash_get_statistics
PARAMS((const HT
*ht
, unsigned int *n_slots_used
,
140 unsigned int *n_keys
,
141 unsigned int *max_chain_length
));
144 hash_table_ok
PARAMS((HT
*ht
));
147 hash_do_for_each
PARAMS((HT
*ht
,
148 void (*f
) PARAMS((void *e
, void *aux
)),
152 hash_do_for_each_2
PARAMS((HT
*ht
,
153 int (*f
) PARAMS((void *e
, void *aux
)),
157 hash_do_for_each_in_selected_bucket
PARAMS((HT
*ht
,
159 int (*f
) PARAMS((const void *bucket_key
,
165 hash_clear
PARAMS((HT
*ht
));
168 hash_free
PARAMS((HT
*ht
));
171 hash_get_key_list
PARAMS((const HT
*ht
,
172 unsigned int bufsize
,
176 hash_get_first
PARAMS((const HT
*ht
));
179 hash_get_next
PARAMS((const HT
*ht
, const void *e
));
181 /* This interface to hash_insert_if_absent is used frequently enough to
182 merit a macro here. */
184 # define HASH_INSERT_NEW_ITEM(Ht, Item, Failp) \
188 _already = hash_insert_if_absent ((Ht), (Item), Failp); \
189 assert (_already == NULL); \