From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <kamasamikon@qq.com>
Received: from mail.ctbri.com.cn (unknown [219.142.69.33])
 by dpdk.org (Postfix) with ESMTP id 924289362
 for <dev@dpdk.org>; Fri, 13 Nov 2015 07:28:29 +0100 (CET)
Received: from localhost.localdomain ([10.9.63.134])
 by mail.ctbri.com.cn (Lotus Domino Release 8.5.3FP1)
 with ESMTP id 2015111314282493-6018 ;
 Fri, 13 Nov 2015 14:28:24 +0800 
From: kamasamikon <kamasamikon@qq.com>
To: dev@dpdk.org
Date: Fri, 13 Nov 2015 14:28:13 +0800
Message-Id: <1447396093-29004-1-git-send-email-kamasamikon@qq.com>
X-Mailer: git-send-email 1.9.1
X-MIMETrack: Itemize by SMTP Server on mailserver/ctbri(Release 8.5.3FP1|March
 07, 2012) at 2015/11/13 14:28:24,
 Serialize by Router on mailserver/ctbri(Release 8.5.3FP1|March 07, 2012) at
 2015/11/13 14:28:30, Serialize complete at 2015/11/13 14:28:30
X-TNEFEvaluated: 1
Cc: Yu Nemo Wenbin <yuwb_bjy@ctbri.com.cn>
Subject: [dpdk-dev] [PATCH] hash: add rte_hash_set_cmp_func() function.
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Fri, 13 Nov 2015 06:28:30 -0000

Give user a chance to costomize 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 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        | 12 ++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 1e970de..71e2419 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -98,8 +98,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 */
@@ -183,6 +181,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..d626d1c 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 key. It works like the memcmp() */
+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,15 @@ struct rte_hash *
 rte_hash_create(const struct rte_hash_parameters *params);
 
 /**
+ * Set the rte_hash_set_cmp_func.
+ * Set the new hash compare function if the default one is not suitable enough.
+ *
+ * @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
-- 
1.9.1