annotate src/hash.h @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents 74fd4e045ea6
children
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
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
20 #ifndef _HASH_H_
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
21 #define _HASH_H_
0
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 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
25 CONST void *key;
0
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
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
29 typedef int (*hash_table_test_function) (CONST void *, CONST void *);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
30 typedef unsigned long (*hash_table_hash_function) (CONST void *);
380
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 /* 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
54 void clrhash (struct hash_table *hash_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
56 /* Free HASH-TABLE and its substructures */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
57 void free_hash_table (struct hash_table *hash_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
59 /* Returns a hentry whose key is 0 if the entry does not exist in HASH-TABLE */
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
60 CONST void *gethash (CONST void *key, struct hash_table *hash_table,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
61 CONST void **ret_value);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
63 /* KEY should be different from 0 */
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
64 void puthash (CONST void *key, void *contents, struct hash_table *hash_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
66 /* delete the entry with key KEY */
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
67 void remhash (CONST void *key, struct hash_table *hash_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
69 typedef int (*maphash_function) (CONST void* key, void* contents, void* arg);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
71 typedef int (*remhash_predicate) (CONST void* key, CONST void* contents,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 void* arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
74 /* Call MF (key, contents, arg) for every entry in HASH-TABLE */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
75 void maphash (maphash_function mf, struct hash_table *hash_table, void* arg);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
77 /* Delete all objects from HASH-TABLE satisfying PREDICATE */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
78 void map_remhash (remhash_predicate predicate,
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 272
diff changeset
79 struct hash_table *hash_table, void *arg);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 398
diff changeset
81 #endif /* _HASH_H_ */