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

Go to the source code of this file.

Data Structures

struct  M_Vector_
 

Macros

#define ARRAY_OFFSET   SZ_INT * 3
 
#define ARRAY_PTR(array)   (array->ptr + ARRAY_OFFSET)
 
#define ARRAY_LEN(array)   *(m_uint *)(array->ptr)
 
#define ARRAY_SIZE(array)   *(m_uint *)(array->ptr + SZ_INT)
 
#define ARRAY_CAP(array)   *(m_uint *)(array->ptr + SZ_INT * 2)
 

Typedefs

typedef struct M_Vector_M_Vector
 

Functions

static ANN m_uint m_vector_size (const M_Vector v)
 
static ANN void m_vector_get (const M_Vector v, const m_uint i, void *c)
 
static ANN m_bitm_vector_addr (const M_Vector v, const m_uint i)
 
void m_vector_init (const M_Vector array, const m_uint size, const m_uint len)
 
static ANN M_Vector new_m_vector (MemPool p, const m_uint size, const m_uint len)
 
static ANN void m_vector_release (M_Vector a)
 
static ANN void free_m_vector (MemPool p, M_Vector a)
 
ANN void m_vector_set (const M_Vector, const m_uint, const void *)
 
ANN void m_vector_add (const M_Vector, const void *)
 
ANN void m_vector_rem (const M_Vector, const m_uint)
 
ANN void m_vector_insert (const M_Vector v, m_uint index, const void *data)
 
ANN void m_vector_add_front (const M_Vector v, const void *data)
 

Macro Definition Documentation

◆ ARRAY_CAP

#define ARRAY_CAP ( array)    *(m_uint *)(array->ptr + SZ_INT * 2)

Definition at line 11 of file m_vector.h.

◆ ARRAY_LEN

#define ARRAY_LEN ( array)    *(m_uint *)(array->ptr)

Definition at line 9 of file m_vector.h.

◆ ARRAY_OFFSET

#define ARRAY_OFFSET   SZ_INT * 3

Definition at line 7 of file m_vector.h.

◆ ARRAY_PTR

#define ARRAY_PTR ( array)    (array->ptr + ARRAY_OFFSET)

Definition at line 8 of file m_vector.h.

◆ ARRAY_SIZE

#define ARRAY_SIZE ( array)    *(m_uint *)(array->ptr + SZ_INT)

Definition at line 10 of file m_vector.h.

Typedef Documentation

◆ M_Vector

typedef struct M_Vector_ * M_Vector

Function Documentation

◆ free_m_vector()

static ANN void free_m_vector ( MemPool p,
M_Vector a )
inlinestatic

Definition at line 37 of file m_vector.h.

37 {
39 mp_free(p, M_Vector, a);
40}
static ANN void m_vector_release(M_Vector a)
Definition m_vector.h:35
#define mp_free(p, name, a)
Definition mpool.h:27

◆ m_vector_add()

ANN void m_vector_add ( const M_Vector v,
const void * data )

Definition at line 18 of file m_vector.c.

18 {
19 const m_uint size = ARRAY_SIZE(v);
20 if (++ARRAY_LEN(v) >= ARRAY_CAP(v)) resize(v, ARRAY_CAP(v) *= 2);
21 memcpy(ARRAY_PTR(v) + (ARRAY_LEN(v) - 1) * size, data, size);
22}
uintptr_t m_uint
Definition gwcommon.h:11
static ANN void resize(const M_Vector v, const m_uint cap)
Definition m_vector.c:3
#define ARRAY_CAP(array)
Definition m_vector.h:11
#define ARRAY_LEN(array)
Definition m_vector.h:9
#define ARRAY_SIZE(array)
Definition m_vector.h:10
#define ARRAY_PTR(array)
Definition m_vector.h:8

◆ m_vector_add_front()

ANN void m_vector_add_front ( const M_Vector v,
const void * data )

Definition at line 24 of file m_vector.c.

24 {
25 const m_uint size = ARRAY_SIZE(v);
26 if (++ARRAY_LEN(v) >= ARRAY_CAP(v)) resize(v, ARRAY_CAP(v) *= 2);
27 memmove(ARRAY_PTR(v) + size, ARRAY_PTR(v), ARRAY_LEN(v) * size);
28 memmove(ARRAY_PTR(v), data, size);
29}

◆ m_vector_addr()

static ANN m_bit * m_vector_addr ( const M_Vector v,
const m_uint i )
inlinestatic

Definition at line 22 of file m_vector.h.

22 {
23 return &*(m_bit *)(ARRAY_PTR(v) + i * ARRAY_SIZE(v));
24}
unsigned char m_bit
Definition gwcommon.h:12

◆ m_vector_get()

static ANN void m_vector_get ( const M_Vector v,
const m_uint i,
void * c )
inlinestatic

Definition at line 17 of file m_vector.h.

17 {
18 const m_uint size = ARRAY_SIZE(v);
19 memcpy(c, ARRAY_PTR(v) + i * size, size);
20}

◆ m_vector_init()

void m_vector_init ( const M_Vector array,
const m_uint size,
const m_uint len )

Definition at line 8 of file m_vector.c.

8 {
9 m_uint cap = 2;
10 while (cap < len) cap *= 2;
11 const size_t sz = ARRAY_OFFSET + cap * size;
12 array->ptr = (m_bit *)xcalloc(1, sz);
13 ARRAY_CAP(array) = cap;
14 ARRAY_SIZE(array) = size;
15 ARRAY_LEN(array) = len;
16}
#define ARRAY_OFFSET
Definition m_vector.h:7
m_bit * ptr
Definition m_vector.h:5
static ANEW void * xcalloc(const m_uint n, const m_uint sz)
Definition xalloc.h:18

◆ m_vector_insert()

ANN void m_vector_insert ( const M_Vector v,
m_uint index,
const void * data )

Definition at line 45 of file m_vector.c.

45 {
46 const size_t size = ARRAY_SIZE(v);
47 if (++ARRAY_LEN(v) >= ARRAY_CAP(v)) resize(v, ARRAY_CAP(v) *= 2);
48 memmove(ARRAY_PTR(v) + (index + 1) * size, ARRAY_PTR(v) + index * size,
49 (ARRAY_LEN(v) - index + 1) * size);
50 memcpy(ARRAY_PTR(v) + index * size, data, size);
51}

◆ m_vector_release()

static ANN void m_vector_release ( M_Vector a)
inlinestatic

Definition at line 35 of file m_vector.h.

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

◆ m_vector_rem()

ANN void m_vector_rem ( const M_Vector v,
const m_uint index )

Definition at line 36 of file m_vector.c.

36 {
37 const m_uint size = ARRAY_SIZE(v);
38 if (index < ARRAY_LEN(v) - 1)
39 memmove(ARRAY_PTR(v) + index * size, ARRAY_PTR(v) + (index + 1) * size,
40 (ARRAY_LEN(v) - index - 1) * size);
41 --ARRAY_LEN(v);
42 if (ARRAY_LEN(v) < ARRAY_CAP(v) / 2) resize(v, ARRAY_CAP(v) / 2);
43}

◆ m_vector_set()

ANN void m_vector_set ( const M_Vector v,
const m_uint i,
const void * data )

Definition at line 31 of file m_vector.c.

31 {
32 const m_uint size = ARRAY_SIZE(v);
33 memcpy(ARRAY_PTR(v) + i * size, data, size);
34}

◆ m_vector_size()

static ANN m_uint m_vector_size ( const M_Vector v)
inlinestatic

Definition at line 13 of file m_vector.h.

13 {
14 return ARRAY_LEN(v);
15}

◆ new_m_vector()

static ANN M_Vector new_m_vector ( MemPool p,
const m_uint size,
const m_uint len )
inlinestatic

Definition at line 28 of file m_vector.h.

29 {
30 const M_Vector array = (M_Vector)mp_calloc(p, M_Vector);
31 m_vector_init(array, size, len);
32 return array;
33}
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
#define mp_calloc(p, name)
Definition mpool.h:26