libcute 0.1
Loading...
Searching...
No Matches
Classes | Enumerations | Functions
vector.h File Reference
#include "macro.h"
#include "memory/allocator.h"
#include "object/optional.h"
#include "object/result.h"
#include "object/destructor.h"
#include "utility.h"
#include <stddef.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.

Classes

struct  cu_Vector
 Growable array of elements. More...
 

Enumerations

enum  cu_Vector_Error {
  CU_VECTOR_ERROR_NONE = 0 , CU_VECTOR_ERROR_OOM , CU_VECTOR_ERROR_INVALID_LAYOUT , CU_VECTOR_ERROR_INVALID ,
  CU_VECTOR_ERROR_OOB
}
 Error codes returned by vector operations. More...
 

Functions

cu_Vector_Result cu_Vector_create (cu_Allocator allocator, cu_Layout layout, Size_Optional initial_capacity, cu_Destructor_Optional destructor)
 
cu_Vector_Error_Optional cu_Vector_resize (cu_Vector *vector, size_t size)
 Change the number of stored elements.
 
void cu_Vector_destroy (cu_Vector *vector)
 
cu_Vector_Error_Optional cu_Vector_push_back (cu_Vector *vector, void *elem)
 
cu_Vector_Error_Optional cu_Vector_pop_back (cu_Vector *vector, void *out_elem)
 
cu_Vector_Error_Optional cu_Vector_push_front (cu_Vector *vector, void *elem)
 
cu_Vector_Error_Optional cu_Vector_pop_front (cu_Vector *vector, void *out_elem)
 
cu_Vector_Result cu_Vector_copy (const cu_Vector *src)
 
cu_Vector_Error_Optional cu_Vector_reserve (cu_Vector *vector, size_t capacity)
 
cu_Vector_Error_Optional cu_Vector_shrink_to_fit (cu_Vector *vector)
 
void cu_Vector_clear (cu_Vector *vector)
 
Ptr_Optional cu_Vector_at (const cu_Vector *vector, size_t index)
 Return a pointer to the element at index.
 
bool cu_Vector_iter (const cu_Vector *vector, size_t *index, void **out_elem)
 Iterate over the vector elements.
 
cu_Slice_Optional cu_Vector_slice (const cu_Vector *vector)
 
cu_Slice_Optional cu_Vector_subslice (const cu_Vector *vector, size_t index, size_t count)
 

Detailed Description

Growable vector container.

Enumeration Type Documentation

◆ cu_Vector_Error

Error codes returned by vector operations.

Enumerator
CU_VECTOR_ERROR_NONE 

success

CU_VECTOR_ERROR_OOM 

out of memory

CU_VECTOR_ERROR_INVALID_LAYOUT 

invalid element layout

CU_VECTOR_ERROR_INVALID 

invalid argument

CU_VECTOR_ERROR_OOB 

out of bounds access

Function Documentation

◆ cu_Vector_at()

Ptr_Optional cu_Vector_at ( const cu_Vector vector,
size_t  index 
)

Return a pointer to the element at index.

If the index is out of bounds the optional contains none.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_clear()

void cu_Vector_clear ( cu_Vector vector)

Reset the vector.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_copy()

cu_Vector_Result cu_Vector_copy ( const cu_Vector src)

Duplicate the contents of src into a new vector.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_create()

cu_Vector_Result cu_Vector_create ( cu_Allocator  allocator,
cu_Layout  layout,
Size_Optional  initial_capacity,
cu_Destructor_Optional  destructor 
)

Create a new vector.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_destroy()

void cu_Vector_destroy ( cu_Vector vector)

Release resources owned by vector.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_iter()

bool cu_Vector_iter ( const cu_Vector vector,
size_t *  index,
void **  out_elem 
)

Iterate over the vector elements.

Parameters
vectorvector to iterate
indexcurrent index, pass NULL for the first call
out_elemreceives a pointer to the element
Returns
true when another element was produced
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_pop_back()

cu_Vector_Error_Optional cu_Vector_pop_back ( cu_Vector vector,
void *  out_elem 
)

Remove the last element and copy it into out_elem.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_pop_front()

cu_Vector_Error_Optional cu_Vector_pop_front ( cu_Vector vector,
void *  out_elem 
)

Remove the first element and copy it into out_elem.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_push_back()

cu_Vector_Error_Optional cu_Vector_push_back ( cu_Vector vector,
void *  elem 
)

Append a new element to the end of the vector.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_push_front()

cu_Vector_Error_Optional cu_Vector_push_front ( cu_Vector vector,
void *  elem 
)

Insert an element at the beginning of the vector.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_reserve()

cu_Vector_Error_Optional cu_Vector_reserve ( cu_Vector vector,
size_t  capacity 
)

Ensure at least capacity slots are allocated.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_resize()

cu_Vector_Error_Optional cu_Vector_resize ( cu_Vector vector,
size_t  size 
)

Change the number of stored elements.

The vector grows to at least size elements, reserving additional capacity when required. When shrinking, elements are discarded but the underlying buffer is retained.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_shrink_to_fit()

cu_Vector_Error_Optional cu_Vector_shrink_to_fit ( cu_Vector vector)

Reduce capacity to the current size.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_slice()

cu_Slice_Optional cu_Vector_slice ( const cu_Vector vector)

View the entire vector as a byte slice.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cu_Vector_subslice()

cu_Slice_Optional cu_Vector_subslice ( const cu_Vector vector,
size_t  index,
size_t  count 
)

Obtain a slice starting at index covering count elements.

Here is the call graph for this function:
Here is the caller graph for this function: