Statistics
| Branch: | Revision:

iof-bird / bird-2.0.1 / proto / bgp / map.h @ 6b3f1a54

History | View | Annotate | Download (1.45 KB)

1
/** 
2
 * Copyright (c) 2014 rxi
3
 *
4
 * This library is free software; you can redistribute it and/or modify it
5
 * under the terms of the MIT license. See LICENSE for details.
6
 */
7

    
8
#ifndef MAP_H
9
#define MAP_H
10

    
11
#include <string.h>
12

    
13
#define MAP_VERSION "0.1.0"
14

    
15
struct map_node_t;
16
typedef struct map_node_t map_node_t;
17

    
18
typedef struct {
19
  map_node_t **buckets;
20
  unsigned nbuckets, nnodes;
21
} map_base_t;
22

    
23
typedef struct {
24
  unsigned bucketidx;
25
  map_node_t *node;
26
} map_iter_t;
27

    
28

    
29
#define map_t(T)\
30
  struct { map_base_t base; T *ref; T tmp; }
31

    
32

    
33
#define map_init(m)\
34
  memset(m, 0, sizeof(*(m)))
35

    
36

    
37
#define map_deinit(m)\
38
  map_deinit_(&(m)->base)
39

    
40

    
41
#define map_get(m, key)\
42
  ( (m)->ref = map_get_(&(m)->base, key) )
43

    
44

    
45
#define map_set(m, key, value)\
46
  ( (m)->tmp = (value),\
47
    map_set_(&(m)->base, key, &(m)->tmp, sizeof((m)->tmp)) )
48

    
49

    
50
#define map_remove(m, key)\
51
  map_remove_(&(m)->base, key)
52

    
53

    
54
#define map_iter(m)\
55
  map_iter_()
56

    
57

    
58
#define map_next(m, iter)\
59
  map_next_(&(m)->base, iter)
60

    
61

    
62
void map_deinit_(map_base_t *m);
63
void *map_get_(map_base_t *m, const char *key);
64
int map_set_(map_base_t *m, const char *key, void *value, int vsize);
65
void map_remove_(map_base_t *m, const char *key);
66
map_iter_t map_iter_(void);
67
const char *map_next_(map_base_t *m, map_iter_t *iter);
68

    
69

    
70
typedef map_t(void*) map_void_t;
71
typedef map_t(char*) map_str_t;
72
typedef map_t(int) map_int_t;
73
typedef map_t(char) map_char_t;
74
typedef map_t(float) map_float_t;
75
typedef map_t(double) map_double_t;
76

    
77
#endif