|
libcute 0.1
|
#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>

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) |
Growable vector container.
| enum cu_Vector_Error |
| 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.


| void cu_Vector_clear | ( | cu_Vector * | vector | ) |
Reset the vector.


| cu_Vector_Result cu_Vector_copy | ( | const cu_Vector * | src | ) |
Duplicate the contents of src into a new vector.


| cu_Vector_Result cu_Vector_create | ( | cu_Allocator | allocator, |
| cu_Layout | layout, | ||
| Size_Optional | initial_capacity, | ||
| cu_Destructor_Optional | destructor | ||
| ) |
Create a new vector.


| void cu_Vector_destroy | ( | cu_Vector * | vector | ) |
Release resources owned by vector.


| bool cu_Vector_iter | ( | const cu_Vector * | vector, |
| size_t * | index, | ||
| void ** | out_elem | ||
| ) |
Iterate over the vector elements.
| vector | vector to iterate |
| index | current index, pass NULL for the first call |
| out_elem | receives a pointer to the element |


| cu_Vector_Error_Optional cu_Vector_pop_back | ( | cu_Vector * | vector, |
| void * | out_elem | ||
| ) |
Remove the last element and copy it into out_elem.


| cu_Vector_Error_Optional cu_Vector_pop_front | ( | cu_Vector * | vector, |
| void * | out_elem | ||
| ) |
Remove the first element and copy it into out_elem.


| cu_Vector_Error_Optional cu_Vector_push_back | ( | cu_Vector * | vector, |
| void * | elem | ||
| ) |
Append a new element to the end of the vector.


| cu_Vector_Error_Optional cu_Vector_push_front | ( | cu_Vector * | vector, |
| void * | elem | ||
| ) |
Insert an element at the beginning of the vector.


| cu_Vector_Error_Optional cu_Vector_reserve | ( | cu_Vector * | vector, |
| size_t | capacity | ||
| ) |
Ensure at least capacity slots are allocated.


| 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.


| cu_Vector_Error_Optional cu_Vector_shrink_to_fit | ( | cu_Vector * | vector | ) |
Reduce capacity to the current size.


| cu_Slice_Optional cu_Vector_slice | ( | const cu_Vector * | vector | ) |
View the entire vector as a byte slice.


| 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.

