Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions
Pointer Vector

Soletta pointer vector is a convenience API to manipulate vectors storing pointers that is based on Soletta Vector. More...

Data Structures

struct  sol_ptr_vector
 Soletta pointer vector is a wrapper around vector with an API more convenient to handle pointers. More...
 

Macros

#define SOL_PTR_VECTOR_FOREACH_IDX(vector, itrvar, idx)
 Macro to iterate over the pointer vector easily. More...
 
#define SOL_PTR_VECTOR_FOREACH_IDX_UNTIL(vector, itrvar, idx, until)
 Macro to iterate over the pointer vector until a index. More...
 
#define SOL_PTR_VECTOR_FOREACH_REVERSE_IDX(vector, itrvar, idx)
 Macro to iterate over the pointer vector easily in the reverse order. More...
 
#define SOL_PTR_VECTOR_INIT   { { NULL, 0, sizeof(void *) } }
 Helper macro to initialize a struct sol_ptr_vector. More...
 

Typedefs

typedef struct sol_ptr_vector sol_ptr_vector
 Soletta pointer vector is a wrapper around vector with an API more convenient to handle pointers. More...
 

Functions

int sol_ptr_vector_append (struct sol_ptr_vector *pv, const void *ptr)
 Append a pointer to the end of the vector. More...
 
static void sol_ptr_vector_clear (struct sol_ptr_vector *pv)
 Delete all elements from the vector. More...
 
static int sol_ptr_vector_del (struct sol_ptr_vector *pv, uint16_t i)
 Remove the pointer of index i from the vector. More...
 
int sol_ptr_vector_del_element (struct sol_ptr_vector *pv, const void *elem)
 Remove all occurrences of elem from the vector pv. More...
 
static int sol_ptr_vector_del_last (struct sol_ptr_vector *pv)
 Remove the last element from the vector. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static uint16_t sol_ptr_vector_get_len (const struct sol_ptr_vector *pv)
 Returns the number of pointers stored in the vector. More...
 
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). More...
 
static void sol_ptr_vector_init (struct sol_ptr_vector *pv)
 Initializes a sol_ptr_vector structure. More...
 
int sol_ptr_vector_init_n (struct sol_ptr_vector *pv, uint16_t n)
 Initializes a sol_ptr_vector structure and preallocates n elements. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int sol_ptr_vector_remove (struct sol_ptr_vector *pv, const void *ptr)
 Remove an pointer from the vector. More...
 
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. More...
 
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. More...
 
static void * sol_ptr_vector_steal_data (struct sol_ptr_vector *pv)
 Steal the memory holding the elements of the vector. More...
 
static void * sol_ptr_vector_steal_last (struct sol_ptr_vector *pv)
 Remove and return the last element from the vector. More...
 
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. More...
 

Detailed Description

Soletta pointer vector is a convenience API to manipulate vectors storing pointers that is based on Soletta Vector.

See Also
Vector

Macro Definition Documentation

#define SOL_PTR_VECTOR_FOREACH_IDX (   vector,
  itrvar,
  idx 
)
Value:
for (idx = 0; \
idx < (vector)->base.len && \
((itrvar = (__typeof__(itrvar))sol_ptr_vector_get_no_check((vector), idx)), true); \
idx++)
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

Macro to iterate over the pointer vector easily.

Parameters
vectorThe pointer vector to iterate over
itrvarVariable pointing to the data on each iteration
idxIndex integer variable that is increased while iterating
Examples:
/src/samples/coap/lwm2m-server.c, /src/samples/crypto/sha256sum.c, /src/samples/design_patterns/stream_sample.c, /src/samples/http/server-sse.c, and /src/samples/network/netctl.c.

Referenced by _sol_glib_integration_source_fd_handler_data_find(), api_close(), get_location_object_status(), on_stdin(), request_input(), shutdown(), shutdown_server(), sol_netctl_find_service_by_name(), sol_ptr_vector_find_first(), and sol_ptr_vector_match_first().

#define SOL_PTR_VECTOR_FOREACH_IDX_UNTIL (   vector,
  itrvar,
  idx,
  until 
)
Value:
for (idx = 0; \
idx < until && \
((itrvar = (__typeof__(itrvar))sol_ptr_vector_get_no_check((vector), idx)), true); \
idx++)
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

Macro to iterate over the pointer vector until a index.

Parameters
vectorThe pointer vector to iterate over
itrvarVariable pointing to the current element's data on each iteration
idxIndex integer variable that is increased while iterating
untilThe index that the iteration should stop
#define SOL_PTR_VECTOR_FOREACH_REVERSE_IDX (   vector,
  itrvar,
  idx 
)
Value:
for (idx = (vector)->base.len - 1; \
idx != ((__typeof__(idx)) - 1) && \
(itrvar = (__typeof__(itrvar))sol_ptr_vector_get_no_check((vector), idx), true); \
idx--)
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

Macro to iterate over the pointer vector easily in the reverse order.

Parameters
vectorThe pointer vector to iterate over
itrvarVariable pointing to the data on each iteration
idxIndex integer variable that is decreased while iterating

Referenced by _sol_glib_integration_source_dispose(), _sol_glib_integration_source_fd_handlers_adjust(), sol_ptr_vector_find_last(), and sol_ptr_vector_match_last().

#define SOL_PTR_VECTOR_INIT   { { NULL, 0, sizeof(void *) } }

Helper macro to initialize a struct sol_ptr_vector.

Examples:
/src/samples/crypto/sha256sum.c, and /src/samples/http/server-sse.c.

Typedef Documentation

Soletta pointer vector is a wrapper around vector with an API more convenient to handle pointers.

Warning
Be careful when storing NULL pointers in the vector since some functions will return NULL as an error when failing to retrieve the data from vector elements.
See Also
struct sol_vector

Function Documentation

int sol_ptr_vector_append ( struct sol_ptr_vector pv,
const void *  ptr 
)

Append a pointer to the end of the vector.

Creates a new element in end of the vector and stores ptr on it.

Parameters
pvPointer Vector pointer
ptrPointer to be stored
Returns
0 on success, error code (always negative) otherwise
Remarks
Time complexity: amortized constant
Examples:
/src/samples/crypto/sha256sum.c, /src/samples/design_patterns/stream_sample.c, /src/samples/http/server-sse.c, and /src/samples/network/netctl.c.

Referenced by _sol_glib_integration_source_fd_handlers_adjust(), hash_file(), hash_stdin(), my_stream_api_feed(), request_events_cb(), and request_input().

static void sol_ptr_vector_clear ( struct sol_ptr_vector pv)
inlinestatic

Delete all elements from the vector.

And frees the memory allocated for them. The vector returns to the initial state (empty).

Parameters
pvPointer Vector pointer
Remarks
Time complexity: constant
Examples:
/src/samples/crypto/sha256sum.c, /src/samples/design_patterns/stream_sample.c, /src/samples/http/server-sse.c, and /src/samples/network/netctl.c.

References sol_ptr_vector::base, and sol_vector_clear().

Referenced by _sol_glib_integration_source_dispose(), api_close(), request_input(), shutdown(), and shutdown_server().

static int sol_ptr_vector_del ( struct sol_ptr_vector pv,
uint16_t  i 
)
inlinestatic

Remove the pointer of index i from the vector.

Parameters
pvPointer Vector pointer
iIndex of the element to remove
Returns
0 on success, error code (always negative) otherwise
Remarks
Time complexity: linear in distance between i and the end of the vector
See Also
sol_ptr_vector_del_element()
sol_ptr_vector_remove()
sol_ptr_vector_find()
sol_ptr_vector_match_sorted()
sol_ptr_vector_find_sorted()
Examples:
/src/samples/design_patterns/stream_sample.c.

References sol_ptr_vector::base, and sol_vector_del().

Referenced by _can_write(), _sol_glib_integration_source_fd_handlers_adjust(), sol_ptr_vector_del_last(), and sol_ptr_vector_steal().

int sol_ptr_vector_del_element ( struct sol_ptr_vector pv,
const void *  elem 
)

Remove all occurrences of elem from the vector pv.

Parameters
pvPointer Vector pointer
elemElement to remove
Returns
0 on success, error code (always negative) otherwise
Remarks
Time complexity: linear in vector size
See Also
sol_ptr_vector_del()
sol_ptr_vector_remove()
Examples:
/src/samples/design_patterns/stream_sample.c.

Referenced by my_stream_api_feed().

static int sol_ptr_vector_del_last ( struct sol_ptr_vector pv)
inlinestatic

Remove the last element from the vector.

Parameters
pvPointer Vector pointer
Returns
0 on success, error code (always negative) otherwise
Remarks
Time complexity: amortized constant

References sol_ptr_vector::base, sol_vector::len, and sol_ptr_vector_del().

static int sol_ptr_vector_del_range ( struct sol_ptr_vector pv,
uint16_t  start,
uint16_t  len 
)
inlinestatic

Remove an range of pointers from the vector.

Removes the range starting at index start from the vector and goes until start + len.

Parameters
pvPointer Vector pointer
startIndex of the first element to remove
lenthe number of elements to remover
Returns
0 on success, error code (always negative) otherwise

References sol_ptr_vector::base, and sol_vector_del_range().

static int32_t sol_ptr_vector_find_first ( const struct sol_ptr_vector pv,
const void *  elem 
)
inlinestatic

Find the first occurrence of elem from the vector pv.

Parameters
pvPointer Vector pointer
elemElement to find
Returns
index (>=0) on success, error code (always negative) otherwise
Remarks
Time complexity: linear between found element and the beginning of the vector
See Also
sol_ptr_vector_find_last()
sol_ptr_vector_find_first_sorted()
sol_ptr_vector_find_last_sorted()
sol_ptr_vector_match_first()
sol_ptr_vector_match_last()
sol_ptr_vector_match_sorted()
sol_ptr_vector_find_sorted()

References SOL_PTR_VECTOR_FOREACH_IDX.

static int32_t sol_ptr_vector_find_first_sorted ( const struct sol_ptr_vector pv,
const void *  elem,
int(*)(const void *data1, const void *data2)  compare_cb 
)
inlinestatic

Find the first occurrence of elem in the sorted vector pv.

Parameters
pvPointer Vector pointer (already sorted)
elemElement to find
compare_cbFunction to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order
Returns
index (>=0) on success, error code (always negative) otherwise
Remarks
Time complexity: logarithmic in vector size or linear in number of elements equal to elem, whichever is greater
See Also
sol_ptr_vector_find_first()
sol_ptr_vector_find_first()
sol_ptr_vector_find_first_sorted()
sol_ptr_vector_match_sorted()
sol_ptr_vector_match_first()
sol_ptr_vector_match_last()
sol_ptr_vector_find_sorted()
sol_ptr_vector_insert_sorted()

References sol_ptr_vector::base, sol_vector::len, sol_ptr_vector_get_no_check(), and sol_ptr_vector_match_sorted().

static int32_t sol_ptr_vector_find_last ( const struct sol_ptr_vector pv,
const void *  elem 
)
inlinestatic

Find the last occurrence of elem from the vector pv.

Parameters
pvPointer Vector pointer
elemElement to find
Returns
index (>=0) on success, error code (always negative) otherwise
Remarks
Time complexity: linear in distance between found element and the end of the vector
See Also
sol_ptr_vector_find_first()
sol_ptr_vector_find_first_sorted()
sol_ptr_vector_match_first()
sol_ptr_vector_match_last()
sol_ptr_vector_find_last_sorted()
sol_ptr_vector_match_sorted()
sol_ptr_vector_find_sorted()

References SOL_PTR_VECTOR_FOREACH_REVERSE_IDX.

static int32_t sol_ptr_vector_find_last_sorted ( const struct sol_ptr_vector pv,
const void *  elem,
int(*)(const void *data1, const void *data2)  compare_cb 
)
inlinestatic

Find the last occurrence of elem in the sorted vector pv.

Parameters
pvPointer Vector pointer (already sorted)
elemElement to find
compare_cbFunction to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order
Returns
index (>=0) on success, error code (always negative) otherwise
Remarks
Time complexity: logarithmic in vector size or linear in number of elements equal to elem, whichever is greater
See Also
sol_ptr_vector_find_first()
sol_ptr_vector_find_last()
sol_ptr_vector_find_first_sorted()
sol_ptr_vector_match_sorted()
sol_ptr_vector_match_first()
sol_ptr_vector_match_last()
sol_ptr_vector_find_sorted()
sol_ptr_vector_insert_sorted()

References sol_ptr_vector::base, sol_vector::len, sol_ptr_vector_get_no_check(), and sol_ptr_vector_match_sorted().

static int32_t sol_ptr_vector_find_sorted ( const struct sol_ptr_vector pv,
const void *  elem,
int(*)(const void *data1, const void *data2)  compare_cb 
)
inlinestatic

Find the exact occurrence of elem in the sorted vector pv.

This function will find the exact pointer to elem, so an existing element must be used. For a query-element (only used for reference in the compare_cb), use sol_ptr_vector_match_sorted().

Unlike sol_ptr_vector_find_first_sorted() and sol_ptr_vector_find_last_sorted(), it will do a binary search and return the first occurrence of the pointer elem. In the case of multiple occurrences, it may be an element in the middle of those that would match (compare_cb returns 0).

Parameters
pvPointer Vector pointer (already sorted)
elemElement to find
compare_cbFunction to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order
Returns
index (>=0) on success, error code (always negative) otherwise
Remarks
Time complexity: logarithmic in number of elements
See Also
sol_ptr_vector_find_first()
sol_ptr_vector_find_last()
sol_ptr_vector_find_first_sorted()
sol_ptr_vector_find_last_sorted()
sol_ptr_vector_find_sorted()
sol_ptr_vector_insert_sorted()
sol_ptr_vector_match_first()
sol_ptr_vector_match_last()
sol_ptr_vector_match_sorted()

References sol_ptr_vector::base, sol_vector::len, sol_ptr_vector_get_no_check(), and sol_ptr_vector_match_sorted().

static void* sol_ptr_vector_get ( const struct sol_ptr_vector pv,
uint16_t  i 
)
inlinestatic

Return the element of the vector at the given index.

Parameters
pvPointer Vector pointer
iIndex of the element to return
Returns
Pointer at the index i and NULL on errors.
Remarks
Time complexity: constant
Examples:
/src/samples/design_patterns/stream_sample.c.

References sol_ptr_vector::base, sol_vector::len, and sol_ptr_vector_get_no_check().

Referenced by _can_write(), and sol_ptr_vector_steal().

static uint16_t sol_ptr_vector_get_len ( const struct sol_ptr_vector pv)
inlinestatic

Returns the number of pointers stored in the vector.

Parameters
pvPointer to the struct sol_ptr_vector to be initialized
Returns
Number of elements in the vector
Remarks
Time complexity: constant
Examples:
/src/samples/coap/lwm2m-server.c, /src/samples/design_patterns/stream_sample.c, and /src/samples/http/server-sse.c.

References sol_ptr_vector::base, and sol_vector::len.

Referenced by _can_write(), delete_cb(), and get_location_object_status().

static void* sol_ptr_vector_get_no_check ( const struct sol_ptr_vector pv,
uint16_t  i 
)
inlinestatic

Return the element of the vector at the given index (no safety checks).

This is similar to sol_ptr_vector_get(), but does no safety checks such as array boundaries. Only use this whenever you're sure the index i exists.

Parameters
pvPointer Vector pointer
iIndex of the element to return
Returns
Pointer at the index i.
Remarks
Time complexity: constant
See Also
sol_ptr_vector_get()

References sol_ptr_vector::base, sol_vector::data, and sol_vector_get_no_check().

Referenced by sol_ptr_vector_find_first_sorted(), sol_ptr_vector_find_last_sorted(), sol_ptr_vector_find_sorted(), and sol_ptr_vector_get().

static void sol_ptr_vector_init ( struct sol_ptr_vector pv)
inlinestatic

Initializes a sol_ptr_vector structure.

Parameters
pvPointer to the struct sol_ptr_vector to be initialized
Examples:
/src/samples/design_patterns/stream_sample.c, and /src/samples/network/netctl.c.

References sol_ptr_vector::base, and sol_vector_init().

Referenced by my_stream_api_new(), request_input(), and sol_glib_integration().

int sol_ptr_vector_init_n ( struct sol_ptr_vector pv,
uint16_t  n 
)

Initializes a sol_ptr_vector structure and preallocates n elements.

Parameters
pvPointer to the struct sol_ptr_vector to be initialized
nNumber of elements that should be preallocated
Remarks
Time complexity: linear in the number of elements n
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.

This function inserts a new element ptr at index i. All existing elements with index greater than i will be moved, thus their index will increase by one. If the index is the last position (sol_ptr_vector_get_len()), then it will have the same effect as sol_ptr_vector_append().

Parameters
pvPointer Vector pointer
iIndex to insert element at.
ptrThe pointer
Returns
0 on success or negative errno on errors.
Remarks
Time complexity: amortized linear in number of elements between i and the end of the vector
See Also
sol_ptr_vector_append()
sol_ptr_vector_match_sorted()
sol_ptr_vector_find_sorted()
sol_ptr_vector_find_first_sorted()
sol_ptr_vector_find_last_sorted()
int32_t sol_ptr_vector_insert_sorted ( struct sol_ptr_vector pv,
const void *  ptr,
int(*)(const void *data1, const void *data2)  compare_cb 
)

Insert a pointer in the pointer vector, using the given comparison function to determine its position.

This function should be stable, if the new element ptr matches an existing in the vector (ie: compare_cb returns 0), then it will insert the new element after the last matching, keeping instances in a stable order.

Parameters
pvPointer Vector pointer
ptrThe pointer
compare_cbFunction to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order
Returns
index (>=0) or negative errno on errors.
Remarks
Time complexity: linear in number of elements between inserted position and the end of the vector or logarithmic in the size of the vector, whichever is greater
See Also
sol_ptr_vector_append()
sol_ptr_vector_insert_at()
sol_ptr_vector_match_sorted()
sol_ptr_vector_find_sorted()
sol_ptr_vector_find_first_sorted()
sol_ptr_vector_find_last_sorted()
static int32_t sol_ptr_vector_match_first ( const struct sol_ptr_vector pv,
const void *  tempt,
int(*)(const void *data1, const void *data2)  compare_cb 
)
inlinestatic

Match for the first occurrence matching template tempt.

Note
this function returns a match given compare_cb, that is, one that returns 0. To find the actual pointer element, use sol_ptr_vector_find_first().
Parameters
pvPointer Vector pointer
temptThe template used to find, the returned index may not be of tempt pointer, but to another element which makes compare_cb return 0.
compare_cbFunction to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order
Returns
index (>=0) on success, error code (always negative) otherwise
Remarks
Time complexity: linear in distance between the beginning of the vector and the matched element
See Also
sol_ptr_vector_match_last()
sol_ptr_vector_find_first()
sol_ptr_vector_find_first_sorted()

References SOL_PTR_VECTOR_FOREACH_IDX.

static int32_t sol_ptr_vector_match_last ( const struct sol_ptr_vector pv,
const void *  tempt,
int(*)(const void *data1, const void *data2)  compare_cb 
)
inlinestatic

Match for the last occurrence matching template tempt.

Note
this function returns a match given compare_cb, that is, one that returns 0. To find the actual pointer element, use sol_ptr_vector_find_first() or sol_ptr_vector_find_last().
Parameters
pvPointer Vector pointer
temptThe template used to find, the returned index may not be of tempt pointer, but to another element which makes compare_cb return 0.
compare_cbFunction to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order
Returns
index (>=0) on success, error code (always negative) otherwise
Remarks
Time complexity: linear in distance between the matched element and the end of the vector
See Also
sol_ptr_vector_match_first()
sol_ptr_vector_find_last()
sol_ptr_vector_find_last_sorted()

References SOL_PTR_VECTOR_FOREACH_REVERSE_IDX.

int32_t sol_ptr_vector_match_sorted ( const struct sol_ptr_vector pv,
const void *  tempt,
int(*)(const void *data1, const void *data2)  compare_cb 
)

Match for occurrence matching template tempt in the sorted vector pv.

Note
this function returns a match given compare_cb, that is, one that returns 0. To find the actual pointer element, use sol_ptr_vector_find_sorted().
Parameters
pvPointer Vector pointer (already sorted)
temptThe template used to find, the returned index may not be of tempt pointer, but to another element which makes compare_cb return 0.
compare_cbFunction to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order
Returns
index (>=0) on success, error code (always negative) otherwise
Remarks
Time complexity: logarithmic in vector size
See Also
sol_ptr_vector_find_first()
sol_ptr_vector_find_last()
sol_ptr_vector_find_first_sorted()
sol_ptr_vector_find_last_sorted()
sol_ptr_vector_find_sorted()
sol_ptr_vector_insert_sorted()
sol_ptr_vector_match_first()
sol_ptr_vector_match_last()

Referenced by sol_ptr_vector_find_first_sorted(), sol_ptr_vector_find_last_sorted(), and sol_ptr_vector_find_sorted().

int sol_ptr_vector_remove ( struct sol_ptr_vector pv,
const void *  ptr 
)

Remove an pointer from the vector.

Removes the last occurrence of the pointer ptr from the vector. To delete all use sol_ptr_vector_del_element()

Parameters
pvPointer Vector pointer
ptrPointer to remove
Returns
0 on success, error code (always negative) otherwise
Remarks
Time complexity: linear in number of elements between the ptr position and the end of the vector
See Also
sol_ptr_vector_del()
sol_ptr_vector_del_element()
Examples:
/src/samples/http/server-sse.c.

Referenced by delete_cb().

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.

Parameters
pvPointer Vector pointer
iIndex of the element to set
ptrThe pointer
Returns
0 on success, error code (always negative) otherwise
Remarks
Time complexity: constant
static void* sol_ptr_vector_steal ( struct sol_ptr_vector pv,
uint16_t  i 
)
inlinestatic

Remove and return the element at index i from the vector.

Parameters
pvPointer Vector pointer
iIndex of the element to retrieved
Returns
Pointer that was at index i, NULL otherwise
Remarks
Time complexity: linear in distance between i and the end of the vector

References sol_ptr_vector_del(), and sol_ptr_vector_get().

Referenced by sol_ptr_vector_steal_last().

static void* sol_ptr_vector_steal_data ( struct sol_ptr_vector pv)
inlinestatic

Steal the memory holding the elements of the vector.

And returns the vector to the initial state.

Parameters
pvPointer Vector pointer
Returns
Pointer to the memory containing the elements
Remarks
Time complexity: constant

References sol_ptr_vector::base, and sol_vector_steal_data().

static void* sol_ptr_vector_steal_last ( struct sol_ptr_vector pv)
inlinestatic

Remove and return the last element from the vector.

Parameters
pvPointer Vector pointer
Returns
Pointer that was in the last position from the vector, NULL otherwise
Remarks
Time complexity: amortized constant

References sol_ptr_vector::base, sol_vector::len, and sol_ptr_vector_steal().

int32_t sol_ptr_vector_update_sorted ( struct sol_ptr_vector pv,
uint16_t  i,
int(*)(const void *data1, const void *data2)  compare_cb 
)

Update sorted pointer vector so the element is still in order.

This function takes an index i and checks it is in correct order in the previously sorted array. It is an optimized version to be used instead of deleting and inserting it again, so array size is untouched.

Parameters
pvPointer Vector pointer
iThe index that was updated and may be repositioned
compare_cbFunction to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order
Returns
the index (>=0) on success, which may be the same if it wasn't changed, or negative errno on failure.
Remarks
Time complexity: linear in number of elements between updated position and the end of the vector or logarithmic in the size of the vector, whichever is greater