blob: de68e19b5df272c7a658955118c92a3ea5981df2 [file] [log] [blame]
Amit Pundir33109f72020-02-07 22:26:08 +05301#ifndef _MAP_H_
2#define _MAP_H_
3
4struct map_item {
5 unsigned int key;
6};
7
8struct map_entry;
9
10struct map {
11 unsigned int size;
12 unsigned int count;
13 struct map_entry *data;
14};
15
16int map_create(struct map *map);
17void map_destroy(struct map *map);
18void map_clear(struct map *map, void (*release)(struct map_item *));
19
20int map_put(struct map *map, unsigned int key, struct map_item *v);
21int map_reput(struct map *map, unsigned int key, struct map_item *v,
22 struct map_item **old);
23int map_contains(const struct map *map, unsigned int key);
24struct map_item *map_get(const struct map *map, unsigned int key);
25int map_remove(struct map *map, unsigned int key);
26unsigned int map_length(struct map *map);
27
28struct map_entry *map_iter_first(const struct map *map);
29struct map_entry *map_iter_next(const struct map *map, struct map_entry *iter);
30struct map_item *map_iter_item(struct map_entry *iter);
31
32#define map_for_each(map, iter) \
33 for (iter = map_iter_first(map); iter; iter = map_iter_next(map, iter))
34
35#define map_iter_data(iter, type, member) \
36 container_of(map_iter_item(iter), type, member)
37
38#endif