YAVL 0.1.0
Yet Another Vector Library – still better than C++ impl. :P
Loading...
Searching...
No Matches
vec.h
Go to the documentation of this file.
1
22#ifndef YAVL_VEC_H
23#define YAVL_VEC_H
24#pragma clang final(YAVL_VEC_H)
31
32#include <stddef.h>
33#include <stdbool.h>
34
35#ifndef YAVL_VEC_H_STRUCT
50typedef struct {
52 char[
53 sizeof(void*)+sizeof(size_t[3])
54 ] _raw;
56#else
57#undef YAVL_VEC_H_STRUCT
58#endif
59
62#define YAVL_VEC_T_ALLOCATOR ((yavl_vec_t){})
63
75
80typedef struct {
84 void *const mem;
86
96yavl_vec_res_t yavl_vec_init(yavl_vec_t *const memory,size_t data_align,size_t data_reserv);
105yavl_vec_res_t yavl_vec_push(yavl_vec_t *const vec, const void *const data);
142yavl_vec_res_t yavl_vec_set(yavl_vec_t* const vec, size_t offset, const void *const data);
152yavl_vec_res_t yavl_vec_get(yavl_vec_t* const vec, size_t offset, void *const out);
186bool yavl_vec_chkptr(const yavl_vec_t* const vec, const void *const ptr);
197 // VEC_H
199#endif /* YAVL_VEC_H */
yavl_vec_errorable_t yavl_vec_pop(yavl_vec_t *const vec)
Pops last elements out of vector. Doesn't free memory yet.
yavl_vec_errorable_t yavl_vec_ref(yavl_vec_t *const vec)
Get reference to dynamic vector array.
yavl_vec_res_t yavl_vec_set(yavl_vec_t *const vec, size_t offset, const void *const data)
Sets offset -th element of vector to data.
yavl_vec_res_t yavl_vec_init(yavl_vec_t *const memory, size_t data_align, size_t data_reserv)
Initializes a new vector. Frees memory if it is already allocated.
yavl_vec_res_t yavl_vec_push(yavl_vec_t *const vec, const void *const data)
Pushes data to vector.
yavl_vec_res_t yavl_vec_free(yavl_vec_t *const vec)
Frees heap in vector and zeroes the entire object.
yavl_vec_res_t
Operation result codes.
Definition vec.h:65
yavl_vec_errorable_t yavl_vec_flush(yavl_vec_t *const vec)
Finalizes vector, to result it in statically-sized array. This allows you to drop vector metadata.
yavl_vec_res_t yavl_vec_fit(yavl_vec_t *const vec)
Resizes vector space to the current size.
bool yavl_vec_chkptr(const yavl_vec_t *const vec, const void *const ptr)
Try to validate if the ptr pointer is in bounds of vec vector. This might be useful to ensure freshne...
yavl_vec_res_t yavl_vec_get(yavl_vec_t *const vec, size_t offset, void *const out)
Gets element at offset and stores it in out memory.
@ YAVL_VEC_RES_FAIL
Generic operation failure.
Definition vec.h:73
@ YAVL_VEC_RES_OOM
Out-of-memory, allocator failures.
Definition vec.h:67
@ YAVL_VEC_RES_NULL
Null pointer exception.
Definition vec.h:69
@ YAVL_VEC_RES_OK
Operation success.
Definition vec.h:71
A return package which contains both result code and data.
Definition vec.h:80
void *const mem
Data pointer, might be NULL on fatal failures.
Definition vec.h:84
yavl_vec_res_t status
Operation status (error code).
Definition vec.h:82
Type-agnostic vector definition.
Definition vec.h:50