#include "hashtable.h"
+#include <utils/chunk.h>
+
/** The maximum capacity of the hash table (MUST be a power of 2) */
#define MAX_CAPACITY (1 << 30)
* previous pair (used by remove_at)
*/
pair_t *prev;
-
};
+/*
+ * See header.
+ */
+u_int hashtable_hash_ptr(void *key)
+{
+ return chunk_hash(chunk_from_thing(key));
+}
+
+/*
+ * See header.
+ */
+u_int hashtable_hash_str(void *key)
+{
+ return chunk_hash(chunk_from_str((char*)key));
+}
+
+/*
+ * See header.
+ */
+bool hashtable_equals_ptr(void *key, void *other_key)
+{
+ return key == other_key;
+}
+
+/*
+ * See header.
+ */
+bool hashtable_equals_str(void *key, void *other_key)
+{
+ return streq(key, other_key);
+}
+
/**
* This function returns the next-highest power of two for the given number.
* The algorithm works by setting all bits on the right-hand side of the most
return &this->public;
}
-
*/
typedef u_int (*hashtable_hash_t)(void *key);
+/**
+ * Hashtable hash function calculation the hash solely based on the key pointer.
+ *
+ * @param key key to hash
+ * @return hash of key
+ */
+u_int hashtable_hash_ptr(void *key);
+
+/**
+ * Hashtable hash function calculation the hash for char* keys.
+ *
+ * @param key key to hash, a char*
+ * @return hash of key
+ */
+u_int hashtable_hash_str(void *key);
+
/**
* Prototype for a function that compares the two keys for equality.
*
*/
typedef bool (*hashtable_equals_t)(void *key, void *other_key);
+/**
+ * Hashtable equals function comparing pointers.
+ *
+ * @param key key to compare
+ * @param other_key other key to compare
+ * @return TRUE if key == other_key
+ */
+bool hashtable_equals_ptr(void *key, void *other_key);
+
+/**
+ * Hashtable equals function comparing char* keys.
+ *
+ * @param key key to compare
+ * @param other_key other key to compare
+ * @return TRUE if streq(key, other_key)
+ */
+bool hashtable_equals_str(void *key, void *other_key);
+
/**
* Class implementing a hash table.
*
* Destroys a hash table object.
*/
void (*destroy) (hashtable_t *this);
-
};
/**