gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
vector.h
Go to the documentation of this file.
1
5#ifndef __VECTOR
6#define __VECTOR
7
8typedef struct Vector_ {
11
13ANN extern void vector_init(const Vector);
14ANN extern Vector vector_copy(MemPool p, const Vector);
15ANN extern void vector_copy2(const __restrict__ Vector, __restrict__ Vector);
16ANN extern m_int vector_find(const Vector, const vtype);
17
18ANN static inline void vector_set(const Vector v, const vtype i,
19 const vtype arg) {
20 VPTR(v, i) = arg;
21}
22ANN static inline vtype vector_front(const Vector v) { return VPTR(v, 0); }
23ANN static inline vtype vector_at(const Vector v, const vtype i) {
24 return VPTR(v, i);
25}
26ANN static inline vtype vector_back(const Vector v) {
27 return VPTR(v, VLEN(v) - 1);
28}
29ANN static inline vtype vector_size(Vector const v) { return VLEN(v); }
30
31extern ANN void vector_add(const Vector, const vtype);
32extern ANN void vector_rem(const Vector, const vtype);
33extern ANN bool vector_rem2(const Vector, const vtype);
34extern ANN vtype vector_pop(const Vector);
35extern ANN void vector_clear(const Vector);
36extern ANN void free_vector(MemPool p, const Vector);
37extern ANN void vector_release(const Vector);
38
39ANN static inline void vector_realloc(const Vector v) {
40 if ((OFFSET + (VLEN(v) << 1) + 1) > VCAP(v))
41 v->ptr = (m_uint *)xrealloc(v->ptr, (VCAP(v) <<= 1) * SZ_INT);
42}
43#endif
#define OFFSET
Definition container.h:9
#define VLEN(v)
Definition container.h:10
uintptr_t vtype
Definition container.h:14
#define VCAP(v)
Definition container.h:11
#define VPTR(v, i)
Definition container.h:12
#define ANN
Definition defs.h:19
#define ANEW
Definition defs.h:22
uintptr_t m_uint
Definition gwcommon.h:11
#define SZ_INT
Definition gwcommon.h:18
intptr_t m_int
Definition gwcommon.h:10
vtype * ptr
Definition vector.h:9
void void * arg
Definition threadpool.h:27
ANN void vector_init(const Vector)
Definition vector.c:3
static ANN vtype vector_size(Vector const v)
Definition vector.h:29
ANN Vector vector_copy(MemPool p, const Vector)
Definition vector.c:32
static ANN void vector_set(const Vector v, const vtype i, const vtype arg)
Definition vector.h:18
ANN void vector_clear(const Vector)
Definition vector.c:67
ANN void free_vector(MemPool p, const Vector)
Definition vector.c:16
static ANN vtype vector_back(const Vector v)
Definition vector.h:26
ANN void vector_copy2(const __restrict__ Vector, __restrict__ Vector)
ANN bool vector_rem2(const Vector, const vtype)
Definition vector.c:53
static ANN void vector_realloc(const Vector v)
Definition vector.h:39
ANEW ANN Vector new_vector(MemPool p)
Definition vector.c:8
static ANN vtype vector_at(const Vector v, const vtype i)
Definition vector.h:23
ANN void vector_release(const Vector)
Definition vector.c:14
ANN void vector_rem(const Vector, const vtype)
Definition vector.c:44
ANN vtype vector_pop(const Vector)
Definition vector.c:61
static ANN vtype vector_front(const Vector v)
Definition vector.h:22
ANN m_int vector_find(const Vector, const vtype)
Definition vector.c:38
ANN void vector_add(const Vector, const vtype)
Definition vector.c:21
struct Vector_ * Vector
static ANEW void * xrealloc(void *p, const m_uint sz)
Definition xalloc.h:23