20#define TMP_REF(type, value) (type[1]){value}
78#define VECTOR_DEFAULT_ARGS \
97typedef bool (*
predicate_t) (
const void *
const element,
void *
const param);
108typedef ssize_t (*
compare_t) (
const void *
const value,
const void *
const element,
void *
const param);
120typedef int (*
foreach_t) (
const void *
const element,
void *
const param);
133typedef int (*
aggregate_t) (
const void *
const element,
void *
const acc,
void *
const param);
145typedef int (*
transform_t) (
void *
const element,
void *
const param);
153#define alloc_opts(...) (alloc_opts_t){__VA_ARGS__}
162#define vector_create(...) \
165 VECTOR_DEFAULT_ARGS,\
329 const void *
const value,
347 const void *
const value,
411 const size_t length);
426 const size_t length);
447 const size_t part_offset,
448 const size_t part_length);
480 const ssize_t shift);
492 const size_t index_a,
493 const size_t index_b);
563void *
vector_alloc(
const size_t alloc_size,
void *
const param);
575void *
vector_realloc(
void *ptr,
const size_t alloc_size,
void *
const param);
606ssize_t
cmp_lex_asc(
const void *
const value,
const void *
const element,
void *
const param);
614ssize_t
cmp_lex_dsc(
const void *
const value,
const void *
const element,
void *
const param);
void * vector_realloc(void *ptr, const size_t alloc_size, void *const param)
Reallocates already allocated memory chunk in order to change allocation size.
void * vector_alloc(const size_t alloc_size, void *const param)
Allocates memory chunk of alloc_size.
void vector_free(void *ptr, void *const param)
Free allocation that was previously allocated.
int(* foreach_t)(const void *const element, void *const param)
Callback determines an operation for vector_foreach.
int(* transform_t)(void *const element, void *const param)
Callback determines an operation for vector_transform.
bool(* predicate_t)(const void *const element, void *const param)
Predicate, tells if traversed element matches user's criteria.
int(* aggregate_t)(const void *const element, void *const acc, void *const param)
Callback determines an operation for vector_aggregate.
ssize_t(* compare_t)(const void *const value, const void *const element, void *const param)
Compare, used to define traversal order.
int vector_transform(vector_t *const vector, const size_t limit, const transform_t func, void *const param)
Perform mutable transformation on each element of the vector.
int vector_aggregate(const vector_t *const vector, const size_t limit, const aggregate_t func, void *const acc, void *const param)
Perform immutable accamulating action on each element of the vector.
void vector_shift(vector_t *const vector, const size_t offset, const size_t length, const ssize_t shift)
Shift range of elements.
void vector_part_copy(const vector_t *const vector, char *dest, const size_t offset, const size_t length, const size_t part_offset, const size_t part_length)
Partial copying.
void vector_spread(vector_t *const vector, const size_t index, const size_t amount)
Duplicates existing element across range.
void * vector_get(const vector_t *const vector, const size_t index)
Returns pointer for the element at index.
int vector_foreach(const vector_t *const vector, const size_t limit, const foreach_t func, void *const param)
Perform immutable action on each element of the vector.
void vector_move(const vector_t *const vector, char *dest, const size_t offset, const size_t length)
Moves range of the vector elements to another location.
void vector_set(vector_t *const vector, const size_t index, const void *const value)
Sets element at given index to a value.
void vector_copy(const vector_t *const vector, char *dest, const size_t offset, const size_t length)
Copy element range to other location.
char * vector_data(const vector_t *const vector)
Gives a pointer to a location where elements' data begins.
void vector_swap(vector_t *const vector, const size_t index_a, const size_t index_b)
Swaps values of elements designated by indicies.
void vector_set_zero(vector_t *const vector, const size_t index)
Sets element at given index to a zero value.
size_t vector_data_offset(const vector_t *const vector)
Compute offset from vector_t::memory to first element.
size_t vector_ext_header_size(const vector_t *const vector)
Retrieves extended header size.
void * vector_get_ext_header(const vector_t *const vector)
Provides a location where user can put a header for the derived class.
vector_status_t vector_resize(vector_t **const vector, const size_t capacity, const vector_status_t error)
Performs allocation resize.
vector_t * vector_clone(const vector_t *const vector)
Duplicates a vector.
void vector_destroy(vector_t *const vector)
Deallocates vector.
vector_t * vector_create_(const vector_opts_t *const opts)
Vector contructor.
size_t vector_capacity_bytes(const vector_t *const vector)
Reports current capacity of the vector in bytes.
size_t vector_element_size(const vector_t *const vector)
Reports current element size.
size_t vector_capacity(const vector_t *const vector)
Reports current capacity of the vector.
alloc_opts_t vector_alloc_opts(const vector_t *const vector)
Access allocator options.
void * vector_linear_find(const vector_t *const vector, const size_t limit, const predicate_t predicate, void *const param)
Simple linear search for unordered data.
void * vector_binary_find(const vector_t *const vector, const void *const value, const size_t limit, const compare_t cmp, void *const param)
Run binary search on the vector.
ssize_t vector_binary_find_index(const vector_t *const vector, const void *const value, const size_t limit, const compare_t cmp, void *const param)
Run binary search on the vector.
ssize_t cmp_lex_asc(const void *const value, const void *const element, void *const param)
Performs comparison in lexicographical ascending order.
size_t calc_aligned_size(const size_t size, const size_t alignment)
Function calculates size of the element while respecting requirement for alignment.
ssize_t cmp_lex_dsc(const void *const value, const void *const element, void *const param)
Performs comparison in lexicographical descending order.
size_t size
Size of the allocator data.
void * data
User defined allocator structure.
size_t element_size
Size of the underling element type.
alloc_opts_t alloc_opts
optional allocator
size_t initial_cap
Amount of elements that will be preallocated.
size_t ext_header_size
Size of the extention header.
Vector control structure type.
vector_status_t
Status enum that indicates errors of operations that may fail.