From mboxrd@z Thu Jan 1 00:00:00 1970 From: "De Lara Guarch, Pablo" Subject: Re: [PATCH v2 1/6] hash: make duplicated code into functions Date: Fri, 6 Jul 2018 10:04:11 +0000 Message-ID: References: <1528455078-328182-1-git-send-email-yipeng1.wang@intel.com> <1530275097-123488-1-git-send-email-yipeng1.wang@intel.com> <1530275097-123488-2-git-send-email-yipeng1.wang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Cc: "dev@dpdk.org" , "Richardson, Bruce" , "honnappa.nagarahalli@arm.com" , "vguvva@caviumnetworks.com" , "brijesh.s.singh@gmail.com" To: "Wang, Yipeng1" Return-path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 1BD5A1BDD5 for ; Fri, 6 Jul 2018 12:04:14 +0200 (CEST) In-Reply-To: <1530275097-123488-2-git-send-email-yipeng1.wang@intel.com> Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Yipeng, > -----Original Message----- > From: Wang, Yipeng1 > Sent: Friday, June 29, 2018 1:25 PM > To: De Lara Guarch, Pablo > Cc: dev@dpdk.org; Wang, Yipeng1 ; Richardson, > Bruce ; honnappa.nagarahalli@arm.com; > vguvva@caviumnetworks.com; brijesh.s.singh@gmail.com > Subject: [PATCH v2 1/6] hash: make duplicated code into functions >=20 > This commit refactors the hash table lookup/add/del code to remove some c= ode > duplication. Processing on primary bucket can also apply to secondary buc= ket > with same code. >=20 > Signed-off-by: Yipeng Wang > --- > lib/librte_hash/rte_cuckoo_hash.c | 186 ++++++++++++++++++--------------= ------ ... > +/* Search one bucket to find the match key */ > static inline int32_t > -__rte_hash_lookup_with_hash(const struct rte_hash *h, const void *key, > - hash_sig_t sig, void **data) > +search_one_bucket(const struct rte_hash *h, const void *key, hash_sig_t = sig, > + void **data, struct rte_hash_bucket *bkt) Use "const" in "struct rte_hash_bucket". ... > +search_and_remove(const struct rte_hash *h, const void *key, > + struct rte_hash_bucket *bkt, hash_sig_t sig, > + int32_t *ret_val) > { > - uint32_t bucket_idx; > - hash_sig_t alt_hash; > - unsigned i; > - struct rte_hash_bucket *bkt; > struct rte_hash_key *k, *keys =3D h->key_store; > - int32_t ret; > - > - bucket_idx =3D sig & h->bucket_bitmask; > - bkt =3D &h->buckets[bucket_idx]; > + unsigned int i; >=20 > /* Check if key is in primary location */ > for (i =3D 0; i < RTE_HASH_BUCKET_ENTRIES; i++) { @@ -833,37 +825,39 > @@ __rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key= , > * Return index where key is stored, > * subtracting the first dummy index > */ > - ret =3D bkt->key_idx[i] - 1; > + *ret_val =3D bkt->key_idx[i] - 1; > bkt->key_idx[i] =3D EMPTY_SLOT; > - return ret; > + return 0; You can store ret_val and return it, instead of returning 0, so the function is similar to the other search functions. > } > } > } > + return -1;