gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
Functions
map.c File Reference
#include "gwion_util.h"

Go to the source code of this file.

Functions

ANN void map_clear (const Map v)
 
ANN void map_init (const Map a)
 
ANEW Map new_map (MemPool p)
 
ANN vtype map_get (const Map map, const vtype key)
 
ANN m_int map_index (const Map map, const vtype key)
 
ANN void map_set (const Map map, const vtype key, const vtype ptr)
 
ANN void map_remove (const Map map, const vtype key)
 
ANN void map_commit (const restrict Map map, const restrict Map commit)
 
ANN void map_release (const Map map)
 
ANN void free_map (MemPool p, const Map map)
 

Function Documentation

◆ free_map()

ANN void free_map ( MemPool p,
const Map map )

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_clear()

ANN void map_clear ( const Map v)

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 map,
const restrict Map commit )

Definition at line 56 of file map.c.

56 {
57 for (m_uint i = 0; i < map_size(commit); ++i)
58 map_set(map, VKEY(commit, i), VVAL(commit, i));
59}
ANN void map_set(const Map map, const vtype key, const vtype ptr)
Definition map.c:32
static ANN vtype map_size(const Map map)
Definition map.h:28
#define VVAL(v, i)
Definition map.h:12
#define VKEY(v, i)
Definition map.h:11

◆ map_get()

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

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

◆ map_index()

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

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()

ANN void map_init ( const Map a)
inline

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)

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 )

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 )

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

◆ new_map()

ANEW Map new_map ( MemPool p)

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