comparison src/hash.h @ 0:376386a54a3c r19-14

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