comparison lib/hash.h @ 4397:c6450308f123

Assume C89, so PARAMS isn't needed.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 18 Jun 2003 05:52:19 +0000
parents df44e79ce676
children 04eb43f18dc7
comparison
equal deleted inserted replaced
4396:ca90cd92b340 4397:c6450308f123
1 /* hash - hashing table processing. 1 /* hash - hashing table processing.
2 Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. 2 Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc.
3 Written by Jim Meyering <meyering@ascend.com>, 1998. 3 Written by Jim Meyering <meyering@ascend.com>, 1998.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 2, or (at your option)
24 #ifndef HASH_H_ 24 #ifndef HASH_H_
25 # define HASH_H_ 25 # define HASH_H_
26 26
27 # include <stdio.h> 27 # include <stdio.h>
28 28
29 # ifndef PARAMS 29 typedef unsigned (*Hash_hasher) (const void *, unsigned);
30 # if PROTOTYPES || __STDC__ 30 typedef bool (*Hash_comparator) (const void *, const void *);
31 # define PARAMS(Args) Args 31 typedef void (*Hash_data_freer) (void *);
32 # else 32 typedef bool (*Hash_processor) (void *, void *);
33 # define PARAMS(Args) ()
34 # endif
35 # endif
36
37 typedef unsigned (*Hash_hasher) PARAMS ((const void *, unsigned));
38 typedef bool (*Hash_comparator) PARAMS ((const void *, const void *));
39 typedef void (*Hash_data_freer) PARAMS ((void *));
40 typedef bool (*Hash_processor) PARAMS ((void *, void *));
41 33
42 struct hash_entry 34 struct hash_entry
43 { 35 {
44 void *data; 36 void *data;
45 struct hash_entry *next; 37 struct hash_entry *next;
62 struct hash_table; 54 struct hash_table;
63 55
64 typedef struct hash_table Hash_table; 56 typedef struct hash_table Hash_table;
65 57
66 /* Information and lookup. */ 58 /* Information and lookup. */
67 unsigned hash_get_n_buckets PARAMS ((const Hash_table *)); 59 unsigned hash_get_n_buckets (const Hash_table *);
68 unsigned hash_get_n_buckets_used PARAMS ((const Hash_table *)); 60 unsigned hash_get_n_buckets_used (const Hash_table *);
69 unsigned hash_get_n_entries PARAMS ((const Hash_table *)); 61 unsigned hash_get_n_entries (const Hash_table *);
70 unsigned hash_get_max_bucket_length PARAMS ((const Hash_table *)); 62 unsigned hash_get_max_bucket_length (const Hash_table *);
71 bool hash_table_ok PARAMS ((const Hash_table *)); 63 bool hash_table_ok (const Hash_table *);
72 void hash_print_statistics PARAMS ((const Hash_table *, FILE *)); 64 void hash_print_statistics (const Hash_table *, FILE *);
73 void *hash_lookup PARAMS ((const Hash_table *, const void *)); 65 void *hash_lookup (const Hash_table *, const void *);
74 66
75 /* Walking. */ 67 /* Walking. */
76 void *hash_get_first PARAMS ((const Hash_table *)); 68 void *hash_get_first (const Hash_table *);
77 void *hash_get_next PARAMS ((const Hash_table *, const void *)); 69 void *hash_get_next (const Hash_table *, const void *);
78 unsigned hash_get_entries PARAMS ((const Hash_table *, void **, unsigned)); 70 unsigned hash_get_entries (const Hash_table *, void **, unsigned);
79 unsigned hash_do_for_each PARAMS ((const Hash_table *, Hash_processor, void *)); 71 unsigned hash_do_for_each (const Hash_table *, Hash_processor, void *);
80 72
81 /* Allocation and clean-up. */ 73 /* Allocation and clean-up. */
82 unsigned hash_string PARAMS ((const char *, unsigned)); 74 unsigned hash_string (const char *, unsigned);
83 void hash_reset_tuning PARAMS ((Hash_tuning *)); 75 void hash_reset_tuning (Hash_tuning *);
84 Hash_table *hash_initialize PARAMS ((unsigned, const Hash_tuning *, 76 Hash_table *hash_initialize (unsigned, const Hash_tuning *,
85 Hash_hasher, Hash_comparator, 77 Hash_hasher, Hash_comparator,
86 Hash_data_freer)); 78 Hash_data_freer);
87 void hash_clear PARAMS ((Hash_table *)); 79 void hash_clear (Hash_table *);
88 void hash_free PARAMS ((Hash_table *)); 80 void hash_free (Hash_table *);
89 81
90 /* Insertion and deletion. */ 82 /* Insertion and deletion. */
91 bool hash_rehash PARAMS ((Hash_table *, unsigned)); 83 bool hash_rehash (Hash_table *, unsigned);
92 void *hash_insert PARAMS ((Hash_table *, const void *)); 84 void *hash_insert (Hash_table *, const void *);
93 void *hash_delete PARAMS ((Hash_table *, const void *)); 85 void *hash_delete (Hash_table *, const void *);
94 86
95 #endif 87 #endif