annotate src/hash.h @ 380:8626e4521993 r21-2-5

Import from CVS: tag r21-2-5
author cvs
date Mon, 13 Aug 2007 11:07:10 +0200
parents c5d627a313b1
children 7d59cb494b73
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 #ifndef _HASH_H_
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 #define _HASH_H_
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 typedef struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 CONST void *key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 void *contents;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 } hentry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
29 typedef int (*hash_table_test_function) (CONST void *, CONST void *);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
30 typedef unsigned long (*hash_table_hash_function) (CONST void *);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
31 typedef size_t hash_size_t;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
32
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
33 struct hash_table
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 hentry *harray;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 long zero_set;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 void *zero_entry;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
38 hash_size_t size; /* size of the hasharray */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
39 hash_size_t fullness; /* number of entries in the hash table */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
40 hash_table_hash_function hash_function;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
41 hash_table_test_function test_function;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
44 /* SIZE is the number of initial entries. The hash table will be grown
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
45 automatically if the number of entries approaches the size */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
46 struct hash_table *make_hash_table (hash_size_t size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
48 struct hash_table *
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
49 make_general_hash_table (hash_size_t size,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
50 hash_table_hash_function hash_function,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
51 hash_table_test_function test_function);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
53 struct hash_table *make_strings_hash_table (hash_size_t size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
55 /* Clear HASH-TABLE. A freshly created hash table is already cleared up. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
56 void clrhash (struct hash_table *hash_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
58 /* Free HASH-TABLE and its substructures */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
59 void free_hash_table (struct hash_table *hash_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
61 /* Returns a hentry whose key is 0 if the entry does not exist in HASH-TABLE */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
62 CONST void *gethash (CONST void *key, struct hash_table *hash_table,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 CONST void **ret_value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
65 /* KEY should be different from 0 */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
66 void puthash (CONST void *key, void *contents, struct hash_table *hash_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
68 /* delete the entry with key KEY */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
69 void remhash (CONST void *key, struct hash_table *hash_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
241
f955c73f5258 Import from CVS: tag r20-5b19
cvs
parents: 173
diff changeset
71 typedef int (*maphash_function) (CONST void* key, void* contents, void* arg);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 typedef int (*remhash_predicate) (CONST void* key, CONST void* contents,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 void* arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
76 typedef void (*generic_hash_table_op) (struct hash_table *hash_table,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 void *arg1, void *arg2, void *arg3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
79 /* Call MF (key, contents, arg) for every entry in HASH-TABLE */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
80 void maphash (maphash_function mf, struct hash_table *hash_table, void* arg);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
82 /* Delete all objects from HASH-TABLE satisfying PREDICATE */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
83 void map_remhash (remhash_predicate predicate,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
84 struct hash_table *hash_table, void *arg);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
86 /* Copy all the entries from SRC into DEST -- DEST is modified as needed
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
87 so it is as big as SRC. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
88 void copy_hash (struct hash_table *dest, struct hash_table *src);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
90 /* Make sure HASH-TABLE can hold at least NEEDED_SIZE entries */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
91 void expand_hash_table (struct hash_table *hash_table, hash_size_t needed_size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 #endif /* _HASH_H_ */