gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
vector.h File Reference

vector functions More...

Go to the source code of this file.

Data Structures

struct  Vector_
 

Typedefs

typedef struct Vector_Vector
 

Functions

ANEW ANN Vector new_vector (MemPool p)
 
ANN void vector_init (const Vector)
 
ANN Vector vector_copy (MemPool p, const Vector)
 
ANN void vector_copy2 (const __restrict__ Vector, __restrict__ Vector)
 
ANN m_int vector_find (const Vector, const vtype)
 
static ANN void vector_set (const Vector v, const vtype i, const vtype arg)
 
static ANN vtype vector_front (const Vector v)
 
static ANN vtype vector_at (const Vector v, const vtype i)
 
static ANN vtype vector_back (const Vector v)
 
static ANN vtype vector_size (Vector const v)
 
ANN void vector_add (const Vector, const vtype)
 
ANN void vector_rem (const Vector, const vtype)
 
ANN bool vector_rem2 (const Vector, const vtype)
 
ANN vtype vector_pop (const Vector)
 
ANN void vector_clear (const Vector)
 
ANN void free_vector (MemPool p, const Vector)
 
ANN void vector_release (const Vector)
 
static ANN void vector_realloc (const Vector v)
 

Detailed Description

vector functions

Definition in file vector.h.

Typedef Documentation

◆ Vector

typedef struct Vector_ * Vector

Function Documentation

◆ free_vector()

ANN void free_vector ( MemPool p,
const Vector v )
extern

Definition at line 16 of file vector.c.

16 {
18 mp_free(p, Vector, v);
19}
#define mp_free(p, name, a)
Definition mpool.h:27
ANN void vector_release(const Vector v)
Definition vector.c:14

◆ new_vector()

ANEW ANN Vector new_vector ( MemPool p)
extern

Definition at line 8 of file vector.c.

8 {
9 const Vector v = mp_calloc(p, Vector);
10 vector_init(v);
11 return v;
12}
#define mp_calloc(p, name)
Definition mpool.h:26
ANN void vector_init(const Vector v)
Definition vector.c:3

◆ vector_add()

ANN void vector_add ( const Vector v,
const vtype data )
extern

Definition at line 21 of file vector.c.

21 {
23 VPTR(v, VLEN(v)++) = (vtype)data;
24}
#define VLEN(v)
Definition container.h:10
uintptr_t vtype
Definition container.h:14
#define VPTR(v, i)
Definition container.h:12
static ANN void vector_realloc(const Vector v)
Definition vector.h:39

◆ vector_at()

static ANN vtype vector_at ( const Vector v,
const vtype i )
inlinestatic

Definition at line 23 of file vector.h.

23 {
24 return VPTR(v, i);
25}

◆ vector_back()

static ANN vtype vector_back ( const Vector v)
inlinestatic

Definition at line 26 of file vector.h.

26 {
27 return VPTR(v, VLEN(v) - 1);
28}

◆ vector_clear()

ANN void vector_clear ( const Vector v)
extern

Definition at line 67 of file vector.c.

67 {
68 v->ptr = (m_uint *)xrealloc(v->ptr, (VCAP(v) = MAP_CAP) * SZ_INT);
69 VLEN(v) = 0;
70}
#define MAP_CAP
Definition container.h:8
#define VCAP(v)
Definition container.h:11
uintptr_t m_uint
Definition gwcommon.h:11
#define SZ_INT
Definition gwcommon.h:18
vtype * ptr
Definition vector.h:9
static ANEW void * xrealloc(void *p, const m_uint sz)
Definition xalloc.h:23

◆ vector_copy()

ANN Vector vector_copy ( MemPool p,
const Vector v )
extern

Definition at line 32 of file vector.c.

32 {
33 const Vector ret = mp_calloc(p, Vector);
34 vector_copy2(v, ret);
35 return ret;
36}
ANN void vector_copy2(const restrict Vector v, const restrict Vector ret)
Definition vector.c:26

◆ vector_copy2()

ANN void vector_copy2 ( const __restrict__ Vector,
__restrict__ Vector )
extern

◆ vector_find()

ANN m_int vector_find ( const Vector v,
const vtype data )
extern

Definition at line 38 of file vector.c.

38 {
39 for (vtype i = VLEN(v) + 1; --i;)
40 if (VPTR(v, i - 1) == (vtype)data) return (m_int)(i - 1);
41 return -1;
42}
intptr_t m_int
Definition gwcommon.h:10

◆ vector_front()

static ANN vtype vector_front ( const Vector v)
inlinestatic

Definition at line 22 of file vector.h.

22{ return VPTR(v, 0); }

◆ vector_init()

ANN void vector_init ( const Vector v)
externinline

Definition at line 3 of file vector.c.

3 {
5 VCAP(v) = MAP_CAP;
6}
static ANEW void * xcalloc(const m_uint n, const m_uint sz)
Definition xalloc.h:18

◆ vector_pop()

ANN vtype vector_pop ( const Vector v)
extern

Definition at line 61 of file vector.c.

61 {
62 const vtype ret = VPTR(v, VLEN(v) - 1);
63 vector_rem(v, VLEN(v) - 1);
64 return ret;
65}
ANN void vector_rem(const Vector v, const vtype index)
Definition vector.c:44

◆ vector_realloc()

static ANN void vector_realloc ( const Vector v)
inlinestatic

Definition at line 39 of file vector.h.

39 {
40 if ((OFFSET + (VLEN(v) << 1) + 1) > VCAP(v))
41 v->ptr = (m_uint *)xrealloc(v->ptr, (VCAP(v) <<= 1) * SZ_INT);
42}
#define OFFSET
Definition container.h:9

◆ vector_release()

ANN void vector_release ( const Vector v)
externinline

Definition at line 14 of file vector.c.

14{ xfree(v->ptr); }
#define xfree(a)
Definition xalloc.h:28

◆ vector_rem()

ANN void vector_rem ( const Vector v,
const vtype index )
extern

Definition at line 44 of file vector.c.

44 {
45 if (index >= VLEN(v)) return;
46 if (index < VLEN(v) - 1)
47 memmove(v->ptr + index + OFFSET, v->ptr + index + OFFSET + 1,
48 (VLEN(v) - index - 1) * SZ_INT);
49 if (--VLEN(v) + OFFSET < VCAP(v) / 2)
50 v->ptr = (m_uint *)xrealloc(v->ptr, (VCAP(v) /= 2) * SZ_INT);
51}

◆ vector_rem2()

ANN bool vector_rem2 ( const Vector v,
const vtype data )
extern

Definition at line 53 of file vector.c.

53 {
54 const m_int index = vector_find(v, data);
55 if (index > -1) {
56 vector_rem(v, (vtype)index);
57 return true;
58 } else return false;
59}
ANN m_int vector_find(const Vector v, const vtype data)
Definition vector.c:38

◆ vector_set()

static ANN void vector_set ( const Vector v,
const vtype i,
const vtype arg )
inlinestatic

Definition at line 18 of file vector.h.

19 {
20 VPTR(v, i) = arg;
21}
void void * arg
Definition threadpool.h:27

◆ vector_size()

static ANN vtype vector_size ( Vector const v)
inlinestatic

Definition at line 29 of file vector.h.

29{ return VLEN(v); }