Mercurial > hg > xemacs-beta
comparison 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 |
comparison
equal
deleted
inserted
replaced
379:76b7d63099ad | 380:8626e4521993 |
---|---|
24 { | 24 { |
25 CONST void *key; | 25 CONST void *key; |
26 void *contents; | 26 void *contents; |
27 } hentry; | 27 } hentry; |
28 | 28 |
29 struct _C_hashtable | 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 | |
30 { | 34 { |
31 hentry *harray; | 35 hentry *harray; |
32 long zero_set; | 36 long zero_set; |
33 void *zero_entry; | 37 void *zero_entry; |
34 size_t size; /* size of the hasharray */ | 38 hash_size_t size; /* size of the hasharray */ |
35 unsigned int fullness; /* number of entries in the hashtable */ | 39 hash_size_t fullness; /* number of entries in the hash table */ |
36 unsigned long (*hash_function) (CONST void *); | 40 hash_table_hash_function hash_function; |
37 int (*test_function) (CONST void *, CONST void *); | 41 hash_table_test_function test_function; |
38 #ifdef emacs | |
39 Lisp_Object elisp_table; | |
40 #endif | |
41 }; | 42 }; |
42 | 43 |
43 typedef struct _C_hashtable *c_hashtable; | 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); | |
44 | 47 |
45 /* size is the number of initial entries. The hashtable will be grown | 48 struct hash_table * |
46 automatically if the number of entries approaches the size */ | 49 make_general_hash_table (hash_size_t size, |
47 c_hashtable make_hashtable (unsigned int size); | 50 hash_table_hash_function hash_function, |
51 hash_table_test_function test_function); | |
48 | 52 |
49 c_hashtable make_general_hashtable (unsigned int hsize, | 53 struct hash_table *make_strings_hash_table (hash_size_t size); |
50 unsigned long (*hash_function) | |
51 (CONST void *), | |
52 int (*test_function) (CONST void *, | |
53 CONST void *)); | |
54 | 54 |
55 c_hashtable make_strings_hashtable (unsigned int hsize); | 55 /* Clear HASH-TABLE. A freshly created hash table is already cleared up. */ |
56 void clrhash (struct hash_table *hash_table); | |
56 | 57 |
57 /* clears the hash table. A freshly created hashtable is already cleared up */ | 58 /* Free HASH-TABLE and its substructures */ |
58 void clrhash (c_hashtable hash); | 59 void free_hash_table (struct hash_table *hash_table); |
59 | 60 |
60 /* frees the table and substructures */ | 61 /* Returns a hentry whose key is 0 if the entry does not exist in HASH-TABLE */ |
61 void free_hashtable (c_hashtable hash); | 62 CONST void *gethash (CONST void *key, struct hash_table *hash_table, |
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); | 63 CONST void **ret_value); |
66 | 64 |
67 /* key should be different from 0 */ | 65 /* KEY should be different from 0 */ |
68 void puthash (CONST void *key, void *contents, c_hashtable hash); | 66 void puthash (CONST void *key, void *contents, struct hash_table *hash_table); |
69 | 67 |
70 /* delete the entry which key is key */ | 68 /* delete the entry with key KEY */ |
71 void remhash (CONST void *key, c_hashtable hash); | 69 void remhash (CONST void *key, struct hash_table *hash_table); |
72 | 70 |
73 typedef int (*maphash_function) (CONST void* key, void* contents, void* arg); | 71 typedef int (*maphash_function) (CONST void* key, void* contents, void* arg); |
74 | 72 |
75 typedef int (*remhash_predicate) (CONST void* key, CONST void* contents, | 73 typedef int (*remhash_predicate) (CONST void* key, CONST void* contents, |
76 void* arg); | 74 void* arg); |
77 | 75 |
78 typedef void (*generic_hashtable_op) (c_hashtable table, | 76 typedef void (*generic_hash_table_op) (struct hash_table *hash_table, |
79 void *arg1, void *arg2, void *arg3); | 77 void *arg1, void *arg2, void *arg3); |
80 | 78 |
81 /* calls mf with the following arguments: key, contents, arg; for every | 79 /* Call MF (key, contents, arg) for every entry in HASH-TABLE */ |
82 entry in the hashtable */ | 80 void maphash (maphash_function mf, struct hash_table *hash_table, void* arg); |
83 void maphash (maphash_function fn, c_hashtable hash, void* arg); | |
84 | 81 |
85 /* delete objects from the table which satisfy the predicate */ | 82 /* Delete all objects from HASH-TABLE satisfying PREDICATE */ |
86 void map_remhash (remhash_predicate predicate, c_hashtable hash, void *arg); | 83 void map_remhash (remhash_predicate predicate, |
84 struct hash_table *hash_table, void *arg); | |
87 | 85 |
88 /* copies all the entries of src into dest -- dest is modified as needed | 86 /* Copy all the entries from SRC into DEST -- DEST is modified as needed |
89 so it is as big as src. */ | 87 so it is as big as SRC. */ |
90 void copy_hash (c_hashtable dest, c_hashtable src); | 88 void copy_hash (struct hash_table *dest, struct hash_table *src); |
91 | 89 |
92 /* makes sure that hashtable can hold at least needed_size entries */ | 90 /* Make sure HASH-TABLE can hold at least NEEDED_SIZE entries */ |
93 void expand_hashtable (c_hashtable hash, unsigned int needed_size); | 91 void expand_hash_table (struct hash_table *hash_table, hash_size_t needed_size); |
94 | |
95 #ifdef emacs /* for elhash.c */ | |
96 unsigned int compute_harray_size (unsigned int); | |
97 #endif | |
98 | 92 |
99 #endif /* _HASH_H_ */ | 93 #endif /* _HASH_H_ */ |