Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/hash.h @ 7675:476857ef4611
* lib/idcache.c: Adjust comments in user- and group- portions to
be more accurate, and to be consistent with one another.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Mon, 20 Nov 2006 13:08:38 +0000 |
parents | a48fb0e98c8c |
children | bbbbbf4cd1c5 |
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. |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
2 Copyright (C) 1998, 1999, 2001, 2003 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, |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
4813
diff
changeset
|
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 |
4347
df44e79ce676
.h files should stand alone, but we shouldn't include <sys/types.h>
Paul Eggert <eggert@cs.ucla.edu>
parents:
3646
diff
changeset
|
27 # include <stdio.h> |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
28 # include <stdbool.h> |
4347
df44e79ce676
.h files should stand alone, but we shouldn't include <sys/types.h>
Paul Eggert <eggert@cs.ucla.edu>
parents:
3646
diff
changeset
|
29 |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
30 typedef size_t (*Hash_hasher) (const void *, size_t); |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
31 typedef bool (*Hash_comparator) (const void *, const void *); |
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
32 typedef void (*Hash_data_freer) (void *); |
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
33 typedef bool (*Hash_processor) (void *, void *); |
1031 | 34 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
35 struct hash_entry |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
36 { |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
37 void *data; |
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
38 struct hash_entry *next; |
1031 | 39 }; |
40 | |
1741
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
41 struct hash_tuning |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
42 { |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
43 /* 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
|
44 documentation of `hash_reset_tuning' for more complete comments. */ |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
45 |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 bool is_n_buckets; /* if CANDIDATE really means table size */ |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
51 }; |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
52 |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
53 typedef struct hash_tuning Hash_tuning; |
fbd0de3235db
(struct hash_tuning): Define.
Jim Meyering <jim@meyering.net>
parents:
1740
diff
changeset
|
54 |
3646
1f095040c850
(struct hash_table): Don't define here. Merely declare it.
Jim Meyering <jim@meyering.net>
parents:
3643
diff
changeset
|
55 struct hash_table; |
1031 | 56 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
57 typedef struct hash_table Hash_table; |
1031 | 58 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
59 /* Information and lookup. */ |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
60 size_t hash_get_n_buckets (const Hash_table *); |
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
61 size_t hash_get_n_buckets_used (const Hash_table *); |
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
62 size_t hash_get_n_entries (const Hash_table *); |
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
63 size_t hash_get_max_bucket_length (const Hash_table *); |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
64 bool hash_table_ok (const Hash_table *); |
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
65 void hash_print_statistics (const Hash_table *, FILE *); |
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
66 void *hash_lookup (const Hash_table *, const void *); |
1031 | 67 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
68 /* Walking. */ |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
69 void *hash_get_first (const Hash_table *); |
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
70 void *hash_get_next (const Hash_table *, const void *); |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
71 size_t hash_get_entries (const Hash_table *, void **, size_t); |
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
72 size_t hash_do_for_each (const Hash_table *, Hash_processor, void *); |
1031 | 73 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
74 /* Allocation and clean-up. */ |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
75 size_t hash_string (const char *, size_t); |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
76 void hash_reset_tuning (Hash_tuning *); |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
77 Hash_table *hash_initialize (size_t, const Hash_tuning *, |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
78 Hash_hasher, Hash_comparator, |
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
79 Hash_data_freer); |
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
80 void hash_clear (Hash_table *); |
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
81 void hash_free (Hash_table *); |
1031 | 82 |
1311
20f35a1b786a
Lots of minor spec and name changes, and new comments.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
83 /* Insertion and deletion. */ |
4813
04eb43f18dc7
Fix several address-calculation bugs in the hash modules,
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
84 bool hash_rehash (Hash_table *, size_t); |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
85 void *hash_insert (Hash_table *, const void *); |
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
86 void *hash_delete (Hash_table *, const void *); |
3643
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
87 |
08373aedb4b6
Bracket contents of file with #ifndef HASH_H_ ... #endif.
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
88 #endif |