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

Map functions. More...

Go to the source code of this file.

Data Structures

struct  Map_
 

Macros

#define VKEY(v, i)   (v)->ptr[OFFSET + (i)*2]
 
#define VVAL(v, i)   (v)->ptr[OFFSET + (i)*2 + 1]
 

Typedefs

typedef struct Map_Map
 

Functions

ANEW Map new_map (MemPool)
 
void map_init (const Map)
 
ANN vtype map_get (const Map, const vtype)
 
ANN m_int map_index (const Map, const vtype)
 
static ANN vtype map_at (const Map map, const vtype index)
 
ANN void map_set (const Map, const vtype, const vtype)
 
ANN void map_remove (const Map, const vtype)
 
ANN void map_commit (const __restrict__ Map, __restrict__ const Map)
 
ANN void map_clear (const Map)
 
ANN void free_map (MemPool p, const Map)
 
ANN void map_release (const Map)
 
static ANN vtype map_size (const Map map)
 

Detailed Description

Map functions.

Definition in file map.h.

Macro Definition Documentation

◆ VKEY

#define VKEY ( v,
i )   (v)->ptr[OFFSET + (i)*2]

Definition at line 11 of file map.h.

◆ VVAL

#define VVAL ( v,
i )   (v)->ptr[OFFSET + (i)*2 + 1]

Definition at line 12 of file map.h.

Typedef Documentation

◆ Map

typedef struct Map_ * Map

Function Documentation

◆ free_map()

ANN void free_map ( MemPool p,
const Map map )
extern

Definition at line 63 of file map.c.

63 {
64 map_release(map);
65 mp_free(p, Map, map);
66}
ANN void map_release(const Map map)
Definition map.c:61
#define mp_free(p, name, a)
Definition mpool.h:27
Definition map.h:7

◆ map_at()

static ANN vtype map_at ( const Map map,
const vtype index )
inlinestatic

Definition at line 19 of file map.h.

19 {
20 return VVAL(map, index);
21}
#define VVAL(v, i)
Definition map.h:12

◆ map_clear()

ANN void map_clear ( const Map v)
extern

Definition at line 3 of file map.c.

3 {
4 if (VCAP(v) != MAP_CAP)
5 v->ptr = (m_uint *)xrealloc(v->ptr, (VCAP(v) = MAP_CAP) * SZ_INT);
6 VLEN(v) = 0;
7}
#define VLEN(v)
Definition container.h:10
#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 map.h:8
static ANEW void * xrealloc(void *p, const m_uint sz)
Definition xalloc.h:23

◆ map_commit()

ANN void map_commit ( const __restrict__ Map,
__restrict__ const Map )
extern

◆ map_get()

ANN vtype map_get ( const Map map,
const vtype key )
extern

Definition at line 20 of file map.c.

20 {
21 for (vtype i = VLEN(map) + 1; --i;)
22 if (VKEY(map, i - 1) == key) return VVAL(map, i - 1);
23 return 0;
24}
uintptr_t vtype
Definition container.h:14
#define VKEY(v, i)
Definition map.h:11

◆ map_index()

ANN m_int map_index ( const Map map,
const vtype key )
extern

Definition at line 26 of file map.c.

26 {
27 for (vtype i = VLEN(map) + 1; --i;)
28 if (VKEY(map, i - 1) == key) return i - 1;
29 return -1;
30}

◆ map_init()

void map_init ( const Map a)
externinline

Definition at line 9 of file map.c.

9 {
11 VCAP(a) = MAP_CAP;
12}
static ANEW void * xcalloc(const m_uint n, const m_uint sz)
Definition xalloc.h:18

◆ map_release()

ANN void map_release ( const Map map)
extern

Definition at line 61 of file map.c.

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

◆ map_remove()

ANN void map_remove ( const Map map,
const vtype key )
extern

Definition at line 44 of file map.c.

44 {
45 const vtype len = VLEN(map);
46 for (vtype i = 0, j = 0; i < len; ++i) {
47 if (VKEY(map, i) != key) {
48 VKEY(map, j) = VKEY(map, i);
49 VVAL(map, j) = VVAL(map, i);
50 ++j;
51 } else
52 --VLEN(map);
53 }
54}

◆ map_set()

ANN void map_set ( const Map map,
const vtype key,
const vtype ptr )
extern

Definition at line 32 of file map.c.

32 {
33 for (vtype i = VLEN(map) + 1; --i;) {
34 if (VKEY(map, i - 1) == key) {
35 VVAL(map, i - 1) = ptr;
36 return;
37 }
38 }
40 VKEY(map, VLEN(map)) = key;
41 VVAL(map, VLEN(map)++) = ptr;
42}
static ANN void vector_realloc(const Vector v)
Definition vector.h:39

◆ map_size()

static ANN vtype map_size ( const Map map)
inlinestatic

Definition at line 28 of file map.h.

28{ return VLEN(map); }

◆ new_map()

ANEW Map new_map ( MemPool p)
extern

Definition at line 14 of file map.c.

14 {
15 const Map map = mp_calloc(p, Map);
16 map_init(map);
17 return map;
18}
ANN void map_init(const Map a)
Definition map.c:9
#define mp_calloc(p, name)
Definition mpool.h:26