return 0;
}
+/*****************************************************************************/
+int /* checks if key exists */
+hashtable_exists(struct hashtable *h, void *k)
+{
+ struct entry *e;
+ unsigned int hashvalue, index;
+
+ hashvalue = hash(h, k);
+ index = indexFor(h->tablelength, hashvalue);
+ e = h->table[index];
+
+ while (e != NULL)
+ {
+ /* Check hash value to short circuit heavier comparison */
+ if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
+ return 1;
+
+ e = e->next;
+ }
+
+ return 0;
+}
+
/*****************************************************************************/
void * /* returns value associated with key */
hashtable_search(struct hashtable *h, void *k)
return hashtable_change(h, k, v); \
}
+/*****************************************************************************
+ * hashtable_exists
+
+ * @name hashtable_exists
+ * @param h the hashtable to search
+ * @param k the key to search for
+ * @return non-zero if key exists, else zero
+ */
+
+int
+hashtable_exists(struct hashtable *h, void *k);
+
+#define DEFINE_HASHTABLE_EXISTS(fnname, keytype, valuetype) \
+static int fnname (struct hashtable *h, keytype *k) \
+{ \
+ return hashtable_exists(h, k); \
+}
+
/*****************************************************************************
* hashtable_search