00001 /*- 00002 * See the file LICENSE for redistribution information. 00003 * 00004 * Copyright (c) 1996-2005 00005 * Sleepycat Software. All rights reserved. 00006 * 00007 * $Id: db_shash.h,v 12.1 2005/06/16 20:21:47 bostic Exp $ 00008 */ 00009 00010 #ifndef _DB_SHASH_H_ 00011 #define _DB_SHASH_H_ 00012 00013 /* Hash Headers */ 00014 typedef SH_TAILQ_HEAD(__hash_head) DB_HASHTAB; 00015 00016 /* 00017 * HASHLOOKUP -- 00018 * 00019 * Look up something in a shared memory hash table. The "elt" argument 00020 * should be a key, and cmp_func must know how to compare a key to whatever 00021 * structure it is that appears in the hash table. The comparison function 00022 * 00023 * begin: address of the beginning of the hash table. 00024 * ndx: index into table for this item. 00025 * type: the structure type of the elements that are linked in each bucket. 00026 * field: the name of the field by which the "type" structures are linked. 00027 * elt: the item for which we are searching in the hash table. 00028 * res: the variable into which we'll store the element if we find it. 00029 * cmp: called as: cmp(lookup_elt, table_elt). 00030 * 00031 * If the element is not in the hash table, this macro exits with res set 00032 * to NULL. 00033 */ 00034 #define HASHLOOKUP(begin, ndx, type, field, elt, res, cmp) do { \ 00035 DB_HASHTAB *__bucket; \ 00036 \ 00037 __bucket = &begin[ndx]; \ 00038 for (res = SH_TAILQ_FIRST(__bucket, type); \ 00039 res != NULL; res = SH_TAILQ_NEXT(res, field, type)) \ 00040 if (cmp(elt, res)) \ 00041 break; \ 00042 } while (0) 00043 00044 /* 00045 * HASHINSERT -- 00046 * 00047 * Insert a new entry into the hash table. This assumes that you already 00048 * have the bucket locked and that lookup has failed; don't call it if you 00049 * haven't already called HASHLOOKUP. If you do, you could get duplicate 00050 * entries. 00051 * 00052 * begin: the beginning address of the hash table. 00053 * ndx: the index for this element. 00054 * type: the structure type of the elements that are linked in each bucket. 00055 * field: the name of the field by which the "type" structures are linked. 00056 * elt: the item to be inserted. 00057 */ 00058 #define HASHINSERT(begin, ndx, type, field, elt) do { \ 00059 DB_HASHTAB *__bucket; \ 00060 \ 00061 __bucket = &begin[ndx]; \ 00062 SH_TAILQ_INSERT_HEAD(__bucket, elt, field, type); \ 00063 } while (0) 00064 00065 /* 00066 * HASHREMOVE_EL -- 00067 * Given the object "obj" in the table, remove it. 00068 * 00069 * begin: address of the beginning of the hash table. 00070 * ndx: index into hash table of where this element belongs. 00071 * type: the structure type of the elements that are linked in each bucket. 00072 * field: the name of the field by which the "type" structures are linked. 00073 * obj: the object in the table that we with to delete. 00074 */ 00075 #define HASHREMOVE_EL(begin, ndx, type, field, obj) { \ 00076 DB_HASHTAB *__bucket; \ 00077 \ 00078 __bucket = &begin[ndx]; \ 00079 SH_TAILQ_REMOVE(__bucket, obj, field, type); \ 00080 } 00081 #endif /* !_DB_SHASH_H_ */