2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 1996-2002
5
* Sleepycat Software. All rights reserved.
14
typedef SH_TAILQ_HEAD(__hash_head) DB_HASHTAB;
19
* Look up something in a shared memory hash table. The "elt" argument
20
* should be a key, and cmp_func must know how to compare a key to whatever
21
* structure it is that appears in the hash table. The comparison function
23
* begin: address of the beginning of the hash table.
24
* ndx: index into table for this item.
25
* type: the structure type of the elements that are linked in each bucket.
26
* field: the name of the field by which the "type" structures are linked.
27
* elt: the item for which we are searching in the hash table.
28
* res: the variable into which we'll store the element if we find it.
29
* cmp: called as: cmp(lookup_elt, table_elt).
31
* If the element is not in the hash table, this macro exits with res set
34
#define HASHLOOKUP(begin, ndx, type, field, elt, res, cmp) do { \
35
DB_HASHTAB *__bucket; \
37
__bucket = &begin[ndx]; \
38
for (res = SH_TAILQ_FIRST(__bucket, type); \
39
res != NULL; res = SH_TAILQ_NEXT(res, field, type)) \
47
* Insert a new entry into the hash table. This assumes that you already
48
* have the bucket locked and that lookup has failed; don't call it if you
49
* haven't already called HASHLOOKUP. If you do, you could get duplicate
52
* begin: the beginning address of the hash table.
53
* ndx: the index for this element.
54
* type: the structure type of the elements that are linked in each bucket.
55
* field: the name of the field by which the "type" structures are linked.
56
* elt: the item to be inserted.
58
#define HASHINSERT(begin, ndx, type, field, elt) do { \
59
DB_HASHTAB *__bucket; \
61
__bucket = &begin[ndx]; \
62
SH_TAILQ_INSERT_HEAD(__bucket, elt, field, type); \
67
* Given the object "obj" in the table, remove it.
69
* begin: address of the beginning of the hash table.
70
* ndx: index into hash table of where this element belongs.
71
* type: the structure type of the elements that are linked in each bucket.
72
* field: the name of the field by which the "type" structures are linked.
73
* obj: the object in the table that we with to delete.
75
#define HASHREMOVE_EL(begin, ndx, type, field, obj) { \
76
DB_HASHTAB *__bucket; \
78
__bucket = &begin[ndx]; \
79
SH_TAILQ_REMOVE(__bucket, obj, field, type); \
81
#endif /* !_DB_SHASH_H_ */