1 #ifndef _MAP_H_ 2 #define _MAP_H_ 3 4 struct map_item { 5 unsigned int key; 6 }; 7 8 struct map_entry; 9 10 struct map { 11 unsigned int size; 12 unsigned int count; 13 struct map_entry *data; 14 }; 15 16 int map_create(struct map *map); 17 void map_destroy(struct map *map); 18 void map_clear(struct map *map, void (*release)(struct map_item *)); 19 20 int map_put(struct map *map, unsigned int key, struct map_item *v); 21 int map_reput(struct map *map, unsigned int key, struct map_item *v, 22 struct map_item **old); 23 int map_contains(const struct map *map, unsigned int key); 24 struct map_item *map_get(const struct map *map, unsigned int key); 25 int map_remove(struct map *map, unsigned int key); 26 unsigned int map_length(struct map *map); 27 28 struct map_entry *map_iter_first(const struct map *map); 29 struct map_entry *map_iter_next(const struct map *map, struct map_entry *iter); 30 struct 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 39