gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
m_vector.h
Go to the documentation of this file.
1#ifndef __M_VECTOR
2#define __M_VECTOR
3
4typedef struct M_Vector_ {
7#define ARRAY_OFFSET SZ_INT * 3
8#define ARRAY_PTR(array) (array->ptr + ARRAY_OFFSET)
9#define ARRAY_LEN(array) *(m_uint *)(array->ptr)
10#define ARRAY_SIZE(array) *(m_uint *)(array->ptr + SZ_INT)
11#define ARRAY_CAP(array) *(m_uint *)(array->ptr + SZ_INT * 2)
12
13ANN static inline m_uint m_vector_size(const M_Vector v) {
14 return ARRAY_LEN(v);
15}
16
17ANN static inline void m_vector_get(const M_Vector v, const m_uint i, void *c) {
18 const m_uint size = ARRAY_SIZE(v);
19 memcpy(c, ARRAY_PTR(v) + i * size, size);
20}
21
22ANN static inline m_bit *m_vector_addr(const M_Vector v, const m_uint i) {
23 return &*(m_bit *)(ARRAY_PTR(v) + i * ARRAY_SIZE(v));
24}
25
26void m_vector_init(const M_Vector array, const m_uint size, const m_uint len);
27
28ANN static inline M_Vector new_m_vector(MemPool p, const m_uint size,
29 const m_uint len) {
30 const M_Vector array = (M_Vector)mp_calloc(p, M_Vector);
31 m_vector_init(array, size, len);
32 return array;
33}
34
35ANN static inline void m_vector_release(M_Vector a) { xfree(a->ptr); }
36
37ANN static inline void free_m_vector(MemPool p, M_Vector a) {
39 mp_free(p, M_Vector, a);
40}
41
42ANN void m_vector_set(const M_Vector, const m_uint, const void *);
43ANN void m_vector_add(const M_Vector, const void *);
44ANN void m_vector_rem(const M_Vector, const m_uint);
45ANN void m_vector_insert(const M_Vector v, m_uint index, const void *data);
46ANN void m_vector_add_front(const M_Vector v, const void *data);
47#endif
#define ANN
Definition defs.h:19
uintptr_t m_uint
Definition gwcommon.h:11
unsigned char m_bit
Definition gwcommon.h:12
ANN void m_vector_add_front(const M_Vector v, const void *data)
Definition m_vector.c:24
ANN void m_vector_set(const M_Vector, const m_uint, const void *)
Definition m_vector.c:31
#define ARRAY_LEN(array)
Definition m_vector.h:9
static ANN m_uint m_vector_size(const M_Vector v)
Definition m_vector.h:13
static ANN M_Vector new_m_vector(MemPool p, const m_uint size, const m_uint len)
Definition m_vector.h:28
#define ARRAY_SIZE(array)
Definition m_vector.h:10
ANN void m_vector_insert(const M_Vector v, m_uint index, const void *data)
Definition m_vector.c:45
void m_vector_init(const M_Vector array, const m_uint size, const m_uint len)
Definition m_vector.c:8
struct M_Vector_ * M_Vector
ANN void m_vector_rem(const M_Vector, const m_uint)
Definition m_vector.c:36
ANN void m_vector_add(const M_Vector, const void *)
Definition m_vector.c:18
static ANN void m_vector_get(const M_Vector v, const m_uint i, void *c)
Definition m_vector.h:17
static ANN void free_m_vector(MemPool p, M_Vector a)
Definition m_vector.h:37
#define ARRAY_PTR(array)
Definition m_vector.h:8
static ANN void m_vector_release(M_Vector a)
Definition m_vector.h:35
static ANN m_bit * m_vector_addr(const M_Vector v, const m_uint i)
Definition m_vector.h:22
#define mp_calloc(p, name)
Definition mpool.h:26
#define mp_free(p, name, a)
Definition mpool.h:27
m_bit * ptr
Definition m_vector.h:5
#define xfree(a)
Definition xalloc.h:28