70 #define SOL_VECTOR_INIT(TYPE) { NULL, 0, sizeof(TYPE) }
128 const unsigned char *data;
130 data = (
const unsigned char *)v->
data;
238 void *data = v->
data;
253 #define SOL_VECTOR_FOREACH_IDX(vector, itrvar, idx) \
255 idx < (vector)->len && (itrvar = (__typeof__(itrvar))sol_vector_get_no_check((vector), idx), true); \
267 #define SOL_VECTOR_FOREACH_IDX_UNTIL(vector, itrvar, idx, until) \
269 idx < until && (itrvar = (__typeof__(itrvar))sol_vector_get_no_check((vector), idx), true); \
280 #define SOL_VECTOR_FOREACH_REVERSE_IDX(vector, itrvar, idx) \
281 for (idx = (vector)->len - 1; \
282 idx != ((__typeof__(idx)) - 1) && (itrvar = (__typeof__(itrvar))sol_vector_get_no_check((vector), idx), true); \
318 #define SOL_PTR_VECTOR_INIT { { NULL, 0, sizeof(void *) } }
351 static inline uint16_t
672 #define SOL_PTR_VECTOR_FOREACH_IDX(vector, itrvar, idx) \
674 idx < (vector)->base.len && \
675 ((itrvar = (__typeof__(itrvar))sol_ptr_vector_get_no_check((vector), idx)), true); \
687 #define SOL_PTR_VECTOR_FOREACH_IDX_UNTIL(vector, itrvar, idx, until) \
690 ((itrvar = (__typeof__(itrvar))sol_ptr_vector_get_no_check((vector), idx)), true); \
701 #define SOL_PTR_VECTOR_FOREACH_REVERSE_IDX(vector, itrvar, idx) \
702 for (idx = (vector)->base.len - 1; \
703 idx != ((__typeof__(idx)) - 1) && \
704 (itrvar = (__typeof__(itrvar))sol_ptr_vector_get_no_check((vector), idx), true); \
726 static inline int32_t
759 static inline int32_t
797 static inline int32_t
804 if (compare_cb(tempt, p) == 0)
835 static inline int32_t
842 if (compare_cb(tempt, p) == 0)
912 static inline int32_t
922 for (i = r; i < pv->
base.
len; i++) {
925 if (compare_cb(elem, other) != 0)
932 for (i = r; i > 0; i--) {
935 if (compare_cb(elem, other) != 0)
968 static inline int32_t
972 int32_t r, found_i = -ENODATA;
978 for (i = r; i < pv->
base.
len; i++) {
981 if (compare_cb(elem, other) != 0)
991 for (i = r; i > 0; i--) {
994 if (compare_cb(elem, other) != 0)
1027 static inline int32_t
1031 int32_t r, found_i = -ENODATA;
1040 if (compare_cb(elem, other) != 0)
1054 for (i = r; i + 1 < pv->
base.
len; i++) {
1057 if (compare_cb(elem, other) != 0)
struct sol_vector base
Definition: sol-vector.h:311
static void * sol_ptr_vector_steal(struct sol_ptr_vector *pv, uint16_t i)
Remove and return the element at index i from the vector.
Definition: sol-vector.h:607
static int sol_vector_del_last(struct sol_vector *v)
Remove the last element from the vector.
Definition: sol-vector.h:192
static void * sol_vector_get_no_check(const struct sol_vector *v, uint16_t i)
Return the element of the vector at the given index (no safety checks).
Definition: sol-vector.h:126
static int32_t sol_ptr_vector_find_last_sorted(const struct sol_ptr_vector *pv, const void *elem, int(*compare_cb)(const void *data1, const void *data2))
Find the last occurrence of elem in the sorted vector pv.
Definition: sol-vector.h:969
#define SOL_PTR_VECTOR_FOREACH_IDX(vector, itrvar, idx)
Macro to iterate over the pointer vector easily.
Definition: sol-vector.h:672
int sol_ptr_vector_del_element(struct sol_ptr_vector *pv, const void *elem)
Remove all occurrences of elem from the vector pv.
static int32_t sol_ptr_vector_find_sorted(const struct sol_ptr_vector *pv, const void *elem, int(*compare_cb)(const void *data1, const void *data2))
Find the exact occurrence of elem in the sorted vector pv.
Definition: sol-vector.h:913
static void sol_ptr_vector_clear(struct sol_ptr_vector *pv)
Delete all elements from the vector.
Definition: sol-vector.h:642
static int32_t sol_ptr_vector_match_last(const struct sol_ptr_vector *pv, const void *tempt, int(*compare_cb)(const void *data1, const void *data2))
Match for the last occurrence matching template tempt.
Definition: sol-vector.h:836
void * sol_vector_append_n(struct sol_vector *v, uint16_t n)
Append n elements to the end of the vector.
int32_t sol_ptr_vector_insert_sorted(struct sol_ptr_vector *pv, const void *ptr, int(*compare_cb)(const void *data1, const void *data2))
Insert a pointer in the pointer vector, using the given comparison function to determine its position...
int sol_ptr_vector_init_n(struct sol_ptr_vector *pv, uint16_t n)
Initializes a sol_ptr_vector structure and preallocates n elements.
static int32_t sol_ptr_vector_find_last(const struct sol_ptr_vector *pv, const void *elem)
Find the last occurrence of elem from the vector pv.
Definition: sol-vector.h:727
static int sol_ptr_vector_del_range(struct sol_ptr_vector *pv, uint16_t start, uint16_t len)
Remove an range of pointers from the vector.
Definition: sol-vector.h:559
int sol_ptr_vector_remove(struct sol_ptr_vector *pv, const void *ptr)
Remove an pointer from the vector.
static int32_t sol_ptr_vector_find_first_sorted(const struct sol_ptr_vector *pv, const void *elem, int(*compare_cb)(const void *data1, const void *data2))
Find the first occurrence of elem in the sorted vector pv.
Definition: sol-vector.h:1028
uint16_t elem_size
Size of each element in bytes.
Definition: sol-vector.h:61
static void * sol_ptr_vector_steal_data(struct sol_ptr_vector *pv)
Steal the memory holding the elements of the vector.
Definition: sol-vector.h:659
static void * sol_ptr_vector_get(const struct sol_ptr_vector *pv, uint16_t i)
Return the element of the vector at the given index.
Definition: sol-vector.h:407
struct sol_ptr_vector sol_ptr_vector
Soletta pointer vector is a wrapper around vector with an API more convenient to handle pointers...
int sol_ptr_vector_set(struct sol_ptr_vector *pv, uint16_t i, const void *ptr)
Set the element at index i to be ptr.
int sol_vector_del_element(struct sol_vector *v, const void *elem)
Remove an element from the vector.
static int sol_ptr_vector_del(struct sol_ptr_vector *pv, uint16_t i)
Remove the pointer of index i from the vector.
Definition: sol-vector.h:541
int32_t sol_ptr_vector_update_sorted(struct sol_ptr_vector *pv, uint16_t i, int(*compare_cb)(const void *data1, const void *data2))
Update sorted pointer vector so the element is still in order.
uint16_t len
Vector length.
Definition: sol-vector.h:60
int sol_ptr_vector_insert_at(struct sol_ptr_vector *pv, uint16_t i, const void *ptr)
Insert a pointer in the pointer vector at a given position.
void * data
Vector data.
Definition: sol-vector.h:59
void sol_vector_init(struct sol_vector *v, uint16_t elem_size)
Initializes a sol_vector structure.
static uint16_t sol_ptr_vector_get_len(const struct sol_ptr_vector *pv)
Returns the number of pointers stored in the vector.
Definition: sol-vector.h:352
static void * sol_vector_steal_data(struct sol_vector *v)
Steal the memory holding the elements of the vector.
Definition: sol-vector.h:236
struct sol_vector sol_vector
Soletta vector is an array that grows dynamically.
static void sol_ptr_vector_init(struct sol_ptr_vector *pv)
Initializes a sol_ptr_vector structure.
Definition: sol-vector.h:326
int32_t sol_ptr_vector_match_sorted(const struct sol_ptr_vector *pv, const void *tempt, int(*compare_cb)(const void *data1, const void *data2))
Match for occurrence matching template tempt in the sorted vector pv.
Soletta pointer vector is a wrapper around vector with an API more convenient to handle pointers...
Definition: sol-vector.h:310
int sol_vector_del_range(struct sol_vector *v, uint16_t start, uint16_t len)
Remove an range of element from the vector.
int sol_vector_del(struct sol_vector *v, uint16_t i)
Remove an element from the vector.
Soletta vector is an array that grows dynamically.
Definition: sol-vector.h:58
static void * sol_ptr_vector_steal_last(struct sol_ptr_vector *pv)
Remove and return the last element from the vector.
Definition: sol-vector.h:625
#define SOL_PTR_VECTOR_FOREACH_REVERSE_IDX(vector, itrvar, idx)
Macro to iterate over the pointer vector easily in the reverse order.
Definition: sol-vector.h:701
static int32_t sol_ptr_vector_find_first(const struct sol_ptr_vector *pv, const void *elem)
Find the first occurrence of elem from the vector pv.
Definition: sol-vector.h:760
static int32_t sol_ptr_vector_match_first(const struct sol_ptr_vector *pv, const void *tempt, int(*compare_cb)(const void *data1, const void *data2))
Match for the first occurrence matching template tempt.
Definition: sol-vector.h:798
void sol_vector_clear(struct sol_vector *v)
Delete all elements from the vector.
static void * sol_ptr_vector_get_no_check(const struct sol_ptr_vector *pv, uint16_t i)
Return the element of the vector at the given index (no safety checks).
Definition: sol-vector.h:388
static int sol_ptr_vector_del_last(struct sol_ptr_vector *pv)
Remove the last element from the vector.
Definition: sol-vector.h:589
void * sol_vector_append(struct sol_vector *v)
Append an element to the end of the vector.
int sol_ptr_vector_append(struct sol_ptr_vector *pv, const void *ptr)
Append a pointer to the end of the vector.
static void * sol_vector_get(const struct sol_vector *v, uint16_t i)
Return the element of the vector at the given index.
Definition: sol-vector.h:146