aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2012-05-24 12:54:38 +0200
committerTobias Brunner <tobias@strongswan.org>2012-05-24 15:15:34 +0200
commit0e5d587df7914be7b8ed6d8ffdefc0b9b437d974 (patch)
tree2d0ff3609a78fcff7c6ec7583c6381b077f0e9b3
parentfa50a89c950118a5da9aa10608dab143ed952ffb (diff)
downloadstrongswan-0e5d587df7914be7b8ed6d8ffdefc0b9b437d974.tar.bz2
strongswan-0e5d587df7914be7b8ed6d8ffdefc0b9b437d974.tar.xz
get_match() method added to hashtable_t.
-rw-r--r--src/libstrongswan/utils/hashtable.c21
-rw-r--r--src/libstrongswan/utils/hashtable.h18
2 files changed, 34 insertions, 5 deletions
diff --git a/src/libstrongswan/utils/hashtable.c b/src/libstrongswan/utils/hashtable.c
index 33f645170..498d107e3 100644
--- a/src/libstrongswan/utils/hashtable.c
+++ b/src/libstrongswan/utils/hashtable.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2011 Tobias Brunner
+ * Copyright (C) 2008-2012 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -251,8 +251,8 @@ METHOD(hashtable_t, put, void*,
return old_value;
}
-METHOD(hashtable_t, get, void*,
- private_hashtable_t *this, void *key)
+static void *get_internal(private_hashtable_t *this, void *key,
+ hashtable_equals_t equals)
{
void *value = NULL;
pair_t *pair;
@@ -260,7 +260,7 @@ METHOD(hashtable_t, get, void*,
pair = this->table[this->hash(key) & this->mask];
while (pair)
{
- if (this->equals(key, pair->key))
+ if (equals(key, pair->key))
{
value = pair->value;
break;
@@ -270,6 +270,18 @@ METHOD(hashtable_t, get, void*,
return value;
}
+METHOD(hashtable_t, get, void*,
+ private_hashtable_t *this, 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)
+{
+ return get_internal(this, key, match);
+}
+
METHOD(hashtable_t, remove_, void*,
private_hashtable_t *this, void *key)
{
@@ -409,6 +421,7 @@ hashtable_t *hashtable_create(hashtable_hash_t hash, hashtable_equals_t equals,
.public = {
.put = _put,
.get = _get,
+ .get_match = _get_match,
.remove = _remove_,
.remove_at = (void*)_remove_at,
.get_count = _get_count,
diff --git a/src/libstrongswan/utils/hashtable.h b/src/libstrongswan/utils/hashtable.h
index 27aca9b68..0a21ca373 100644
--- a/src/libstrongswan/utils/hashtable.h
+++ b/src/libstrongswan/utils/hashtable.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2010 Tobias Brunner
+ * Copyright (C) 2008-2012 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -78,6 +78,22 @@ struct hashtable_t {
void *(*get) (hashtable_t *this, void *key);
/**
+ * Returns the value with a matching key, if the hash table contains such an
+ * entry, otherwise NULL is returned.
+ *
+ * Compared to get() the given match function is used to compare the keys
+ * for equality. The hash function does have to be deviced properly in
+ * order to make this work if the match function compares keys differently
+ * than the equals function provided to the constructor. This basically
+ * allows to enumerate all entries with the same hash value.
+ *
+ * @param key the key to match against
+ * @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);
+
+ /**
* Removes the value with the given key from the hash table and returns the
* removed value (or NULL if no such value existed).
*