db400cebc8f33c54b5a126277dd7971f17446a2a
[rrq/rrqmisc.git] / vector / stringitem.c
1 #include <string.h>
2 #include <stringitem.h>
3 #include <hashvector.h>
4
5 /**
6  * This callback function returns the hashcode of a key. The hashcode
7  * is used for indexing into the backing vector for finding the an
8  * item via its key. The same key must map consistently to the same
9  * hashcode while the hashtable contains an item with that key.
10  * Different keys map map to the same hashcode, in which case the
11  * vector placement is made at the first empty or hole slot following
12  * the hashcode index.
13  */
14 static unsigned long stringitem_hashcode(void *this,void *key) {
15     return hashvector_hashcode( (unsigned char*)key, strlen( (char*)key ) );
16 }
17
18 /**
19  * This callback function determines whether an item has a
20  * given key or not.
21  */
22 static int stringitem_haskey(void *this,void *item,void *key) {
23     return strcmp( item, key ) == 0;
24 }
25
26 /**
27  * This callback function returns the key of an item by considering
28  * the arity and schema.
29  */
30 static void *stringitem_itemkey(void *this,void *item) {
31     return item;
32 }
33
34 /**
35  * This callback function handles a key obtained from the itemkey
36  * callback function to reclaim temporary allocation.
37  */
38 static void stringitem_releasekey(void *this,void *key) {
39 }
40
41 itemkeyfun stringitem = {
42     .hashcode = stringitem_hashcode,
43     .haskey = stringitem_haskey,
44     .itemkey = stringitem_itemkey,
45     .releasekey = stringitem_releasekey
46 };