Added Query functions. Major renaming of stuff to use camelcase type names.
[rrq/rrqmisc.git] / vector / integeritem.c
index 57d309fd3d5dd857a252679f33d82386c46d45d9..221fb7095fce341e6fba8d974edf4c1f08d96f04 100644 (file)
@@ -1,6 +1,15 @@
 #include <integeritem.h>
 
-unsigned long integeritem_hashcode(itemkeyfun *this,void *key) {
+/**
+ * This callback function returns the hashcode of a key. The hashcode
+ * 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
+ * the hashcode index.
+ */
+static unsigned long integeritem_hashcode(void *this,void *key) {
     return (unsigned long) key;
 }
 
@@ -8,7 +17,7 @@ unsigned long integeritem_hashcode(itemkeyfun *this,void *key) {
  * This callback function determines whether an item has a
  * given key or not.
  */
-int integeritem_haskey(itemkeyfun *this,void *item,void *key) {
+static int integeritem_haskey(void *this,void *item,void *key) {
     return item == key;
 }
 
@@ -16,7 +25,7 @@ int integeritem_haskey(itemkeyfun *this,void *item,void *key) {
  * This callback function returns the key of an item by considering
  * the arity and schema.
  */
-void *integeritem_itemkey(itemkeyfun *this,void *item) {
+static void *integeritem_itemkey(void *this,void *item) {
     return item;
 }
 
@@ -24,12 +33,21 @@ void *integeritem_itemkey(itemkeyfun *this,void *item) {
  * This callback function handles a key obtained from the itemkey
  * callback function to reclaim temporary allocation.
  */
-void integeritem_releasekey(itemkeyfun *this,void *key) {
+static void integeritem_releasekey(void *this,void *key) {
+}
+
+/**
+ * This callback function writes a representation of an item into
+ * a character buffer.
+ */
+static int integeritem_tostring(void *this,void *item,char *buffer,int limit) {
+    return snprintf( buffer, limit, "%lld", (long long) item );
 }
 
-itemkeyfun integeritem = {
+ItemKeyFun integeritem = {
     .hashcode = integeritem_hashcode,
     .haskey = integeritem_haskey,
     .itemkey = integeritem_itemkey,
-    .releasekey = integeritem_releasekey
+    .releasekey = integeritem_releasekey,
+    .tostring = integeritem_tostring
 };