40 #define QHASH_ALL_VALID ((1 << QHASH_KEYS_PER_BUCKET) - 1)
53 v = _vec_resize (0, 1 << l, elt_bytes << l,
sizeof (
h[0]),
58 h->log2_hash_size = l;
83 for (
i = 0;
i < 256;
i++)
103 #define _(i) ((hash_keys[i] == search_key) << i)
104 t = (_(0) | _(1) | _(2) | _(3));
106 t |= (_(4) | _(5) | _(6) | _(7));
108 t |= (_(8) | _(9) | _(10) | _(11) | _(12) | _(13) | _(14) | _(15));
117 uword n_search_keys,
u32 * result_indices)
120 uword *k, *hash_keys;
127 sizeof (result_indices[0]) * n_search_keys);
135 hash_keys =
h->hash_keys;
140 u32 a0, b0, c0, bi0, valid0, match0;
141 u32 a1, b1, c1, bi1, valid1, match1;
142 uword k0, k1, *h0, *h1;
149 a0 = a1 =
h->hash_seeds[0];
150 b0 = b1 =
h->hash_seeds[1];
151 c0 = c1 =
h->hash_seeds[2];
166 bi0 = c0 & bucket_mask;
167 bi1 = c1 & bucket_mask;
169 h0 = hash_keys + bi0;
170 h1 = hash_keys + bi1;
182 r[0] = match0 ? bi0 : ~0;
183 r[1] = match1 ? bi1 : ~0;
190 r[-2] = p ? p[0] : ~0;
197 r[-1] = p ? p[0] : ~0;
203 u32 a0, b0, c0, bi0, valid0, match0;
210 a0 =
h->hash_seeds[0];
211 b0 =
h->hash_seeds[1];
212 c0 =
h->hash_seeds[2];
220 bi0 = c0 & bucket_mask;
222 h0 = hash_keys + bi0;
230 r[0] = match0 ? bi0 : ~0;
237 r[-1] = p ? p[0] : ~0;
250 uword *k, *hash_keys;
261 hash_keys =
h->hash_keys;
264 u32 a0, b0, c0, bi0, valid0;
265 u32 a1, b1, c1, bi1, valid1;
266 uword k0, k1, *h0, *h1;
273 a0 = a1 =
h->hash_seeds[0];
274 b0 = b1 =
h->hash_seeds[1];
275 c0 = c1 =
h->hash_seeds[2];
290 bi0 = c0 & bucket_mask;
291 bi1 = c1 & bucket_mask;
293 h0 = hash_keys + bi0;
294 h1 = hash_keys + bi1;
309 bi += ((is_match1 ? bi1 : bi0)
311 *matching_key = (k - 2 - search_keys) + is_match1;
320 uword ki = k - 2 - search_keys;
341 u32 a0, b0, c0, bi0, valid0;
348 a0 =
h->hash_seeds[0];
349 b0 =
h->hash_seeds[1];
350 c0 =
h->hash_seeds[2];
358 bi0 = c0 & bucket_mask;
360 h0 = hash_keys + bi0;
369 *matching_key = (k - 1 - search_keys);
379 *matching_key = (k - 1 - search_keys);
405 i =
h->overflow_free_indices[l - 1];
406 _vec_len (
h->overflow_free_indices) = l - 1;
409 i = (1 <<
h->log2_hash_size) +
hash_elts (
h->overflow_hash);
412 h->overflow_counts[bi] += 1;
419 v = _vec_resize (v, dl, (l + dl) * elt_bytes,
sizeof (
h[0]),
421 clib_memset (v + l * elt_bytes, ~0, dl * elt_bytes);
444 ASSERT (
h->overflow_counts[bi] > 0);
446 vec_add1 (
h->overflow_free_indices, result);
447 h->overflow_counts[bi] -= 1;
463 _qhash_set_multiple (
void *v,
466 uword n_search_keys,
u32 * result_indices)
469 uword *k, *hash_keys;
473 if (
vec_len (v) < n_search_keys)
474 v = _qhash_resize (v, n_search_keys, elt_bytes);
486 hash_keys =
h->hash_keys;
494 u32 a0, b0, c0, bi0, match0, valid0, free0;
495 u32 a1, b1, c1, bi1, match1, valid1, free1;
508 a0 = a1 =
h->hash_seeds[0];
509 b0 = b1 =
h->hash_seeds[1];
510 c0 = c1 =
h->hash_seeds[2];
525 bi0 = c0 & bucket_mask;
526 bi1 = c1 & bucket_mask;
528 h0 = hash_keys + bi0;
529 h1 = hash_keys + bi1;
541 valid1 = valid1 | (bi0 == bi1 ? free0 : 0);
544 n_elts += (match0 == 0) + (match1 == 0);
546 match0 = match0 ? match0 : free0;
547 match1 = match1 ? match1 : free1;
560 r[0] = h0 - hash_keys;
561 r[1] = h1 - hash_keys;
576 r[0] = h0 - hash_keys;
587 r[1] = h1 - hash_keys;
595 u32 a0, b0, c0, bi0, match0, valid0, free0;
602 a0 =
h->hash_seeds[0];
603 b0 =
h->hash_seeds[1];
604 c0 =
h->hash_seeds[2];
612 bi0 = c0 & bucket_mask;
614 h0 = hash_keys + bi0;
623 n_elts += (match0 == 0);
625 match0 = match0 ? match0 : free0;
635 r[0] = h0 - hash_keys;
658 uword i, j = 0, k, l, t = ~0;
672 &&
i <
vec_len (
h->overflow_counts) &&
h->overflow_counts[
i] > 0)
677 j = qhash_hash_mix (h, p->key) / QHASH_KEYS_PER_BUCKET;
692 h->overflow_counts[
i] -= 1;
697 clib_memswap (v + t * elt_bytes, v + l * elt_bytes, elt_bytes);
707 _qhash_unset_multiple (
void *v,
710 uword n_search_keys,
u32 * result_indices)
713 uword *k, *hash_keys;
720 for (
i = 0;
i < n_search_keys;
i++)
721 result_indices[
i] = ~0;
726 hash_keys =
h->hash_keys;
734 u32 a0, b0, c0, bi0, match0, valid0;
735 u32 a1, b1, c1, bi1, match1, valid1;
748 a0 = a1 =
h->hash_seeds[0];
749 b0 = b1 =
h->hash_seeds[1];
750 c0 = c1 =
h->hash_seeds[2];
765 bi0 = c0 & bucket_mask;
766 bi1 = c1 & bucket_mask;
768 h0 = hash_keys + bi0;
769 h1 = hash_keys + bi1;
778 n_elts -= (match0 != 0) + (match1 != 0);
787 valid1 = bi0 == bi1 ? valid0 : valid1;
806 n_elts -= (match1 != 0);
815 u32 a0, b0, c0, bi0, match0, valid0;
822 a0 =
h->hash_seeds[0];
823 b0 =
h->hash_seeds[1];
824 c0 =
h->hash_seeds[2];
832 bi0 = c0 & bucket_mask;
834 h0 = hash_keys + bi0;
839 n_elts -= (match0 != 0);