annotate src/hash.h @ 120:cca96a509cfe r20-1b12

Import from CVS: tag r20-1b12
author cvs
date Mon, 13 Aug 2007 09:25:29 +0200
parents 376386a54a3c
children 8eaf7971accc
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 struct _C_hashtable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 hentry *harray;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 long zero_set;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 void *zero_entry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 unsigned int size; /* size of the hasharray */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 unsigned int fullness; /* number of entries in the hashtable */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 unsigned long (*hash_function) (CONST void *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 int (*test_function) (CONST void *, CONST void *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #ifdef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 Lisp_Object elisp_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 typedef struct _C_hashtable *c_hashtable;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 /* size is the number of initial entries. The hashtable will be grown
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 automatically if the number of entries approaches the size */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 c_hashtable make_hashtable (unsigned int size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 c_hashtable make_general_hashtable (unsigned int hsize,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 unsigned long (*hash_function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (CONST void *),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 int (*test_function) (CONST void *,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 CONST void *));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 c_hashtable make_strings_hashtable (unsigned int hsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 /* clears the hash table. A freshly created hashtable is already cleared up */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 void clrhash (c_hashtable hash);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 /* frees the table and substructures */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 void free_hashtable (c_hashtable hash);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 /* returns a hentry whose key is 0 if the entry does not exist in hashtable */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 CONST void *gethash (CONST void *key, c_hashtable hash,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 CONST void **ret_value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 /* key should be different from 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 void puthash (CONST void *key, void *contents, c_hashtable hash);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 /* delete the entry which key is key */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 void remhash (CONST void *key, c_hashtable hash);
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 void (*maphash_function) (CONST void* key, 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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 typedef int (*remhash_predicate) (CONST void* key, CONST void* contents,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 void* arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 typedef void (*generic_hashtable_op) (c_hashtable table,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 void *arg1, void *arg2, void *arg3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 /* calls mf with the following arguments: key, contents, arg; for every
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 entry in the hashtable */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 void maphash (maphash_function fn, c_hashtable hash, void* arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 /* delete objects from the table which satisfy the predicate */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 void map_remhash (remhash_predicate predicate, c_hashtable hash, void *arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 /* copies all the entries of src into dest -- dest is modified as needed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 so it is as big as src. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 void copy_hash (c_hashtable dest, c_hashtable src);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 /* makes sure that hashtable can hold at least needed_size entries */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 void expand_hashtable (c_hashtable hash, unsigned int needed_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 #ifdef emacs /* for elhash.c */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 unsigned int compute_harray_size (unsigned int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 #endif /* _HASH_H_ */