coll 0.1.0-alpha.1
A collections library
Loading...
Searching...
No Matches
coll_arraylist_map.h
Go to the documentation of this file.
1#ifndef ___COLL_AL_MAP_H___
2#define ___COLL_AL_MAP_H___
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
18#include "coll_arraylist.h"
19#include <stdbool.h>
20
21#define COLL_AL_MAP_DEFAULT_CAPACITY 25
22#define E_COLL_AL_MAP_ALLOC_FAILED 10
23#define E_COLL_AL_MAP_NULL 11
24#define E_COLL_AL_MAP_ALREADY_EXISTS 12
25#define E_COLL_AL_MAP_KEY_NULL 13
26#define E_COLL_AL_MAP_COMPARE_FN_NULL 15
27#define E_COLL_AL_MAP_SUCCESS 0
28
29typedef int (coll_al_map_compare_fn) (void* first, void* second);
30
31typedef void (coll_al_map_iter_fn)(size_t index, void* key, void* value);
32
33typedef struct coll_al_map_t {
34 coll_al_map_compare_fn* compare;
35 size_t size;
36 arraylist* keys;
37 arraylist* values;
39
40#define coll_al_map_keys(map) map->keys
41#define coll_al_map_keys_length(map) arraylist_length(coll_al_map_keys(map))
42#define coll_al_map_keys_get_idx(map, i) arraylist_get(coll_al_map_keys(map), i)
43#define coll_al_map_values(map) map->values
44#define coll_al_map_values_length(map) arraylist_length(coll_al_map_values(map))
45#define coll_al_map_values_get_idx(map, i) arraylist_get(coll_al_map_values(map), i)
46
56coll_al_map* make_coll_al_map(coll_al_map_compare_fn* compare);
57
68coll_al_map* make_coll_al_map_w_capacity(coll_al_map_compare_fn* compare, size_t initial_capacity);
69
82int coll_al_map_put(coll_al_map* map, void* key, void* val);
83
92void* coll_al_map_get(coll_al_map* map, void* key);
93
106bool coll_al_map_remove(coll_al_map* map, void* key, coll_al_map_iter_fn* iter_fn);
107
115bool coll_al_map_has(coll_al_map* map, void* key);
116
124
131void coll_al_map_foreach_fn(coll_al_map* map, coll_al_map_iter_fn* iter_fn);
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif /* ___COLL_AL_MAP_H___ */
void free_coll_al_map(coll_al_map *map)
Definition coll_arraylist_map.c:110
bool coll_al_map_has(coll_al_map *map, void *key)
Definition coll_arraylist_map.c:100
coll_al_map * make_coll_al_map_w_capacity(coll_al_map_compare_fn *compare, size_t initial_capacity)
Definition coll_arraylist_map.c:8
void * coll_al_map_get(coll_al_map *map, void *key)
Definition coll_arraylist_map.c:56
void coll_al_map_foreach_fn(coll_al_map *map, coll_al_map_iter_fn *iter_fn)
Definition coll_arraylist_map.c:118
bool coll_al_map_remove(coll_al_map *map, void *key, coll_al_map_iter_fn *iter_fn)
Definition coll_arraylist_map.c:79
coll_al_map * make_coll_al_map(coll_al_map_compare_fn *compare)
Definition coll_arraylist_map.c:4
int coll_al_map_put(coll_al_map *map, void *key, void *val)
Definition coll_arraylist_map.c:33
Definition coll_arraylist.h:80
Definition coll_arraylist_map.h:33