coll  0.1.0-alpha.1
A collections library
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
5 extern "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 
29 typedef int (coll_al_map_compare_fn) (void* first, void* second);
30 
31 typedef void (coll_al_map_iter_fn)(size_t index, void* key, void* value);
32 
33 typedef struct coll_al_map_t {
34  coll_al_map_compare_fn* compare;
35  size_t size;
36  arraylist* keys;
37  arraylist* values;
38 } coll_al_map;
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 
56 coll_al_map* make_coll_al_map(coll_al_map_compare_fn* compare);
57 
68 coll_al_map* make_coll_al_map_w_capacity(coll_al_map_compare_fn* compare, size_t initial_capacity);
69 
82 int coll_al_map_put(coll_al_map* map, void* key, void* val);
83 
92 void* coll_al_map_get(coll_al_map* map, void* key);
93 
106 bool coll_al_map_remove(coll_al_map* map, void* key, coll_al_map_iter_fn* iter_fn);
107 
115 bool coll_al_map_has(coll_al_map* map, void* key);
116 
123 void free_coll_al_map(coll_al_map* map);
124 
131 void 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
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
bool coll_al_map_has(coll_al_map *map, void *key)
Definition: coll_arraylist_map.c:100
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