map.h
Go to the documentation of this file.
1 #ifndef NVIM_MAP_H
2 #define NVIM_MAP_H
3 
4 #include <stdbool.h>
5 
6 #include "nvim/map_defs.h"
7 #include "nvim/extmark_defs.h"
10 #include "nvim/highlight_defs.h"
11 
12 #if defined(__NetBSD__)
13 # undef uint64_t
14 # define uint64_t uint64_t
15 #endif
16 
17 #define MAP_DECLS(T, U) \
18  KHASH_DECLARE(T##_##U##_map, T, U) \
19  \
20  typedef struct { \
21  khash_t(T##_##U##_map) table; \
22  } Map(T, U); \
23  \
24  Map(T, U) *map_##T##_##U##_new(void); \
25  void map_##T##_##U##_free(Map(T, U) *map); \
26  void map_##T##_##U##_destroy(Map(T, U) *map); \
27  U map_##T##_##U##_get(Map(T, U) *map, T key); \
28  bool map_##T##_##U##_has(Map(T, U) *map, T key); \
29  T map_##T##_##U##_key(Map(T, U) *map, T key); \
30  U map_##T##_##U##_put(Map(T, U) *map, T key, U value); \
31  U *map_##T##_##U##_ref(Map(T, U) *map, T key, bool put); \
32  U map_##T##_##U##_del(Map(T, U) *map, T key); \
33  void map_##T##_##U##_clear(Map(T, U) *map);
34 
35 //
36 // NOTE: Keys AND values must be allocated! khash.h does not make a copy.
37 //
38 MAP_DECLS(int, int)
40 MAP_DECLS(cstr_t, int)
42 MAP_DECLS(uint64_t, ptr_t)
43 MAP_DECLS(uint64_t, ssize_t)
44 MAP_DECLS(uint64_t, uint64_t)
45 
46 // NB: this is the only way to define a struct both containing and contained
47 // in a map...
48 typedef struct ExtmarkNs { // For namespacing extmarks
49  Map(uint64_t, uint64_t) map[1]; // For fast lookup
50  uint64_t free_id; // For automatically assigning id's
51 } ExtmarkNs;
52 
53 MAP_DECLS(uint64_t, ExtmarkNs)
54 MAP_DECLS(uint64_t, ExtmarkItem)
57 MAP_DECLS(HlEntry, int)
59 
61 
62 #define MAP_INIT { { 0, 0, 0, 0, NULL, NULL, NULL } }
63 #define map_init(k, v, map) do { *(map) = (Map(k, v))MAP_INIT; } while (false)
64 
65 #define map_destroy(T, U) map_##T##_##U##_destroy
66 #define map_get(T, U) map_##T##_##U##_get
67 #define map_has(T, U) map_##T##_##U##_has
68 #define map_key(T, U) map_##T##_##U##_key
69 #define map_put(T, U) map_##T##_##U##_put
70 #define map_ref(T, U) map_##T##_##U##_ref
71 #define map_del(T, U) map_##T##_##U##_del
72 #define map_clear(T, U) map_##T##_##U##_clear
73 
74 #define map_size(map) ((map)->table.size)
75 
76 #define pmap_destroy(T) map_destroy(T, ptr_t)
77 #define pmap_get(T) map_get(T, ptr_t)
78 #define pmap_has(T) map_has(T, ptr_t)
79 #define pmap_key(T) map_key(T, ptr_t)
80 #define pmap_put(T) map_put(T, ptr_t)
81 #define pmap_ref(T) map_ref(T, ptr_t)
82 #define pmap_del(T) map_del(T, ptr_t)
84 #define pmap_clear(T) map_clear(T, ptr_t)
85 #define pmap_init(k, map) map_init(k, ptr_t, map)
86 
87 #define map_foreach(map, key, value, block) \
88  kh_foreach(&(map)->table, key, value, block)
89 
90 #define map_foreach_value(map, value, block) \
91  kh_foreach_value(&(map)->table, value, block)
92 
93 void pmap_del2(PMap(cstr_t) *map, const char *key);
94 
95 #endif // NVIM_MAP_H
map_defs.h
HlEntry
Definition: highlight_defs.h:187
highlight_defs.h
ExtmarkNs::free_id
uint64_t free_id
Definition: map.h:50
ExtmarkItem
Definition: extmark_defs.h:9
defs.h
dispatch.h
pmap_del2
void pmap_del2(PMap(cstr_t) *map, const char *key)
Definition: map.c:207
ExtmarkNs
Definition: map.h:48
MsgpackRpcRequestHandler
Definition: dispatch.h:12
MAP_DECLS
#define MAP_DECLS(T, U)
Definition: map.h:17
String
Definition: defs.h:76
extmark_defs.h
Map
#define Map(T, U)
Definition: map_defs.h:9
ColorKey
Definition: highlight_defs.h:195
cstr_t
const typedef char * cstr_t
Definition: map_defs.h:6
ptr_t
void * ptr_t
Definition: map_defs.h:7
handle_T
int handle_T
Definition: types.h:18
ColorItem
Definition: highlight_defs.h:201
PMap
#define PMap(T)
Definition: map_defs.h:10
ExtmarkNs
struct ExtmarkNs ExtmarkNs