Vector 1.0.0
Loading...
Searching...
No Matches
vector.h File Reference

Public interface of the vector. More...

#include <stdbool.h>
#include <stddef.h>
#include <sys/types.h>
Include dependency graph for vector.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  alloc_opts_t
 Allocator options. More...
 
struct  vector_opts_t
 Vector options. More...
 

Macros

#define TMP_REF(type, value)   (type[1]){value}
 Create temporary typed reference.
 
#define VECTOR_DEFAULT_ARGS    .initial_cap = 10
 
#define alloc_opts(...)   (alloc_opts_t){__VA_ARGS__}
 Use this macro to define allocator opts in vector_opts_t.
 
#define vector_create(...)
 Vector constructor.
 

Typedefs

typedef bool(* predicate_t) (const void *const element, void *const param)
 Predicate, tells if traversed element matches user's criteria.
 
typedef ssize_t(* compare_t) (const void *const value, const void *const element, void *const param)
 Compare, used to define traversal order.
 
typedef int(* foreach_t) (const void *const element, void *const param)
 Callback determines an operation for vector_foreach.
 
typedef int(* aggregate_t) (const void *const element, void *const acc, void *const param)
 Callback determines an operation for vector_aggregate.
 
typedef int(* transform_t) (void *const element, void *const param)
 Callback determines an operation for vector_transform.
 

Enumerations

enum  vector_status_t { VECTOR_SUCCESS = 0 , VECTOR_ALLOC_ERROR , VECTOR_STATUS_LAST }
 Status enum that indicates errors of operations that may fail. More...
 

Functions

vector_tvector_create_ (const vector_opts_t *const opts)
 Vector contructor.
 
void vector_destroy (vector_t *const vector)
 Deallocates vector.
 
vector_tvector_clone (const vector_t *const vector)
 Duplicates a vector.
 
vector_status_t vector_resize (vector_t **const vector, const size_t capacity, const vector_status_t error)
 Performs allocation resize.
 
void * vector_get_ext_header (const vector_t *const vector)
 Provides a location where user can put a header for the derived class.
 
size_t vector_ext_header_size (const vector_t *const vector)
 Retrieves extended header size.
 
size_t vector_data_offset (const vector_t *const vector)
 Compute offset from vector_t::memory to first element.
 
alloc_opts_t vector_alloc_opts (const vector_t *const vector)
 Access allocator options.
 
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.
 
size_t vector_capacity_bytes (const vector_t *const vector)
 Reports current capacity of the vector in bytes.
 
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.
 
char * vector_data (const vector_t *const vector)
 Gives a pointer to a location where elements' data begins.
 
void * vector_get (const vector_t *const vector, const size_t index)
 Returns pointer for the element at index.
 
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_set_zero (vector_t *const vector, const size_t index)
 Sets element at given index to a zero 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.
 
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_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_shift (vector_t *const vector, const size_t offset, const size_t length, const ssize_t shift)
 Shift range of elements.
 
void vector_swap (vector_t *const vector, const size_t index_a, const size_t index_b)
 Swaps values of elements designated by indicies.
 
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.
 
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.
 
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.
 
void * vector_alloc (const size_t alloc_size, void *const param)
 Allocates memory chunk of alloc_size.
 
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_free (void *ptr, void *const param)
 Free allocation that was previously allocated.
 
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_asc (const void *const value, const void *const element, void *const param)
 Performs comparison in lexicographical ascending order.
 
ssize_t cmp_lex_dsc (const void *const value, const void *const element, void *const param)
 Performs comparison in lexicographical descending order.
 

Detailed Description

Public interface of the vector.

Author
Evgeni Semenov

Definition in file vector.h.

Macro Definition Documentation

◆ TMP_REF

#define TMP_REF ( type,
value )   (type[1]){value}

Create temporary typed reference.

Used to create temporary reference to an object, that need to be passed via pointer. Life time of the referenced object is bounded by a scope in which it was defined.

Definition at line 20 of file vector.h.

◆ VECTOR_DEFAULT_ARGS

#define VECTOR_DEFAULT_ARGS    .initial_cap = 10

Represents vectors default create values.

Definition at line 78 of file vector.h.

Enumeration Type Documentation

◆ vector_status_t

Status enum that indicates errors of operations that may fail.

This enum is designed to be extended by user enums for derived containes.

Enumerator
VECTOR_SUCCESS 

Success operation status code, reserved.

VECTOR_ALLOC_ERROR 

Allocation error status code, reserved.

VECTOR_STATUS_LAST 

Indicates end of the enum values, can be used as next value in successor enum

Definition at line 67 of file vector.h.