comparison src/hash.h @ 428:3ecd8885ac67 r21-2-22

Import from CVS: tag r21-2-22
author cvs
date Mon, 13 Aug 2007 11:28:15 +0200
parents
children 8de8e3f6228a
comparison
equal deleted inserted replaced
427:0a0253eac470 428:3ecd8885ac67
1 /* This file is part of XEmacs.
2
3 XEmacs is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2, or (at your option) any
6 later version.
7
8 XEmacs is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with XEmacs; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA. */
17
18 /* Synched up with: Not in FSF. */
19
20 #ifndef _HASH_H_
21 #define _HASH_H_
22
23 typedef struct
24 {
25 CONST void *key;
26 void *contents;
27 } hentry;
28
29 typedef int (*hash_table_test_function) (CONST void *, CONST void *);
30 typedef unsigned long (*hash_table_hash_function) (CONST void *);
31 typedef size_t hash_size_t;
32
33 struct hash_table
34 {
35 hentry *harray;
36 long zero_set;
37 void *zero_entry;
38 hash_size_t size; /* size of the hasharray */
39 hash_size_t fullness; /* number of entries in the hash table */
40 hash_table_hash_function hash_function;
41 hash_table_test_function test_function;
42 };
43
44 /* SIZE is the number of initial entries. The hash table will be grown
45 automatically if the number of entries approaches the size */
46 struct hash_table *make_hash_table (hash_size_t size);
47
48 struct hash_table *
49 make_general_hash_table (hash_size_t size,
50 hash_table_hash_function hash_function,
51 hash_table_test_function test_function);
52
53 /* Clear HASH-TABLE. A freshly created hash table is already cleared up. */
54 void clrhash (struct hash_table *hash_table);
55
56 /* Free HASH-TABLE and its substructures */
57 void free_hash_table (struct hash_table *hash_table);
58
59 /* Returns a hentry whose key is 0 if the entry does not exist in HASH-TABLE */
60 CONST void *gethash (CONST void *key, struct hash_table *hash_table,
61 CONST void **ret_value);
62
63 /* KEY should be different from 0 */
64 void puthash (CONST void *key, void *contents, struct hash_table *hash_table);
65
66 /* delete the entry with key KEY */
67 void remhash (CONST void *key, struct hash_table *hash_table);
68
69 typedef int (*maphash_function) (CONST void* key, void* contents, void* arg);
70
71 typedef int (*remhash_predicate) (CONST void* key, CONST void* contents,
72 void* arg);
73
74 /* Call MF (key, contents, arg) for every entry in HASH-TABLE */
75 void maphash (maphash_function mf, struct hash_table *hash_table, void* arg);
76
77 /* Delete all objects from HASH-TABLE satisfying PREDICATE */
78 void map_remhash (remhash_predicate predicate,
79 struct hash_table *hash_table, void *arg);
80
81 #endif /* _HASH_H_ */