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,
123 is_member = (w & (1ULL << b)) != 0;
128 u8 is_range, is_valid_range;
133 is_member = is_range ? is_valid_range : is_member;
138 *insert = !is_member;
151 d = is_member ? d : 0;
153 return is_member + d;
169 uword b0, b1, w0, w1, v0, v1;
171 u8 is_member0, is_member1;
198 v0 = w0 & ((1ULL << b0) - 1);
199 v1 = w1 & ((1ULL << b1) - 1);
212 is_member0 = (w0 & (1ULL << b0)) != 0;
213 is_member1 = (w1 & (1ULL << b1)) != 0;
215 d0 = is_member0 ? d0 : 0;
216 d1 = is_member1 ? d1 : 0;
218 *i0_return = is_member0 + d0;
219 *i1_return = is_member1 + d1;
222 #define sparse_vec_free(v) vec_free(v) 224 #define sparse_vec_elt_at_index(v,i) \ 225 vec_elt_at_index ((v), sparse_vec_index ((v), (i))) 227 #define sparse_vec_validate(v,i) \ 233 (v) = sparse_vec_new (sizeof ((v)[0]), BITS (u16)); \ 235 _i = sparse_vec_index_internal ((v), (i), \ 239 vec_insert_ha ((v), 1, _i, \ 240 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)
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".