/* 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 #define LIBCDSB_ARRAY_H typedef int (*array_access_callback)(vtype_variable, ssize_t index, void* data); /*#####################################################################################################################*/ inline void array_init (vtype_array* x, vtype type) Always_inline__ Nonnull__(1); extern size_t array_slice (vtype_array* x, vtype_array* src, ssize_t index, size_t count, bool cut) Nonnull__(1); extern void array_sort (vtype_array* x) Nonnull__(1); extern void array_reverse (vtype_array* x) Nonnull__(1); extern void* at_array(const vtype_array* s, ssize_t index) Nonnull__(1); inline void array_init (vtype_array* x, vtype type) { x->type = type; x->mem = (void*)(x->size = 0); } /*#####################################################################################################################*/ #define array_pop(x, value, data, callback) libcdsb_array_find (x, _LIBCDSB_var(value), data, callback, 0, 1) #define array_get array_find #define array_pop_by_index(x, index, data, callback) libcdsb_array_get (x, index, data, callback, 1) #define array_get_by_index(x, index, data, callback) libcdsb_array_get (x, index, data, callback, 0) #define array_find(x, value, data, callback) libcdsb_array_find (x, _LIBCDSB_var(value), data, callback, 0, 0) #define array_rfind(x, value, data, callback) libcdsb_array_find (x, _LIBCDSB_var(value), data, callback, 1, 0) #define array_countof(x, value) libcdsb_array_count (x, _LIBCDSB_var(value)) #define array_push_back(x, value) libcdsb_array_insert (x, _LIBCDSB_var(value)) #define array_attach_back(x, value) libcdsb_array_attach (x, _LIBCDSB_var(value)) #define array_foreach(x, data, callback) libcdsb_array_foreach(x, data, callback, 0) #define array_remove(x, value) array_pop (x, value, 0, 0) #define array_remove_by_index(x, index) array_pop_by_index (x, index, 0, 0) #define in_array(x, value) (array_get(x, value, 0, 0) == 0) /*#####################################################################################################################*/ extern ssize_t libcdsb_array_insert (vtype_array* x, vtype_variable) Nonnull__(1); extern ssize_t libcdsb_array_attach (vtype_array* x, vtype_variable) Nonnull__(1); extern int libcdsb_array_find (vtype_array* x, vtype_variable, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); extern int libcdsb_array_get (vtype_array* x, ssize_t index, void* data, array_access_callback, bool cut) Nonnull__(1); extern int libcdsb_array_foreach (vtype_array* x, void* data, array_access_callback, bool flush) Nonnull__(1,3); extern size_t libcdsb_array_count(const vtype_array* s, vtype_variable) Pure__ Warn_unused_result__ Nonnull__(1); #endif /* LIBCDSB_ARRAY_H */