FD.io VPP
v20.05.1-6-gf53edbc3b
Vector Packet Processing
|
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers". More...
Go to the source code of this file.
Macros | |
#define | vec_resize_has(V, N, H, A, S) |
Resize a vector (general version). More... | |
#define | vec_resize_ha(V, N, H, A) vec_resize_has(V,N,H,A,VEC_NUMA_UNSPECIFIED) |
Resize a vector (less general version). More... | |
#define | vec_resize(V, N) vec_resize_ha(V,N,0,0) |
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V, return pointer to start of vector. More... | |
#define | vec_resize_aligned(V, N, A) vec_resize_ha(V,N,0,A) |
Resize a vector (no header, alignment specified). More... | |
#define | vec_alloc_ha(V, N, H, A) |
Allocate space for N more elements. More... | |
#define | vec_alloc(V, N) vec_alloc_ha(V,N,0,0) |
Allocate space for N more elements (no header, unspecified alignment) More... | |
#define | vec_alloc_aligned(V, N, A) vec_alloc_ha(V,N,0,A) |
Allocate space for N more elements (no header, given alignment) More... | |
#define | vec_new_ha(T, N, H, A) |
Create new vector of given type and length (general version). More... | |
#define | vec_new(T, N) vec_new_ha(T,N,0,0) |
Create new vector of given type and length (unspecified alignment, no header). More... | |
#define | vec_new_aligned(T, N, A) vec_new_ha(T,N,0,A) |
Create new vector of given type and length (alignment specified, no header). More... | |
#define | vec_free_h(V, H) |
Free vector's memory (general version) More... | |
#define | vec_free(V) vec_free_h(V,0) |
Free vector's memory (no header). More... | |
#define | vec_free_header(h) clib_mem_free (h) |
Free vector user header (syntactic sugar) More... | |
#define | vec_dup_ha_numa(V, H, A, S) |
Return copy of vector (general version). More... | |
#define | vec_dup_ha(V, H, A) vec_dup_ha_numa(V,H,A,VEC_NUMA_UNSPECIFIED) |
Return copy of vector (VEC_NUMA_UNSPECIFIED). More... | |
#define | vec_dup(V) vec_dup_ha(V,0,0) |
Return copy of vector (no header, no alignment) More... | |
#define | vec_dup_aligned(V, A) vec_dup_ha(V,0,A) |
Return copy of vector (no header, alignment specified). More... | |
#define | vec_copy(DST, SRC) |
Copy a vector, memcpy wrapper. More... | |
#define | vec_clone(NEW_V, OLD_V) |
Clone a vector. More... | |
#define | vec_validate_han(V, I, H, A, N) |
Make sure vector is long enough for given index (general version). More... | |
#define | vec_validate_ha(V, I, H, A) vec_validate_han(V,I,H,A,VEC_NUMA_UNSPECIFIED) |
#define | vec_validate(V, I) vec_validate_ha(V,I,0,0) |
Make sure vector is long enough for given index (no header, unspecified alignment) More... | |
#define | vec_validate_aligned(V, I, A) vec_validate_ha(V,I,0,A) |
Make sure vector is long enough for given index (no header, specified alignment) More... | |
#define | vec_validate_init_empty_ha(V, I, INIT, H, A) |
Make sure vector is long enough for given index and initialize empty space (general version) More... | |
#define | vec_validate_init_empty(V, I, INIT) vec_validate_init_empty_ha(V,I,INIT,0,0) |
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment) More... | |
#define | vec_validate_init_empty_aligned(V, I, INIT, A) vec_validate_init_empty_ha(V,I,INIT,0,A) |
Make sure vector is long enough for given index and initialize empty space (no header, alignment alignment) More... | |
#define | vec_add1_ha(V, E, H, A) |
Add 1 element to end of vector (general version). More... | |
#define | vec_add1(V, E) vec_add1_ha(V,E,0,0) |
Add 1 element to end of vector (unspecified alignment). More... | |
#define | vec_add1_aligned(V, E, A) vec_add1_ha(V,E,0,A) |
Add 1 element to end of vector (alignment specified). More... | |
#define | vec_add2_ha(V, P, N, H, A) |
Add N elements to end of vector V, return pointer to new elements in P. More... | |
#define | vec_add2(V, P, N) vec_add2_ha(V,P,N,0,0) |
Add N elements to end of vector V, return pointer to new elements in P. More... | |
#define | vec_add2_aligned(V, P, N, A) vec_add2_ha(V,P,N,0,A) |
Add N elements to end of vector V, return pointer to new elements in P. More... | |
#define | vec_add_ha(V, E, N, H, A) |
Add N elements to end of vector V (general version) More... | |
#define | vec_add(V, E, N) vec_add_ha(V,E,N,0,0) |
Add N elements to end of vector V (no header, unspecified alignment) More... | |
#define | vec_add_aligned(V, E, N, A) vec_add_ha(V,E,N,0,A) |
Add N elements to end of vector V (no header, specified alignment) More... | |
#define | vec_pop(V) |
Returns last element of a vector and decrements its length. More... | |
#define | vec_pop2(V, E) |
Set E to the last element of a vector, decrement vector length. More... | |
#define | vec_insert_init_empty_ha(V, N, M, INIT, H, A) |
Insert N vector elements starting at element M, initialize new elements (general version). More... | |
#define | vec_insert_ha(V, N, M, H, A) vec_insert_init_empty_ha(V,N,M,0,H,A) |
Insert N vector elements starting at element M, initialize new elements to zero (general version) More... | |
#define | vec_insert(V, N, M) vec_insert_ha(V,N,M,0,0) |
Insert N vector elements starting at element M, initialize new elements to zero (no header, unspecified alignment) More... | |
#define | vec_insert_aligned(V, N, M, A) vec_insert_ha(V,N,M,0,A) |
Insert N vector elements starting at element M, initialize new elements to zero (no header, alignment specified) More... | |
#define | vec_insert_init_empty(V, N, M, INIT) vec_insert_init_empty_ha(V,N,M,INIT,0,0) |
Insert N vector elements starting at element M, initialize new elements (no header, unspecified alignment) More... | |
#define | vec_insert_init_empty_aligned(V, N, M, INIT, A) vec_insert_init_empty_ha(V,N,M,INIT,0,A) |
Insert N vector elements starting at element M, initialize new elements (no header, specified alignment) More... | |
#define | vec_insert_elts_ha(V, E, N, M, H, A) |
Insert N vector elements starting at element M, insert given elements (general version) More... | |
#define | vec_insert_elts(V, E, N, M) vec_insert_elts_ha(V,E,N,M,0,0) |
Insert N vector elements starting at element M, insert given elements (no header, unspecified alignment) More... | |
#define | vec_insert_elts_aligned(V, E, N, M, A) vec_insert_elts_ha(V,E,N,M,0,A) |
Insert N vector elements starting at element M, insert given elements (no header, specified alignment) More... | |
#define | vec_delete(V, N, M) |
Delete N elements starting at element M. More... | |
#define | vec_del1(v, i) |
Delete the element at index I. More... | |
#define | vec_append(v1, v2) |
Append v2 after v1. More... | |
#define | vec_append_aligned(v1, v2, align) |
Append v2 after v1. More... | |
#define | vec_prepend(v1, v2) |
Prepend v2 before v1. More... | |
#define | vec_prepend_aligned(v1, v2, align) |
Prepend v2 before v1. More... | |
#define | vec_zero(var) |
Zero all vector elements. More... | |
#define | vec_set(v, val) |
Set all vector elements to given value. More... | |
#define | vec_is_equal(v1, v2) (vec_len (v1) == vec_len (v2) && ! memcmp ((v1), (v2), vec_len (v1) * sizeof ((v1)[0]))) |
Compare two vectors, not NULL-pointer tolerant. More... | |
#define | vec_cmp(v1, v2) |
Compare two vectors (only applicable to vectors of signed numbers). More... | |
#define | vec_search(v, E) |
Search a vector for the index of the entry that matches. More... | |
#define | vec_search_with_function(v, E, fn) |
Search a vector for the index of the entry that matches. More... | |
#define | vec_sort_with_function(vec, f) |
Sort a vector using the supplied element comparison function. More... | |
#define | vec_validate_init_c_string(V, S, L) |
Make a vector containing a NULL terminated c-string. More... | |
#define | vec_c_string_is_terminated(V) (((V) != 0) && (vec_len (V) != 0) && ((V)[vec_len ((V)) - 1] == 0)) |
Test whether a vector is a NULL terminated c-string. More... | |
#define | vec_terminate_c_string(V) |
(If necessary) NULL terminate a vector containing a c-string. More... | |
Functions | |
void * | vec_resize_allocate_memory (void *v, word length_increment, uword data_bytes, uword header_bytes, uword data_align, uword numa_id) |
Low-level resize allocation function, usually not called directly. More... | |
uword | clib_mem_is_vec_h (void *v, uword header_bytes) |
Predicate function, says whether the supplied vector is a clib heap object (general version). More... | |
static uword | clib_mem_is_vec (void *v) |
Predicate function, says whether the supplied vector is a clib heap object. More... | |
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
Many CLIB data structures (e.g. hash, heap, pool) are vectors with various different headers.
The memory layout looks like this:
The user pointer contains the address of vector element # 0. Null pointer vectors are valid and mean a zero length vector.
You can reset the length of an allocated vector to zero via the vec_reset_length(v) macro, or by setting the vector length field to zero (e.g. _vec_len (v) = 0). Vec_reset_length(v) preferred: it understands Null pointers.
Typically, the header is not present. Headers allow for other data structures to be built atop CLIB vectors.
Users may specify the alignment for first data element of a vector via the vec_*_aligned macros.
Vector elements can be any C type e.g. (int, double, struct bar). This is also true for data types built atop vectors (e.g. heap, pool, etc.).
Many macros have _a variants supporting alignment of vector elements and _h variants supporting non-zero-length vector headers. The _ha variants support both. Additionally cacheline alignment within a vector element structure can be specified using the CLIB_CACHE_LINE_ALIGN_MARK() macro.
Standard programming error: memorize a pointer to the ith element of a vector then expand it. Vectors expand by 3/2, so such code may appear to work for a period of time. Memorize vector indices which are invariant.
Definition in file vec.h.
#define vec_add | ( | V, | |
E, | |||
N | |||
) | vec_add_ha(V,E,N,0,0) |
#define vec_add1 | ( | V, | |
E | |||
) | vec_add1_ha(V,E,0,0) |
#define vec_add1_aligned | ( | V, | |
E, | |||
A | |||
) | vec_add1_ha(V,E,0,A) |
#define vec_add1_ha | ( | V, | |
E, | |||
H, | |||
A | |||
) |
Add 1 element to end of vector (general version).
V | pointer to a vector |
E | element to add |
H | header size in bytes (may be zero) |
A | alignment (may be zero) |
#define vec_add2 | ( | V, | |
P, | |||
N | |||
) | vec_add2_ha(V,P,N,0,0) |
Add N elements to end of vector V, return pointer to new elements in P.
(no header, alignment specified)
V | pointer to a vector |
P | pointer to new vector element(s) |
N | number of elements to add |
A | alignment (may be zero) |
Add N elements to end of vector V, return pointer to new elements in P.
(general version)
V | pointer to a vector |
P | pointer to new vector element(s) |
N | number of elements to add |
H | header size in bytes (may be zero) |
A | alignment (may be zero) |
#define vec_add_aligned | ( | V, | |
E, | |||
N, | |||
A | |||
) | vec_add_ha(V,E,N,0,A) |
Add N elements to end of vector V (general version)
V | pointer to a vector |
E | pointer to element(s) to add |
N | number of elements to add |
H | header size in bytes (may be zero) |
A | alignment (may be zero) |
#define vec_alloc | ( | V, | |
N | |||
) | vec_alloc_ha(V,N,0,0) |
#define vec_alloc_aligned | ( | V, | |
N, | |||
A | |||
) | vec_alloc_ha(V,N,0,A) |
Allocate space for N more elements.
V | pointer to a vector |
N | number of elements to add |
H | header size in bytes (may be zero) |
A | alignment (may be zero) |
#define vec_append | ( | v1, | |
v2 | |||
) |
Append v2 after v1.
Result in v1.
V1 | target vector |
V2 | vector to append |
#define vec_append_aligned | ( | v1, | |
v2, | |||
align | |||
) |
Append v2 after v1.
Result in v1. Specified alignment.
V1 | target vector |
V2 | vector to append |
align | required alignment |
#define vec_clone | ( | NEW_V, | |
OLD_V | |||
) |
Clone a vector.
Make a new vector with the same size as a given vector but possibly with a different type.
NEW_V | pointer to new vector |
OLD_V | pointer to old vector |
#define vec_cmp | ( | v1, | |
v2 | |||
) |
Compare two vectors (only applicable to vectors of signed numbers).
Used in qsort compare functions.
v1 | Pointer to a vector |
v2 | Pointer to a vector |
#define vec_copy | ( | DST, | |
SRC | |||
) |
Copy a vector, memcpy wrapper.
Assumes sizeof(SRC[0]) == sizeof(DST[0])
DST | destination |
SRC | source |
#define vec_del1 | ( | v, | |
i | |||
) |
Delete the element at index I.
V | pointer to a vector |
I | index to delete |
Delete N elements starting at element M.
V | pointer to a vector |
N | number of elements to delete |
M | first element to delete |
#define vec_dup | ( | V | ) | vec_dup_ha(V,0,0) |
#define vec_dup_aligned | ( | V, | |
A | |||
) | vec_dup_ha(V,0,A) |
#define vec_dup_ha | ( | V, | |
H, | |||
A | |||
) | vec_dup_ha_numa(V,H,A,VEC_NUMA_UNSPECIFIED) |
Return copy of vector (general version).
V | pointer to a vector |
H | size of header in bytes |
A | alignment (may be zero) |
S | numa (may be VEC_NUMA_UNSPECIFIED) |
#define vec_free | ( | V | ) | vec_free_h(V,0) |
#define vec_free_h | ( | V, | |
H | |||
) |
Free vector's memory (general version)
V | pointer to a vector |
H | size of header in bytes |
#define vec_free_header | ( | h | ) | clib_mem_free (h) |
#define vec_insert | ( | V, | |
N, | |||
M | |||
) | vec_insert_ha(V,N,M,0,0) |
Insert N vector elements starting at element M, initialize new elements to zero (no header, alignment specified)
V | (possibly NULL) pointer to a vector. |
N | number of elements to insert |
M | insertion point |
A | alignment (may be zero) |
#define vec_insert_elts | ( | V, | |
E, | |||
N, | |||
M | |||
) | vec_insert_elts_ha(V,E,N,M,0,0) |
Insert N vector elements starting at element M, insert given elements (no header, unspecified alignment)
V | (possibly NULL) pointer to a vector. |
E | element(s) to insert |
N | number of elements to insert |
M | insertion point |
Insert N vector elements starting at element M, insert given elements (no header, specified alignment)
V | (possibly NULL) pointer to a vector. |
E | element(s) to insert |
N | number of elements to insert |
M | insertion point |
A | alignment (may be zero) |
Insert N vector elements starting at element M, insert given elements (general version)
V | (possibly NULL) pointer to a vector. |
E | element(s) to insert |
N | number of elements to insert |
M | insertion point |
H | header size in bytes (may be zero) |
A | alignment (may be zero) |
Insert N vector elements starting at element M, initialize new elements to zero (general version)
V | (possibly NULL) pointer to a vector. |
N | number of elements to insert |
M | insertion point |
H | header size in bytes (may be zero) |
A | alignment (may be zero) |
#define vec_insert_init_empty | ( | V, | |
N, | |||
M, | |||
INIT | |||
) | vec_insert_init_empty_ha(V,N,M,INIT,0,0) |
Insert N vector elements starting at element M, initialize new elements (no header, unspecified alignment)
V | (possibly NULL) pointer to a vector. |
N | number of elements to insert |
M | insertion point |
INIT | initial value (can be a complex expression!) |
Insert N vector elements starting at element M, initialize new elements (no header, specified alignment)
V | (possibly NULL) pointer to a vector. |
N | number of elements to insert |
M | insertion point |
INIT | initial value (can be a complex expression!) |
A | alignment (may be zero) |
Insert N vector elements starting at element M, initialize new elements (general version).
V | (possibly NULL) pointer to a vector. |
N | number of elements to insert |
M | insertion point |
INIT | initial value (can be a complex expression!) |
H | header size in bytes (may be zero) |
A | alignment (may be zero) |
#define vec_new | ( | T, | |
N | |||
) | vec_new_ha(T,N,0,0) |
#define vec_new_aligned | ( | T, | |
N, | |||
A | |||
) | vec_new_ha(T,N,0,A) |
Create new vector of given type and length (general version).
T | type of elements in new vector |
N | number of elements to add |
H | header size in bytes (may be zero) |
A | alignment (may be zero) |
#define vec_pop | ( | V | ) |
Returns last element of a vector and decrements its length.
V | pointer to a vector |
#define vec_pop2 | ( | V, | |
E | |||
) |
Set E to the last element of a vector, decrement vector length.
V | pointer to a vector |
E | pointer to the last vector element |
#define vec_prepend | ( | v1, | |
v2 | |||
) |
Prepend v2 before v1.
Result in v1.
V1 | target vector |
V2 | vector to prepend |
#define vec_prepend_aligned | ( | v1, | |
v2, | |||
align | |||
) |
Prepend v2 before v1.
Result in v1. Specified alignment
V1 | target vector |
V2 | vector to prepend |
align | required alignment |
#define vec_resize | ( | V, | |
N | |||
) | vec_resize_ha(V,N,0,0) |
Resize a vector (no header, unspecified alignment) Add N elements to end of given vector V, return pointer to start of vector.
Vector will have room for H header bytes and will have user's data aligned at alignment A (rounded to next power of 2).
V | pointer to a vector |
N | number of elements to add |
#define vec_resize_aligned | ( | V, | |
N, | |||
A | |||
) | vec_resize_ha(V,N,0,A) |
Resize a vector (no header, alignment specified).
Add N elements to end of given vector V, return pointer to start of vector. Vector will have room for H header bytes and will have user's data aligned at alignment A (rounded to next power of 2).
V | pointer to a vector |
N | number of elements to add |
A | alignment (may be zero) |
#define vec_resize_ha | ( | V, | |
N, | |||
H, | |||
A | |||
) | vec_resize_has(V,N,H,A,VEC_NUMA_UNSPECIFIED) |
Resize a vector (less general version).
Add N elements to end of given vector V, return pointer to start of vector. Vector will have room for H header bytes and will have user's data aligned at alignment A (rounded to next power of 2).
V | pointer to a vector |
N | number of elements to add |
H | header size in bytes (may be zero) |
A | alignment (may be zero) |
Resize a vector (general version).
Add N elements to end of given vector V, return pointer to start of vector. Vector will have room for H header bytes and will have user's data aligned at alignment A (rounded to next power of 2).
V | pointer to a vector |
N | number of elements to add |
H | header size in bytes (may be zero) |
A | alignment (may be zero) |
S | numa_id (may be zero) |
#define vec_search | ( | v, | |
E | |||
) |
Search a vector for the index of the entry that matches.
v | Pointer to a vector |
E | Entry to match |
#define vec_search_with_function | ( | v, | |
E, | |||
fn | |||
) |
Search a vector for the index of the entry that matches.
v | Pointer to a vector |
E | Pointer to entry to match |
fn | Comparison function !0 => match |
#define vec_set | ( | v, | |
val | |||
) |
Set all vector elements to given value.
Null-pointer tolerant.
v | vector to set |
val | value for each vector element |
#define vec_sort_with_function | ( | vec, | |
f | |||
) |
Sort a vector using the supplied element comparison function.
Does not depend on the underlying implementation to deal correctly with null, zero-long, or 1-long vectors
vec | vector to sort |
f | comparison function |
#define vec_terminate_c_string | ( | V | ) |
(If necessary) NULL terminate a vector containing a c-string.
V | (possibly NULL) pointer to a vector. |
#define vec_validate | ( | V, | |
I | |||
) | vec_validate_ha(V,I,0,0) |
#define vec_validate_aligned | ( | V, | |
I, | |||
A | |||
) | vec_validate_ha(V,I,0,A) |
#define vec_validate_ha | ( | V, | |
I, | |||
H, | |||
A | |||
) | vec_validate_han(V,I,H,A,VEC_NUMA_UNSPECIFIED) |
Make sure vector is long enough for given index (general version).
V | (possibly NULL) pointer to a vector. |
I | vector index which will be valid upon return |
H | header size in bytes (may be zero) |
A | alignment (may be zero) |
N | numa_id (may be zero) |
#define vec_validate_init_c_string | ( | V, | |
S, | |||
L | |||
) |
Make a vector containing a NULL terminated c-string.
V | (possibly NULL) pointer to a vector. |
S | pointer to string buffer. |
L | string length (NOT including the terminating NULL; a la strlen()) |
#define vec_validate_init_empty | ( | V, | |
I, | |||
INIT | |||
) | vec_validate_init_empty_ha(V,I,INIT,0,0) |
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
V | (possibly NULL) pointer to a vector. |
I | vector index which will be valid upon return |
INIT | initial value (can be a complex expression!) |
#define vec_validate_init_empty_aligned | ( | V, | |
I, | |||
INIT, | |||
A | |||
) | vec_validate_init_empty_ha(V,I,INIT,0,A) |
Make sure vector is long enough for given index and initialize empty space (no header, alignment alignment)
V | (possibly NULL) pointer to a vector. |
I | vector index which will be valid upon return |
INIT | initial value (can be a complex expression!) |
A | alignment (may be zero) |
#define vec_validate_init_empty_ha | ( | V, | |
I, | |||
INIT, | |||
H, | |||
A | |||
) |
Make sure vector is long enough for given index and initialize empty space (general version)
V | (possibly NULL) pointer to a vector. |
I | vector index which will be valid upon return |
INIT | initial value (can be a complex expression!) |
H | header size in bytes (may be zero) |
A | alignment (may be zero) |
#define vec_zero | ( | var | ) |
Zero all vector elements.
Null-pointer tolerant.
var | Vector to zero |
|
inlinestatic |
Predicate function, says whether the supplied vector is a clib heap object (general version).
v | pointer to a vector |
header_bytes | vector header size in bytes (may be zero) |
Definition at line 138 of file vec.c.
void* vec_resize_allocate_memory | ( | void * | v, |
word | length_increment, | ||
uword | data_bytes, | ||
uword | header_bytes, | ||
uword | data_align, | ||
uword | numa_id | ||
) |
Low-level resize allocation function, usually not called directly.
v | pointer to a vector |
length_increment | length increment in elements |
data_bytes | requested size in bytes |
header_bytes | header size in bytes (may be zero) |
data_align | alignment (may be zero) |
numa_id | numa id (may be zero) |