X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vector%2Fstringitem.c;h=ee8f2cba74695f39f16faf47eb8aaa4facd3d9cf;hb=6fcd4ffc18696dbf4c11be32837a2035ea5ee92f;hp=db400cebc8f33c54b5a126277dd7971f17446a2a;hpb=e7cfb732dbf345432b0832c32b99b17a1741b206;p=rrq%2Frrqmisc.git diff --git a/vector/stringitem.c b/vector/stringitem.c index db400ce..ee8f2cb 100644 --- a/vector/stringitem.c +++ b/vector/stringitem.c @@ -1,18 +1,18 @@ #include #include -#include +#include /** * 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(void *this,void *key) { - return hashvector_hashcode( (unsigned char*)key, strlen( (char*)key ) ); + return HashVector_hashcode( (unsigned char*)key, strlen( (char*)key ) ); } /** @@ -38,9 +38,21 @@ static void *stringitem_itemkey(void *this,void *item) { 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 };