added explicit "unused" markers
[rrq/rrqmisc.git] / typing / 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     (void)this;
16     return HashVector_hashcode( (unsigned char*)key, strlen( (char*)key ) );
17 }
18
19 /**
20  * This callback function determines whether an item has a
21  * given key or not.
22  */
23 static int stringitem_haskey(void *this,void *item,void *key) {
24     (void)this;
25     return strcmp( item, key ) == 0;
26 }
27
28 /**
29  * This callback function returns the key of an item by considering
30  * the arity and schema.
31  */
32 static void *stringitem_itemkey(void *this,void *item) {
33     (void)this;
34     return item;
35 }
36
37 /**
38  * This callback function handles a key obtained from the itemkey
39  * callback function to reclaim temporary allocation.
40  */
41 static void stringitem_releasekey(void *this,void *key) {
42     (void)this; (void)key;
43 }
44
45 /**
46  * This callback function writes a representation of an item into
47  * a character buffer.
48  */
49 static int stringitem_tostring(void *this,void *item,char *buffer,int limit) {
50     (void)this;
51     if ( item ) {
52         return snprintf( buffer, limit, "\"%s\"", (char*) item );
53     }
54     return snprintf( buffer, limit, "(null)" );
55 }
56
57 ItemKeyFun stringitem = {
58     .hashcode = stringitem_hashcode,
59     .haskey = stringitem_haskey,
60     .itemkey = stringitem_itemkey,
61     .releasekey = stringitem_releasekey,
62     .tostring = stringitem_tostring
63 };