X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Fhash.h;h=21986ea774c342dfdd2df0a6015510658a705114;hb=49d8cddaba69a6f08cb990c9be9bebe87f33b808;hp=3f0efaa727ce00879d3c3fa00be31c5c10430913;hpb=7cd468a3d7dee7d6c92f69a0bb7061ae208ec727;p=vpp.git diff --git a/src/vppinfra/hash.h b/src/vppinfra/hash.h index 3f0efaa727c..21986ea774c 100644 --- a/src/vppinfra/hash.h +++ b/src/vppinfra/hash.h @@ -273,12 +273,35 @@ uword hash_bytes (void *v); /* Public macro to set (key, value) for pointer key */ #define hash_set_mem(h,key,value) hash_set3 (h, pointer_to_uword (key), (value), 0) +/* Public inline funcion allocate and copy key to use in hash for pointer key */ +always_inline void +hash_set_mem_alloc (uword ** h, void *key, uword v) +{ + size_t ksz = hash_header (*h)->user; + void *copy = clib_mem_alloc (ksz); + clib_memcpy (copy, key, ksz); + hash_set_mem (*h, copy, v); +} + /* Public macro to set (key, 0) for pointer key */ #define hash_set1_mem(h,key) hash_set3 ((h), pointer_to_uword (key), 0, 0) /* Public macro to unset (key, value) for pointer key */ #define hash_unset_mem(h,key) ((h) = _hash_unset ((h), pointer_to_uword (key),0)) +/* Public inline funcion to unset pointer key and then free the key memory */ +always_inline void +hash_unset_mem_free (uword ** h, void *key) +{ + hash_pair_t *hp = hash_get_pair_mem (*h, key); + if (PREDICT_TRUE (hp != NULL)) + { + key = uword_to_pointer (hp->key, void *); + hash_unset_mem (*h, key); + clib_mem_free (key); + } +} + /* internal routine to free a hash table */ extern void *_hash_free (void *v); @@ -683,11 +706,6 @@ unformat_function_t unformat_hash_string; /* Main test routine. */ int test_hash_main (unformat_input_t * input); -static inline void -hash_delete (void *bob) -{ -} - #endif /* included_hash_h */ /*