From: Yu Nemo Wenbin <yuwb_bjy@ctbri.com.cn>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] hash: add rte_hash_set_cmp_func() function.
Date: Fri, 27 Nov 2015 10:11:00 +0800 [thread overview]
Message-ID: <1448590260-15382-1-git-send-email-yuwb_bjy@ctbri.com.cn> (raw)
Give user a chance to customize the hash key compare function.
The default rte_hash_cmp_eq function is set in the rte_hash_create
function, but these builtin ones may not be good enough, so the user
may call this to override the default one.
Signed-off-by: Yu Nemo Wenbin <yuwb_bjy@ctbri.com.cn>
---
lib/librte_hash/rte_cuckoo_hash.c | 7 +++++--
lib/librte_hash/rte_hash.h | 15 +++++++++++++++
lib/librte_hash/rte_hash_version.map | 7 +++++++
3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 88f77c3..2ccb81c 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -102,8 +102,6 @@ EAL_REGISTER_TAILQ(rte_hash_tailq)
#define LCORE_CACHE_SIZE 8
-typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len);
-
struct lcore_cache {
unsigned len; /**< Cache len */
void *objs[LCORE_CACHE_SIZE]; /**< Cache objects */
@@ -187,6 +185,11 @@ rte_hash_find_existing(const char *name)
return h;
}
+void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func)
+{
+ h->rte_hash_cmp_eq = func;
+}
+
struct rte_hash *
rte_hash_create(const struct rte_hash_parameters *params)
{
diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h
index b678766..dfca5ef 100644
--- a/lib/librte_hash/rte_hash.h
+++ b/lib/librte_hash/rte_hash.h
@@ -66,6 +66,9 @@ typedef uint32_t hash_sig_t;
typedef uint32_t (*rte_hash_function)(const void *key, uint32_t key_len,
uint32_t init_val);
+/** Type of function used to compare the hash key. */
+typedef int (*rte_hash_cmp_eq_t)(const void *key1, const void *key2, size_t key_len);
+
/**
* Parameters used when creating the hash table.
*/
@@ -104,6 +107,18 @@ struct rte_hash *
rte_hash_create(const struct rte_hash_parameters *params);
/**
+ * Set the rte_hash_set_cmp_func.
+ * Set a new hash compare function other than the default one.
+ *
+ * @note Function pointer does not work with multi-process, so don't use it
+ * in multi-process mode.
+ *
+ * @param h
+ * Hash table to reset
+ */
+void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func);
+
+/**
* Find an existing hash table object and return a pointer to it.
*
* @param name
diff --git a/lib/librte_hash/rte_hash_version.map b/lib/librte_hash/rte_hash_version.map
index 906c8ad..1aa94f9 100644
--- a/lib/librte_hash/rte_hash_version.map
+++ b/lib/librte_hash/rte_hash_version.map
@@ -32,3 +32,10 @@ DPDK_2.1 {
rte_hash_reset;
} DPDK_2.0;
+
+DPDK_2.2 {
+ global:
+
+ rte_hash_set_cmp_func;
+
+} DPDK_2.1;
--
1.9.1
next reply other threads:[~2015-11-27 2:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-27 2:11 Yu Nemo Wenbin [this message]
2015-11-30 8:34 ` De Lara Guarch, Pablo
-- strict thread matches above, loose matches on Subject: below --
2015-11-19 1:15 Yu Nemo Wenbin
2015-11-24 14:06 ` De Lara Guarch, Pablo
2015-11-13 6:28 kamasamikon
2015-11-13 10:00 ` Bruce Richardson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1448590260-15382-1-git-send-email-yuwb_bjy@ctbri.com.cn \
--to=yuwb_bjy@ctbri.com.cn \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).