/**
* Key of a hash table item.
*/
- void *key;
+ const void *key;
/**
* Value of a hash table item.
/**
* Creates an empty pair object.
*/
-static inline pair_t *pair_create(void *key, void *value, u_int hash)
+static inline pair_t *pair_create(const void *key, void *value, u_int hash)
{
pair_t *this;
/*
* See header.
*/
-u_int hashtable_hash_ptr(void *key)
+u_int hashtable_hash_ptr(const void *key)
{
return chunk_hash(chunk_from_thing(key));
}
/*
* See header.
*/
-u_int hashtable_hash_str(void *key)
+u_int hashtable_hash_str(const void *key)
{
return chunk_hash(chunk_from_str((char*)key));
}
/*
* See header.
*/
-bool hashtable_equals_ptr(void *key, void *other_key)
+bool hashtable_equals_ptr(const void *key, const void *other_key)
{
return key == other_key;
}
/*
* See header.
*/
-bool hashtable_equals_str(void *key, void *other_key)
+bool hashtable_equals_str(const void *key, const void *other_key)
{
return streq(key, other_key);
}
}
METHOD(hashtable_t, put, void*,
- private_hashtable_t *this, void *key, void *value)
+ private_hashtable_t *this, const void *key, void *value)
{
void *old_value = NULL;
pair_t *pair;
return old_value;
}
-static void *get_internal(private_hashtable_t *this, void *key,
+static void *get_internal(private_hashtable_t *this, const void *key,
hashtable_equals_t equals)
{
void *value = NULL;
}
METHOD(hashtable_t, get, void*,
- private_hashtable_t *this, void *key)
+ private_hashtable_t *this, const void *key)
{
return get_internal(this, key, this->equals);
}
METHOD(hashtable_t, get_match, void*,
- private_hashtable_t *this, void *key, hashtable_equals_t match)
+ private_hashtable_t *this, const void *key, hashtable_equals_t match)
{
return get_internal(this, key, match);
}
METHOD(hashtable_t, remove_, void*,
- private_hashtable_t *this, void *key)
+ private_hashtable_t *this, const void *key)
{
void *value = NULL;
pair_t *pair, *prev = NULL;
}
METHOD(enumerator_t, enumerate, bool,
- private_enumerator_t *this, void **key, void **value)
+ private_enumerator_t *this, const void **key, void **value)
{
while (this->count && this->row < this->table->capacity)
{
* @param key key to hash
* @return hash code
*/
-typedef u_int (*hashtable_hash_t)(void *key);
+typedef u_int (*hashtable_hash_t)(const 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);
+u_int hashtable_hash_ptr(const 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);
+u_int hashtable_hash_str(const void *key);
/**
* Prototype for a function that compares the two keys for equality.
* @param other_key second key
* @return TRUE if the keys are equal
*/
-typedef bool (*hashtable_equals_t)(void *key, void *other_key);
+typedef bool (*hashtable_equals_t)(const void *key, const void *other_key);
/**
* Hashtable equals function comparing pointers.
* @param other_key other key to compare
* @return TRUE if key == other_key
*/
-bool hashtable_equals_ptr(void *key, void *other_key);
+bool hashtable_equals_ptr(const void *key, const void *other_key);
/**
* Hashtable equals function comparing char* keys.
* @param other_key other key to compare
* @return TRUE if streq(key, other_key)
*/
-bool hashtable_equals_str(void *key, void *other_key);
+bool hashtable_equals_str(const void *key, const void *other_key);
/**
* Class implementing a hash table.
* @param value the value to store
* @return NULL if no item was replaced, the old value otherwise
*/
- void *(*put) (hashtable_t *this, void *key, void *value);
+ void *(*put) (hashtable_t *this, const void *key, void *value);
/**
* Returns the value with the given key, if the hash table contains such an
* @param key the key of the requested value
* @return the value, NULL if not found
*/
- void *(*get) (hashtable_t *this, void *key);
+ void *(*get) (hashtable_t *this, const void *key);
/**
* Returns the value with a matching key, if the hash table contains such an
* @param match match function to be used when comparing keys
* @return the value, NULL if not found
*/
- void *(*get_match) (hashtable_t *this, void *key, hashtable_equals_t match);
+ void *(*get_match) (hashtable_t *this, const void *key,
+ hashtable_equals_t match);
/**
* Removes the value with the given key from the hash table and returns the
* @param key the key of the value to remove
* @return the removed value, NULL if not found
*/
- void *(*remove) (hashtable_t *this, void *key);
+ void *(*remove) (hashtable_t *this, const void *key);
/**
* Removes the key and value pair from the hash table at which the given