38 #ifndef included_sparse_vec_h 39 #define included_sparse_vec_h 54 #define SPARSE_VEC_IS_RANGE (1 << 0) 55 #define SPARSE_VEC_IS_VALID_RANGE (1 << 1) 68 #define SPARSE_VEC_INVALID_INDEX (0) 77 ASSERT (sparse_index_bits <= 16);
79 v = _vec_resize ((
void *) 0,
119 if (
PREDICT_FALSE (maybe_range == 0 && insert == 0 && w == 0))
127 is_member = (w & (1ULL <<
b)) != 0;
132 u8 is_range, is_valid_range;
137 is_member = is_range ? is_valid_range : is_member;
142 *insert = !is_member;
155 d = is_member ? d : 0;
157 return is_member + d;
173 uword b0, b1, w0, w1, v0, v1;
175 u8 is_member0, is_member1;
202 v0 = w0 & ((1ULL << b0) - 1);
203 v1 = w1 & ((1ULL << b1) - 1);
216 is_member0 = (w0 & (1ULL << b0)) != 0;
217 is_member1 = (w1 & (1ULL << b1)) != 0;
219 d0 = is_member0 ? d0 : 0;
220 d1 = is_member1 ? d1 : 0;
222 *i0_return = is_member0 + d0;
223 *i1_return = is_member1 + d1;
226 #define sparse_vec_free(v) vec_free(v) 228 #define sparse_vec_elt_at_index(v,i) \ 229 vec_elt_at_index ((v), sparse_vec_index ((v), (i))) 231 #define sparse_vec_validate(v,i) \ 237 (v) = sparse_vec_new (sizeof ((v)[0]), BITS (u16)); \ 239 _i = sparse_vec_index_internal ((v), (i), \ 243 vec_insert_ha ((v), 1, _i, \ 244 sizeof (sparse_vec_header_t), \ #define SPARSE_VEC_IS_RANGE
#define count_trailing_zeros(x)
static uword min_log2(uword x)
#define vec_resize(V, N)
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V...
static void sparse_vec_index2(void *v, u32 si0, u32 si1, u32 *i0_return, u32 *i1_return)
sll srl srl sll sra u16x4 i
static sparse_vec_header_t * sparse_vec_header(void *v)
static uword sparse_vec_index(void *v, uword sparse_index)
static uword is_pow2(uword x)
static uword sparse_vec_index_internal(void *v, uword sparse_index, uword maybe_range, u32 *insert)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define SPARSE_VEC_IS_VALID_RANGE
static void * vec_header(void *v, uword header_bytes)
Find a user vector header.
static uword count_set_bits(uword x)
static void * sparse_vec_new(uword elt_bytes, uword sparse_index_bits)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".