Mercurial > hg > octave-kai > gnulib-hg
annotate lib/hash.h @ 4120:77d7a6d46166
(memcoll): Fall back on a simple algorithm using
memcmp if strcoll doesn't work.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 31 Dec 2002 22:11:34 +0000 |
parents | 1f095040c850 |
children | df44e79ce676 |
rev | line source |
---|---|
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
1 /* hash - hashing table processing. |
3643
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
2 Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
3 Written by Jim Meyering <meyering@ascend.com>, 1998. |
1031 | 4 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
5 This program is free software; you can redistribute it and/or modify |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
7 the Free Software Foundation; either version 2, or (at your option) |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
8 any later version. |
1032
0b6b7e10fe5f
use HASH_H, not _hash_h_ in #ifndef
Jim Meyering <jim@meyering.net>
parents:
1031
diff
changeset
|
9 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
13 GNU General Public License for more details. |
1170 | 14 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
16 along with this program; if not, write to the Free Software Foundation, |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
1031 | 18 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
19 /* A generic hash table package. */ |
1031 | 20 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
21 /* Make sure USE_OBSTACK is defined to 1 if you want the allocator to use |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
22 obstacks instead of malloc, and recompile `hash.c' with same setting. */ |
1031 | 23 |
3643
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
24 #ifndef HASH_H_ |
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
25 # define HASH_H_ |
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
26 |
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
27 # ifndef PARAMS |
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
28 # if PROTOTYPES || __STDC__ |
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
29 # define PARAMS(Args) Args |
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
30 # else |
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
31 # define PARAMS(Args) () |
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
32 # endif |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
33 # endif |
1031 | 34 |
1741
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
35 typedef unsigned (*Hash_hasher) PARAMS ((const void *, unsigned)); |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
36 typedef bool (*Hash_comparator) PARAMS ((const void *, const void *)); |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
37 typedef void (*Hash_data_freer) PARAMS ((void *)); |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
38 typedef bool (*Hash_processor) PARAMS ((void *, void *)); |
1031 | 39 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
40 struct hash_entry |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
41 { |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
42 void *data; |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
43 struct hash_entry *next; |
1031 | 44 }; |
45 | |
1741
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
46 struct hash_tuning |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
47 { |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
48 /* This structure is mainly used for `hash_initialize', see the block |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
49 documentation of `hash_reset_tuning' for more complete comments. */ |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
50 |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
51 float shrink_threshold; /* ratio of used buckets to trigger a shrink */ |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
52 float shrink_factor; /* ratio of new smaller size to original size */ |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
53 float growth_threshold; /* ratio of used buckets to trigger a growth */ |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
54 float growth_factor; /* ratio of new bigger size to original size */ |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
55 bool is_n_buckets; /* if CANDIDATE really means table size */ |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
56 }; |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
57 |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
58 typedef struct hash_tuning Hash_tuning; |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
59 |
3646
1f095040c850
(struct hash_table): Don't define here. Merely declare it.
Jim Meyering <jim@meyering.net>
parents:
3643
diff
changeset
|
60 struct hash_table; |
1031 | 61 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
62 typedef struct hash_table Hash_table; |
1031 | 63 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
64 /* Information and lookup. */ |
1741
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
65 unsigned hash_get_n_buckets PARAMS ((const Hash_table *)); |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
66 unsigned hash_get_n_buckets_used PARAMS ((const Hash_table *)); |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
67 unsigned hash_get_n_entries PARAMS ((const Hash_table *)); |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
68 unsigned hash_get_max_bucket_length PARAMS ((const Hash_table *)); |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
69 bool hash_table_ok PARAMS ((const Hash_table *)); |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
70 void hash_print_statistics PARAMS ((const Hash_table *, FILE *)); |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
71 void *hash_lookup PARAMS ((const Hash_table *, const void *)); |
1031 | 72 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
73 /* Walking. */ |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
74 void *hash_get_first PARAMS ((const Hash_table *)); |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
75 void *hash_get_next PARAMS ((const Hash_table *, const void *)); |
1741
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
76 unsigned hash_get_entries PARAMS ((const Hash_table *, void **, unsigned)); |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
77 unsigned hash_do_for_each PARAMS ((const Hash_table *, Hash_processor, void *)); |
1031 | 78 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
79 /* Allocation and clean-up. */ |
1741
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
80 unsigned hash_string PARAMS ((const char *, unsigned)); |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
81 void hash_reset_tuning PARAMS ((Hash_tuning *)); |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
82 Hash_table *hash_initialize PARAMS ((unsigned, const Hash_tuning *, |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
83 Hash_hasher, Hash_comparator, |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
84 Hash_data_freer)); |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
85 void hash_clear PARAMS ((Hash_table *)); |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
86 void hash_free PARAMS ((Hash_table *)); |
1031 | 87 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
88 /* Insertion and deletion. */ |
1741
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
89 bool hash_rehash PARAMS ((Hash_table *, unsigned)); |
1740
99255b403d74
(hash_insert): Update prototype.
Jim Meyering <jim@meyering.net>
parents:
1311
diff
changeset
|
90 void *hash_insert PARAMS ((Hash_table *, const void *)); |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
91 void *hash_delete PARAMS ((Hash_table *, const void *)); |
3643
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
92 |
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
93 #endif |