#include <string.h>
#include <stringitem.h>
-#include <hashvector.h>
+#include <HashVector.h>
/**
* This callback function returns the hashcode of a key. The hashcode
- * is used for indexing into the backing vector for finding the an
+ * is used for indexing into the backing Vector for finding the an
* item via its key. The same key must map consistently to the same
* hashcode while the hashtable contains an item with that key.
* Different keys map map to the same hashcode, in which case the
- * vector placement is made at the first empty or hole slot following
+ * Vector placement is made at the first empty or hole slot following
* the hashcode index.
*/
-static unsigned long stringitem_hashcode(itemkeyfun *this,void *key) {
- return hashvector_hashcode( (unsigned char*)key, strlen( (char*)key ) );
+static unsigned long stringitem_hashcode(void *this,void *key) {
+ return HashVector_hashcode( (unsigned char*)key, strlen( (char*)key ) );
}
/**
* This callback function determines whether an item has a
* given key or not.
*/
-static int stringitem_haskey(itemkeyfun *this,void *item,void *key) {
+static int stringitem_haskey(void *this,void *item,void *key) {
return strcmp( item, key ) == 0;
}
* This callback function returns the key of an item by considering
* the arity and schema.
*/
-static void *stringitem_itemkey(itemkeyfun *this,void *item) {
+static void *stringitem_itemkey(void *this,void *item) {
return item;
}
* This callback function handles a key obtained from the itemkey
* callback function to reclaim temporary allocation.
*/
-static void stringitem_releasekey(itemkeyfun *this,void *key) {
+static void stringitem_releasekey(void *this,void *key) {
}
-itemkeyfun stringitem = {
+/**
+ * This callback function writes a representation of an item into
+ * a character buffer.
+ */
+static int stringitem_tostring(void *this,void *item,char *buffer,int limit) {
+ if ( item ) {
+ return snprintf( buffer, limit, "\"%s\"", (char*) item );
+ }
+ return snprintf( buffer, limit, "(null)" );
+}
+
+ItemKeyFun stringitem = {
.hashcode = stringitem_hashcode,
.haskey = stringitem_haskey,
.itemkey = stringitem_itemkey,
- .releasekey = stringitem_releasekey
+ .releasekey = stringitem_releasekey,
+ .tostring = stringitem_tostring
};