/* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ #include "bits/__generics.h" #include "bits/__rbtree.h" #include "vtype.h" #ifndef LIBCDSB_MAP_H #define LIBCDSB_MAP_H typedef int (*map_access_callback)(const void* key, vtype key_type, void* value, vtype value_type, void* data); /*#####################################################################################################################*/ extern void map_init(vtype_map* x, vtype key_type) Nonnull__(1); /*#####################################################################################################################*/ #define map_pop(x, key, data, callback) libcdsb_map_find (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), data, callback, 1) #define map_get(x, key, data, callback) libcdsb_map_find (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), data, callback, 0) #define map_update(x, key, value) libcdsb_map_update (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) #define map_inject(x, key, value) libcdsb_map_inject (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) #define map_foreach(x, data, callback) libcdsb_map_foreach (x, data, callback, RBFOREACH_UNSPECIFIED, 0) #define map_remove(x, key) map_pop (x, key, 0, 0) #define in_map(x, key) (map_get(x, key, 0, 0) == 0) /*#####################################################################################################################*/ extern bool libcdsb_map_update (vtype_map* x, const void* key, vtype key_type, const void* value, vtype value_type) Nonnull__(1); extern bool libcdsb_map_inject (vtype_map* x, const void* key, vtype key_type, const void* value, vtype value_type) Nonnull__(1); extern int libcdsb_map_find (vtype_map* x, const void* key, vtype key_type, void* data, map_access_callback, bool cut) Nonnull__(1); extern int libcdsb_map_foreach(vtype_map* x, void* data, map_access_callback, rbforeach_t, bool flush) Nonnull__(1,3); #endif /* LIBCDSB_MAP_H */