/* 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 */
+/* Public inline function allocate and copy key to use in hash for pointer key */
always_inline void
-hash_set_mem_alloc (uword ** h, void *key, uword v)
+hash_set_mem_alloc (uword ** h, const void *key, uword v)
{
size_t ksz = hash_header (*h)->user;
void *copy = clib_mem_alloc (ksz);
- clib_memcpy (copy, key, ksz);
+ clib_memcpy_fast (copy, key, ksz);
hash_set_mem (*h, copy, v);
}
/* 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 */
+/* Public inline function to unset pointer key and then free the key memory */
always_inline void
-hash_unset_mem_free (uword ** h, void *key)
+hash_unset_mem_free (uword ** h, const 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);
+ void *_k = uword_to_pointer (hp->key, void *);
+ hash_unset_mem (*h, _k);
+ clib_mem_free (_k);
}
}
clib_error_t *hash_validate (void *v);
-/* Public inline funcion to get the number of value bytes for a hash table */
+/* Public inline function to get the number of value bytes for a hash table */
always_inline uword
hash_value_bytes (hash_t * h)
{
return (sizeof (p->value[0]) << h->log2_pair_size) - sizeof (p->key);
}
-/* Public inline funcion to get log2(size of a (key,value) pair) */
+/* Public inline function to get log2(size of a (key,value) pair) */
always_inline uword
hash_pair_log2_bytes (hash_t * h)
{
return log2_bytes;
}
-/* Public inline funcion to get size of a (key,value) pair */
+/* Public inline function to get size of a (key,value) pair */
always_inline uword
hash_pair_bytes (hash_t * h)
{
return (uword) 1 << hash_pair_log2_bytes (h);
}
-/* Public inline funcion to advance a pointer past one (key,value) pair */
+/* Public inline function to advance a pointer past one (key,value) pair */
always_inline void *
hash_forward1 (hash_t * h, void *v)
{
return (u8 *) v + hash_pair_bytes (h);
}
-/* Public inline funcion to advance a pointer past N (key,value) pairs */
+/* Public inline function to advance a pointer past N (key,value) pairs */
always_inline void *
hash_forward (hash_t * h, void *v, uword n)
{
calls body with each active hash pair
*/
-/* Iteratate over key/value pairs. */
+/* Iterate over key/value pairs. */
#define hash_foreach(key_var,value_var,h,body) \
do { \
hash_pair_t * _r; \
_format_pair,_format_pair_arg) \
({ \
hash_t _h; \
- memset (&_h, 0, sizeof (_h)); \
+ clib_memset (&_h, 0, sizeof (_h)); \
_h.user = (_user); \
_h.key_sum = (hash_key_sum_function_t *) (_key_sum); \
_h.key_equal = (_key_equal); \