aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/map.h
blob: 9e61b903d560b0ef187f5ac5d30b5b52900f00f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// General-purpose string->pointer associative array with a simple API
#ifndef NEOVIM_MAP_H
#define NEOVIM_MAP_H

#include <stdbool.h>

#include "map_defs.h"

/// Creates a new `Map` instance
///
/// @return a pointer to the new instance
Map *map_new(void);

/// Frees memory for a `Map` instance
///
/// @param map The `Map` instance
void map_free(Map *map);

/// Gets the value corresponding to a key in a `Map` instance
///
/// @param map The `Map` instance
/// @param key A key string
/// @return The value if the key exists in the map, or NULL if it doesn't
void *map_get(Map *map, const char *key);

/// Checks if a key exists in the map
///
/// @param map The `Map` instance
/// @param key A key string
/// @return true if the key exists, false otherwise
bool map_has(Map *map, const char *key);

/// Set the value corresponding to a key in a `Map` instance and returns
/// the old value.
///
/// @param map The `Map` instance
/// @param key A key string
/// @param value A value
/// @return The current value if exists or NULL otherwise
void *map_put(Map *map, const char *key, void *value);

/// Deletes the value corresponding to a key in a `Map` instance and returns
/// the old value.
///
/// @param map The `Map` instance
/// @param key A key string
/// @return The current value if exists or NULL otherwise
void *map_del(Map *map, const char *key);

/// Iterates through each key/value pair in the map
///
/// @param map The `Map` instance
/// @param cb A function that will be called for each key/value
void map_foreach(Map *map, key_value_cb cb);

#endif /* NEOVIM_MAP_H */