libcdsb/include/map.h

36 lines
2.1 KiB
C
Raw Normal View History

2022-06-08 09:56:14 +03:00
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
2022-08-24 11:43:27 +03:00
#include "bits/__generics.h"
#include "bits/__rbtree.h"
2022-06-08 09:56:14 +03:00
#include "vtype.h"
#ifndef LIBCDSB_MAP_H
#define LIBCDSB_MAP_H
2023-03-23 16:15:28 +03:00
typedef int (*map_access_callback)(vtype_variable key, vtype_variable value, void* data);
2022-06-08 21:00:33 +03:00
2022-08-17 22:20:04 +03:00
/*#####################################################################################################################*/
2022-08-19 18:46:51 +03:00
extern void map_init(vtype_map* x, vtype key_type) Nonnull__(1);
2022-06-08 09:56:14 +03:00
2022-08-19 18:46:51 +03:00
/*#####################################################################################################################*/
2022-06-08 09:56:14 +03:00
2023-03-23 16:29:10 +03:00
#define map_pop(x, key, data, callback) libcdsb_map_find (x, _LIBCDSB_var(key), data, callback, 1)
#define map_get(x, key, data, callback) libcdsb_map_find (x, _LIBCDSB_var(key), data, callback, 0)
#define map_update(x, key, value) libcdsb_map_update (x, _LIBCDSB_var(key), _LIBCDSB_var(value), 0, 0)
#define map_inject(x, key, value) libcdsb_map_inject (x, _LIBCDSB_var(key), _LIBCDSB_var(value), 0, 0)
#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)
2022-06-08 09:56:14 +03:00
2022-08-19 18:46:51 +03:00
#define in_map(x, key) (map_get(x, key, 0, 0) == 0)
2022-06-08 09:56:14 +03:00
2022-08-19 18:46:51 +03:00
/*#####################################################################################################################*/
2022-06-08 09:56:14 +03:00
2023-03-23 16:15:28 +03:00
extern bool libcdsb_map_update (vtype_map* x, vtype_variable key, vtype_variable value, void* data, map_access_callback) Nonnull__(1);
extern bool libcdsb_map_inject (vtype_map* x, vtype_variable key, vtype_variable value, void* data, map_access_callback) Nonnull__(1);
extern int libcdsb_map_find (vtype_map* x, vtype_variable key, 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);
2022-06-08 09:56:14 +03:00
#endif /* LIBCDSB_MAP_H */