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  U map_##T##_##U##_get(Map(T, U) *map, T key); \
27  bool map_##T##_##U##_has(Map(T, U) *map, T key); \
28  T map_##T##_##U##_key(Map(T, U) *map, T key); \
29  U map_##T##_##U##_put(Map(T, U) *map, T key, U value); \
30  U *map_##T##_##U##_ref(Map(T, U) *map, T key, bool put); \
31  U map_##T##_##U##_del(Map(T, U) *map, T key); \
32  void map_##T##_##U##_clear(Map(T, U) *map);
33 
34 //
35 // NOTE: Keys AND values must be allocated! khash.h does not make a copy.
36 //
37 MAP_DECLS(int, int)
39 MAP_DECLS(ptr_t, ptr_t)
40 MAP_DECLS(uint64_t, ptr_t)
41 MAP_DECLS(uint64_t, ssize_t)
42 MAP_DECLS(uint64_t, uint64_t)
43 
44 // NB: this is the only way to define a struct both containing and contained
45 // in a map...
46 typedef struct ExtmarkNs { // For namespacing extmarks
47  Map(uint64_t, uint64_t) *map; // For fast lookup
48  uint64_t free_id; // For automatically assigning id's
49 } ExtmarkNs;
50 
51 MAP_DECLS(uint64_t, ExtmarkNs)
52 MAP_DECLS(uint64_t, ExtmarkItem)
55 MAP_DECLS(HlEntry, int)
56 MAP_DECLS(String, handle_T)
57 
58 #define map_new(T, U) map_##T##_##U##_new
59 #define map_free(T, U) map_##T##_##U##_free
60 #define map_get(T, U) map_##T##_##U##_get
61 #define map_has(T, U) map_##T##_##U##_has
62 #define map_key(T, U) map_##T##_##U##_key
63 #define map_put(T, U) map_##T##_##U##_put
64 #define map_ref(T, U) map_##T##_##U##_ref
65 #define map_del(T, U) map_##T##_##U##_del
66 #define map_clear(T, U) map_##T##_##U##_clear
67 
68 #define map_size(map) ((map)->table->size)
69 
70 #define pmap_new(T) map_new(T, ptr_t)
71 #define pmap_free(T) map_free(T, ptr_t)
72 #define pmap_get(T) map_get(T, ptr_t)
73 #define pmap_has(T) map_has(T, ptr_t)
74 #define pmap_key(T) map_key(T, ptr_t)
75 #define pmap_put(T) map_put(T, ptr_t)
76 #define pmap_del(T) map_del(T, ptr_t)
78 #define pmap_clear(T) map_clear(T, ptr_t)
79 
80 #define map_foreach(map, key, value, block) \
81  kh_foreach(map->table, key, value, block)
82 
83 #define map_foreach_value(map, value, block) \
84  kh_foreach_value(map->table, value, block)
85 
86 void pmap_del2(PMap(cstr_t) *map, const char *key);
87 
88 #endif // NVIM_MAP_H
uint64_t free_id
Definition: map.h:48
struct ExtmarkNs ExtmarkNs
#define PMap(T)
Definition: map_defs.h:10
Definition: defs.h:76
const char * cstr_t
Definition: map_defs.h:6
Definition: highlight_defs.h:178
Definition: extmark_defs.h:15
Definition: map.h:46
void pmap_del2(PMap(cstr_t)*map, const char *key)
Definition: map.c:199
EXTERN Map(String, handle_T)*namespace_ids INIT(
int handle_T
Definition: types.h:17
#define MAP_DECLS(T, U)
Definition: map.h:17
void * ptr_t
Definition: map_defs.h:7
Definition: dispatch.h:12