- Copyright (C) 1998-2004, 2006-2007, 2009-2011 Free Software Foundation, Inc.
+ Copyright (C) 1998-2004, 2006-2007, 2009-2013 Free Software Foundation, Inc.
/* Tuning arguments, kept in a physically separate structure. */
const Hash_tuning *tuning;
/* Tuning arguments, kept in a physically separate structure. */
const Hash_tuning *tuning;
block for this function. In a word, HASHER randomizes a user entry
into a number up from 0 up to some maximum minus 1; COMPARATOR returns
true if two user entries compare equally; and DATA_FREER is the cleanup
block for this function. In a word, HASHER randomizes a user entry
into a number up from 0 up to some maximum minus 1; COMPARATOR returns
true if two user entries compare equally; and DATA_FREER is the cleanup
some user-provided data (also called a user entry). An entry indistinctly
refers to both the internal entry and its associated user entry. A user
entry contents may be hashed by a randomization function (the hashing
some user-provided data (also called a user entry). An entry indistinctly
refers to both the internal entry and its associated user entry. A user
entry contents may be hashed by a randomization function (the hashing
and the current table size. At each slot position in the hash table,
starts a linked chain of entries for which the user data all hash to this
slot. A bucket is the collection of all entries hashing to the same slot.
and the current table size. At each slot position in the hash table,
starts a linked chain of entries for which the user data all hash to this
slot. A bucket is the collection of all entries hashing to the same slot.
In the ideal case, the length of each bucket is roughly the number of
entries divided by the table size. Finding the slot for a data is usually
In the ideal case, the length of each bucket is roughly the number of
entries divided by the table size. Finding the slot for a data is usually
entry is linear in time with the size of the bucket. Consequently, a
larger hash table size (that is, a larger number of buckets) is prone to
entry is linear in time with the size of the bucket. Consequently, a
larger hash table size (that is, a larger number of buckets) is prone to
Long buckets slow down the lookup algorithm. One might use big hash table
sizes in hope to reduce the average length of buckets, but this might
become inordinate, as unused slots in the hash table take some space. The
Long buckets slow down the lookup algorithm. One might use big hash table
sizes in hope to reduce the average length of buckets, but this might
become inordinate, as unused slots in the hash table take some space. The
that those are not that easy to write! :-), and to use a table size
larger than the actual number of entries. */
that those are not that easy to write! :-), and to use a table size
larger than the actual number of entries. */
1.0). The growth threshold defaults to 0.8, and the growth factor
defaults to 1.414, meaning that the table will have doubled its size
every second time 80% of the buckets get used. */
1.0). The growth threshold defaults to 0.8, and the growth factor
defaults to 1.414, meaning that the table will have doubled its size
every second time 80% of the buckets get used. */
/* If a deletion empties a bucket and causes the ratio of used buckets to
table size to become smaller than the shrink threshold (a number between
/* If a deletion empties a bucket and causes the ratio of used buckets to
table size to become smaller than the shrink threshold (a number between
number greater than the shrink threshold but smaller than 1.0). The shrink
threshold and factor default to 0.0 and 1.0, meaning that the table never
shrinks. */
number greater than the shrink threshold but smaller than 1.0). The shrink
threshold and factor default to 0.0 and 1.0, meaning that the table never
shrinks. */
/* Return true if CANDIDATE is a prime number. CANDIDATE should be an odd
number at least equal to 11. */
/* Return true if CANDIDATE is a prime number. CANDIDATE should be an odd
number at least equal to 11. */
/* Round a given CANDIDATE number up to the nearest prime, and return that
prime. Primes lower than 10 are merely skipped. */
/* Round a given CANDIDATE number up to the nearest prime, and return that
prime. Primes lower than 10 are merely skipped. */
compute_bucket_size (size_t candidate, const Hash_tuning *tuning)
{
if (!tuning->is_n_buckets)
compute_bucket_size (size_t candidate, const Hash_tuning *tuning)
{
if (!tuning->is_n_buckets)
The user-supplied DATA_FREER function, when not NULL, may be later called
with the user data as an argument, just before the entry containing the
The user-supplied DATA_FREER function, when not NULL, may be later called
with the user data as an argument, just before the entry containing the
hash_insert, the only way to distinguish those cases is to compare
the return value and ENTRY. That works only when you can have two
different ENTRY values that point to data that compares "equal". Thus,
hash_insert, the only way to distinguish those cases is to compare
the return value and ENTRY. That works only when you can have two
different ENTRY values that point to data that compares "equal". Thus,
- when the ENTRY value is a simple scalar, you must use hash_insert0.
- ENTRY must not be NULL. */
+ when the ENTRY value is a simple scalar, you must use
+ hash_insert_if_absent. ENTRY must not be NULL. */
int
hash_insert_if_absent (Hash_table *table, void const *entry,
void const **matched_ent)
int
hash_insert_if_absent (Hash_table *table, void const *entry,
void const **matched_ent)