CVEC v1.0.0-build
Functional C++ vector-like manipulation for C
Loading...
Searching...
No Matches
cvec.h File Reference

Go to the source code of this file.

Classes

struct  CVEC
 Custom generic dynamic vector type. More...

Functions

int __cvec_del (CVEC *_vec, void *_elem)
 Delete first occurrence of matching value.
int __cvec_delIndex (CVEC *_vec, void *_elem, const size_t start)
 Delete matching element starting search at index.
int __cvec_destroySplit (CVEC *_vec)
 Cleanup after split operations.
int __cvec_find (const CVEC *_vec, void *_find)
 Search for an element in the vector.
bool __cvec_hasEnoughCap (const CVEC *_vec, const size_t _additions)
 Check whether capacity is sufficient for requested additions.
int __cvec_push (CVEC *_vec, void *_elem)
 Insert at end of vector.
int __cvec_pushFront (CVEC *_vec, void *_elem)
 Insert new element at beginning.
int __cvec_pushIndex (CVEC *_vec, const size_t _index, void *_elem)
 Insert element at specific index, shifting elements as needed.
int __cvec_set (CVEC *_vec, const size_t _index, void *_set)
 Replace value at given index.
bool cvec_at (const CVEC *_vec, const size_t _index)
 Check whether element exists at index.
bool cvec_atCap (const CVEC *_vec, const size_t _index)
 Check whether element exists within vector capacity.
void cvec_clear (CVEC *_vec)
 Clear vector contents but keep capacity unchanged.
int cvec_destroy (CVEC *_vec)
 Destroy a CVEC, freeing allocated memory and invalidating the structure.
int cvec_emptyAll (CVEC *_vec)
 Clear all elements and reset size to zero without freeing memory.
void * cvec_get (const CVEC *_vec, const size_t _index)
 Get a pointer to an element at specified index.
CVEC cvec_init (int _cap, size_t _elemSize)
 Initialize a new vector with requested capacity and element size.
CVEC cvec_initCopy (const CVEC *_src)
 Create a deep copy of an existing CVEC.
int cvec_merge (CVEC *_toMerge, const CVEC *_input)
 Merge contents of _input vector into _toMerge.
int cvec_popBack (CVEC *_vec)
 Remove the last element.
int cvec_popFront (CVEC *_vec)
 Remove the first element, shifting all others left.
int cvec_remove (CVEC *_vec, const size_t _index)
 Remove an element at a specific index.
int cvec_reverse (CVEC *_vec)
 Reverse the order of elements in place.
int cvec_shrink (CVEC *_vec)
 Shrink allocated memory to match current size.
int cvec_split (CVEC *_vec, char *_str, const char *_del)
 Split a string by delimiter and store parts inside CVEC.
void cvec_swap (CVEC *_a, CVEC *_b)
 Swap two CVEC instances.

Function Documentation

◆ __cvec_del()

int __cvec_del ( CVEC * _vec,
void * _elem )

Delete first occurrence of matching value.

◆ __cvec_delIndex()

int __cvec_delIndex ( CVEC * _vec,
void * _elem,
const size_t start )

Delete matching element starting search at index.

◆ __cvec_destroySplit()

int __cvec_destroySplit ( CVEC * _vec)

Cleanup after split operations.

◆ __cvec_find()

int __cvec_find ( const CVEC * _vec,
void * _find )

Search for an element in the vector.

Returns
index or CVEC_NPOS

◆ __cvec_hasEnoughCap()

bool __cvec_hasEnoughCap ( const CVEC * _vec,
const size_t _additions )

Check whether capacity is sufficient for requested additions.

Returns
true if capacity allows, else false

◆ __cvec_push()

int __cvec_push ( CVEC * _vec,
void * _elem )

Insert at end of vector.

Parameters
_vecVector
_elemPointer to element data to store
Returns
CVEC_SUCCESS or an error code

◆ __cvec_pushFront()

int __cvec_pushFront ( CVEC * _vec,
void * _elem )

Insert new element at beginning.

Returns
CVEC_SUCCESS or CVEC_NOT_ENOUGH_CAP

◆ __cvec_pushIndex()

int __cvec_pushIndex ( CVEC * _vec,
const size_t _index,
void * _elem )

Insert element at specific index, shifting elements as needed.

◆ __cvec_set()

int __cvec_set ( CVEC * _vec,
const size_t _index,
void * _set )

Replace value at given index.

◆ cvec_at()

bool cvec_at ( const CVEC * _vec,
const size_t _index )

Check whether element exists at index.

Parameters
_vecVector to inspect
_indexElement index
Returns
true if valid index, false otherwise

◆ cvec_atCap()

bool cvec_atCap ( const CVEC * _vec,
const size_t _index )

Check whether element exists within vector capacity.

Parameters
_vecVector to inspect
_indexIndex inside original allocated capacity
Returns
true if index < capacity, else false

◆ cvec_clear()

void cvec_clear ( CVEC * _vec)

Clear vector contents but keep capacity unchanged.

Parameters
_vecPointer to vector

◆ cvec_destroy()

int cvec_destroy ( CVEC * _vec)

Destroy a CVEC, freeing allocated memory and invalidating the structure.

Parameters
_vecPointer to the CVEC to destroy
Returns
CVEC_SUCCESS on success, or CVEC_FAIL

◆ cvec_emptyAll()

int cvec_emptyAll ( CVEC * _vec)

Clear all elements and reset size to zero without freeing memory.

Parameters
_vecPointer to the vector
Returns
CVEC_SUCCESS on success, else CVEC_FAIL

◆ cvec_get()

void * cvec_get ( const CVEC * _vec,
const size_t _index )

Get a pointer to an element at specified index.

Parameters
_vecVector to inspect
_indexPosition to access
Returns
Pointer to element or NULL if invalid

◆ cvec_init()

CVEC cvec_init ( int _cap,
size_t _elemSize )

Initialize a new vector with requested capacity and element size.

Parameters
_capInitial capacity (number of elements, not bytes)
_elemSizeSize in bytes of each element
Returns
A fully initialized CVEC instance

◆ cvec_initCopy()

CVEC cvec_initCopy ( const CVEC * _src)

Create a deep copy of an existing CVEC.

Copies memory, capacity, element properties, and flags.

Parameters
_srcPointer to the original CVEC
Returns
A new CVEC instance with copied data

◆ cvec_merge()

int cvec_merge ( CVEC * _toMerge,
const CVEC * _input )

Merge contents of _input vector into _toMerge.

Appends all items from _input to _toMerge, expanding capacity if allowed.

Parameters
_toMergeDestination vector to merge into
_inputVector to merge from
Returns
CVEC_SUCCESS or error code (CVEC_FAIL, CVEC_NOT_ENOUGH_CAP, ...)

◆ cvec_popBack()

int cvec_popBack ( CVEC * _vec)

Remove the last element.

Parameters
_vecVector to modify
Returns
CVEC_SUCCESS or CVEC_FAIL

◆ cvec_popFront()

int cvec_popFront ( CVEC * _vec)

Remove the first element, shifting all others left.

Parameters
_vecVector to modify
Returns
CVEC_SUCCESS or CVEC_FAIL

◆ cvec_remove()

int cvec_remove ( CVEC * _vec,
const size_t _index )

Remove an element at a specific index.

Shifts trailing elements left by one.

Parameters
_vecPointer to vector
_indexIndex to remove
Returns
CVEC_SUCCESS, CVEC_OUT_BOUNDS, or CVEC_FAIL

◆ cvec_reverse()

int cvec_reverse ( CVEC * _vec)

Reverse the order of elements in place.

Parameters
_vecPointer to CVEC
Returns
CVEC_SUCCESS or CVEC_FAIL

◆ cvec_shrink()

int cvec_shrink ( CVEC * _vec)

Shrink allocated memory to match current size.

Parameters
_vecPointer to vector
Returns
CVEC_SUCCESS or CVEC_FAIL_ALLOCATION

◆ cvec_split()

int cvec_split ( CVEC * _vec,
char * _str,
const char * _del )

Split a string by delimiter and store parts inside CVEC.

Internal __usedSplit tracks cleanup ownership.

Parameters
_vecDestination vector
_strInput string to tokenize
_delDelimiter string
Returns
CVEC_SUCCESS or CVEC_FAIL

◆ cvec_swap()

void cvec_swap ( CVEC * _a,
CVEC * _b )

Swap two CVEC instances.

Parameters
_aFirst vector
_bSecond vector