44 return ((
u32 *) d)[0];
46 return ((
u16 *) d)[0] | (((
u8 *) d)[2] << 16);
48 return ((
u16 *) d)[0];
62 n_left = n_data_bytes;
93 #define foreach_mhash_key_size \ 94 _ (2) _ (3) _ (4) _ (5) _ (6) _ (7) \ 95 _ (8) _ (12) _ (16) _ (20) \ 96 _ (24) _ (28) _ (32) _ (36) \ 97 _ (40) _ (44) _ (48) _ (52) \ 100 #define _(N_KEY_BYTES) \ 102 mhash_key_sum_##N_KEY_BYTES (hash_t * h, uword key) \ 104 mhash_t * hv = uword_to_pointer (h->user, mhash_t *); \ 105 return mhash_key_sum_inline (mhash_key_to_mem (hv, key), \ 111 mhash_key_equal_##N_KEY_BYTES (hash_t * h, uword key1, uword key2) \ 113 mhash_t * hv = uword_to_pointer (h->user, mhash_t *); \ 114 void * k1 = mhash_key_to_mem (hv, key1); \ 115 void * k2 = mhash_key_to_mem (hv, key2); \ 116 return ! memcmp (k1, k2, (N_KEY_BYTES)); \ 137 return strcmp (k1, k2) == 0;
175 #define _(N_KEY_BYTES) \ 177 .key_sum = mhash_key_sum_##N_KEY_BYTES, \ 178 .key_equal = mhash_key_equal_##N_KEY_BYTES, \ 209 memset (h, 0,
sizeof (h[0]));
216 _vec_len(h->key_tmp) = 0;
245 vec_add (key_tmp, key, strlen (key) + 1);
275 uword ikey,
i, l=0, n_key_bytes, old_n_elts, key_alloc_from_free_list = 0;
285 n_key_bytes = is_c_string ? (strlen (key) + 1) :
vec_len (key);
290 sk->
vec.
len = n_key_bytes;
299 if (key_alloc_from_free_list)
317 h->
hash = _hash_set3 (h->
hash, ikey, new_value, old_value);
337 if (key_alloc_from_free_list)
381 u32 ki = va_arg (*va,
u32);
387 u32 l = is_c_string ? strlen (k) :
vec_len (k);
static uword mhash_set_tmp_key(mhash_t *h, void *key)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
#define foreach_mhash_key_size
sll srl srl sll sra u16x4 i
hash_pair_t * mhash_get_pair(mhash_t *h, void *key)
uword mhash_unset(mhash_t *h, void *key, uword *old_value)
format_function_t * format_key
always_inline hash_t * hash_header(void *v)
always_inline uword key_sum(hash_t *h, uword key)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
uword( hash_key_equal_function_t)(struct hash_header *, uword key1, uword key2)
always_inline void * mhash_key_to_mem(mhash_t *h, uword key)
#define hash_v3_mix32(a, b, c)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
always_inline uword mhash_key_vector_is_heap(mhash_t *h)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define hash_get_pair(h, key)
static uword pointer_to_uword(const void *p)
uword mhash_set_mem(mhash_t *h, void *key, uword *new_value, uword *old_value)
uword os_get_cpu_number(void)
u32 * key_vector_free_indices
#define uword_to_pointer(u, type)
void mhash_init(mhash_t *h, uword n_value_bytes, uword n_key_bytes)
#define vec_free(V)
Free vector's memory (no header).
static uword mhash_key_sum_vec_string(hash_t *h, uword key)
#define clib_memcpy(a, b, c)
always_inline u32 load_partial_u32(void *d, uword n)
always_inline uword hash_elts(void *v)
#define hash_create2(_elts, _user, _value_bytes,_key_sum, _key_equal,_format_pair, _format_pair_arg)
static foreach_mhash_key_size uword mhash_key_sum_c_string(hash_t *h, uword key)
#define hash_v3_finalize32(a, b, c)
void heap_dealloc(void *v, uword handle)
#define heap_alloc(v, size, handle)
static uword mhash_key_equal_c_string(hash_t *h, uword key1, uword key2)
always_inline uword key_equal(hash_t *h, uword key1, uword key2)
uword( hash_key_sum_function_t)(struct hash_header *, uword key)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define MHASH_C_STRING_KEY
#define MHASH_VEC_STRING_KEY
always_inline void mhash_sanitize_hash_user(mhash_t *mh)
always_inline u32 mhash_key_sum_inline(void *data, uword n_data_bytes, u32 seed)
u8 * format_mhash_key(u8 *s, va_list *va)
#define hash_unset3(h, key, old_value)
static uword mhash_key_equal_vec_string(hash_t *h, uword key1, uword key2)