1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* hash - hashing table processing.
4 Copyright (C) 1998-1999, 2001, 2003, 2009-2013 Free Software Foundation,
6 Written by Jim Meyering <meyering@ascend.com>, 1998.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* A generic hash table package. */
23 /* Make sure USE_OBSTACK is defined to 1 if you want the allocator to use
24 obstacks instead of malloc, and recompile 'hash.c' with same setting. */
32 /* The __attribute__ feature is available in gcc versions 2.5 and later.
33 The warn_unused_result attribute appeared first in gcc-3.4.0. */
34 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
35 # define _GL_ATTRIBUTE_WUR __attribute__ ((__warn_unused_result__))
37 # define _GL_ATTRIBUTE_WUR /* empty */
40 # ifndef _GL_ATTRIBUTE_DEPRECATED
41 /* The __attribute__((__deprecated__)) feature
42 is available in gcc versions 3.1 and newer. */
43 # if __GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 1)
44 # define _GL_ATTRIBUTE_DEPRECATED /* empty */
46 # define _GL_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
50 typedef size_t (*Hash_hasher) (const void *, size_t);
51 typedef bool (*Hash_comparator) (const void *, const void *);
52 typedef void (*Hash_data_freer) (void *);
53 typedef bool (*Hash_processor) (void *, void *);
57 /* This structure is mainly used for 'hash_initialize', see the block
58 documentation of 'hash_reset_tuning' for more complete comments. */
60 float shrink_threshold; /* ratio of used buckets to trigger a shrink */
61 float shrink_factor; /* ratio of new smaller size to original size */
62 float growth_threshold; /* ratio of used buckets to trigger a growth */
63 float growth_factor; /* ratio of new bigger size to original size */
64 bool is_n_buckets; /* if CANDIDATE really means table size */
67 typedef struct hash_tuning Hash_tuning;
71 typedef struct hash_table Hash_table;
73 /* Information and lookup. */
74 size_t hash_get_n_buckets (const Hash_table *) _GL_ATTRIBUTE_PURE;
75 size_t hash_get_n_buckets_used (const Hash_table *) _GL_ATTRIBUTE_PURE;
76 size_t hash_get_n_entries (const Hash_table *) _GL_ATTRIBUTE_PURE;
77 size_t hash_get_max_bucket_length (const Hash_table *) _GL_ATTRIBUTE_PURE;
78 bool hash_table_ok (const Hash_table *) _GL_ATTRIBUTE_PURE;
79 void hash_print_statistics (const Hash_table *, FILE *);
80 void *hash_lookup (const Hash_table *, const void *);
83 void *hash_get_first (const Hash_table *) _GL_ATTRIBUTE_PURE;
84 void *hash_get_next (const Hash_table *, const void *);
85 size_t hash_get_entries (const Hash_table *, void **, size_t);
86 size_t hash_do_for_each (const Hash_table *, Hash_processor, void *);
88 /* Allocation and clean-up. */
89 size_t hash_string (const char *, size_t) _GL_ATTRIBUTE_PURE;
90 void hash_reset_tuning (Hash_tuning *);
91 Hash_table *hash_initialize (size_t, const Hash_tuning *,
92 Hash_hasher, Hash_comparator,
93 Hash_data_freer) _GL_ATTRIBUTE_WUR;
94 void hash_clear (Hash_table *);
95 void hash_free (Hash_table *);
97 /* Insertion and deletion. */
98 bool hash_rehash (Hash_table *, size_t) _GL_ATTRIBUTE_WUR;
99 void *hash_insert (Hash_table *, const void *) _GL_ATTRIBUTE_WUR;
101 /* Deprecate this interface. It has been renamed to hash_insert_if_absent. */
102 int hash_insert0 (Hash_table *table, /* FIXME: remove in 2013 */
104 const void **matched_ent) _GL_ATTRIBUTE_DEPRECATED;
105 int hash_insert_if_absent (Hash_table *table, const void *entry,
106 const void **matched_ent);
107 void *hash_delete (Hash_table *, const void *);