diff --git a/include/array.h b/include/array.h index 35bfd1f..68b37c3 100644 --- a/include/array.h +++ b/include/array.h @@ -1,6 +1,7 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ +#include "bits/__generics.h" #include "vtype.h" #ifndef LIBCDSB_ARRAY_H diff --git a/include/bits/__rbtree.h b/include/bits/__rbtree.h new file mode 100644 index 0000000..73cf384 --- /dev/null +++ b/include/bits/__rbtree.h @@ -0,0 +1,20 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#ifndef LIBCDSB_BITS_RBTREE_H +#define LIBCDSB_BITS_RBTREE_H + +typedef enum { + RBFOREACH_UNSPECIFIED = 0x00, + RBFOREACH_REVERSE = 0x80, + RBFOREACH_INORDER = 0x01, + RBFOREACH_PREORDER = 0x02, + RBFOREACH_POSTORDER = 0x04, + RBFOREACH_BREADTH_FIRST = 0x08, + RBFOREACH_INORDER_REVERSE = RBFOREACH_INORDER | RBFOREACH_REVERSE, + RBFOREACH_PREORDER_REVERSE = RBFOREACH_PREORDER | RBFOREACH_REVERSE, + RBFOREACH_POSTORDER_REVERSE = RBFOREACH_POSTORDER | RBFOREACH_REVERSE, + RBFOREACH_BREADTH_FIRST_REVERSE = RBFOREACH_BREADTH_FIRST | RBFOREACH_REVERSE +} rbforeach_t; + +#endif /* LIBCDSB_BITS_RBTREE_H */ diff --git a/include/dict.h b/include/dict.h index 23966e7..1be89a3 100644 --- a/include/dict.h +++ b/include/dict.h @@ -1,6 +1,7 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ +#include "bits/__generics.h" #include "vtype.h" #ifndef LIBCDSB_DICT_H diff --git a/include/list.h b/include/list.h index e617d48..0ebbf47 100644 --- a/include/list.h +++ b/include/list.h @@ -1,6 +1,7 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ +#include "bits/__generics.h" #include "vtype.h" #ifndef LIBCDSB_LIST_H diff --git a/include/map.h b/include/map.h index f04ef43..a3264be 100644 --- a/include/map.h +++ b/include/map.h @@ -1,6 +1,8 @@ /* 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 @@ -18,7 +20,7 @@ extern void map_init(vtype_map* x, vtype key_type) Nonnull__(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, 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) #define in_map(x, key) (map_get(x, key, 0, 0) == 0) @@ -28,6 +30,6 @@ extern void map_init(vtype_map* x, vtype key_type) Nonnull__(1); 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, bool flush) Nonnull__(1,3); +extern int libcdsb_map_foreach(vtype_map* x, void* data, map_access_callback, rbforeach_t, bool flush) Nonnull__(1,3); #endif /* LIBCDSB_MAP_H */ diff --git a/include/set.h b/include/set.h index 67857fa..e9ffa04 100644 --- a/include/set.h +++ b/include/set.h @@ -1,6 +1,8 @@ /* 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_SET_H @@ -18,7 +20,7 @@ extern void vset_init(vtype_set* x, vtype type) Nonnull__(1); #define vset_get(x, value, data, callback) libcdsb_vset_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0) #define vset_push(x, value) libcdsb_vset_insert (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) #define vset_attach(x, value) libcdsb_vset_attach (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) -#define vset_foreach(x, data, callback) libcdsb_vset_foreach(x, data, callback, 0) +#define vset_foreach(x, data, callback) libcdsb_vset_foreach(x, data, callback, RBFOREACH_UNSPECIFIED, 0) #define vset_remove(x, value) vset_pop (x, value, 0, 0) #define in_vset(x, value) (vset_get(x, value, 0, 0) == 0) @@ -28,6 +30,6 @@ extern void vset_init(vtype_set* x, vtype type) Nonnull__(1); extern bool libcdsb_vset_insert (vtype_set* x, const void* value, vtype type) Nonnull__(1); extern bool libcdsb_vset_attach (vtype_set* x, const void* value, vtype type) Nonnull__(1); extern int libcdsb_vset_find (vtype_set* x, const void* value, vtype type, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_foreach(vtype_set* x, void* data, vset_access_callback, bool flush) Nonnull__(1,3); +extern int libcdsb_vset_foreach(vtype_set* x, void* data, vset_access_callback, rbforeach_t, bool flush) Nonnull__(1,3); #endif /* LIBCDSB_SET_H */