libcdsb/include/list.h

97 lines
8.3 KiB
C
Raw Normal View History

2022-06-04 21:58:04 +03:00
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "__generics.h"
#include "vtype.h"
#ifndef LIBCDSB_LIST_H
#define LIBCDSB_LIST_H
/*#####################################################################################################################*/
2022-06-08 20:59:07 +03:00
typedef int (*list_access_callback)(void* value, ssize_t index, vtype type, void* data);
2022-06-04 21:58:04 +03:00
extern void list_init(vtype_list* x);
extern void list_extend(vtype_list* x, const vtype_list* s);
2022-06-10 12:21:57 +03:00
extern size_t list_slice(vtype_list* x, vtype_list* src, ssize_t index, size_t count, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
2022-06-04 21:58:04 +03:00
extern void list_sort(vtype_list* x);
extern void list_reverse(vtype_list* x);
2022-06-08 20:59:07 +03:00
#define list_pop(x, value, data, callback) _LIBCDSB_Generic(libcdsb_list, find, value)(x, value, data, callback, 0, 1)
#define list_find(x, value, data, callback) _LIBCDSB_Generic(libcdsb_list, find, value)(x, value, data, callback, 0, 0)
#define list_rfind(x, value, data, callback) _LIBCDSB_Generic(libcdsb_list, find, value)(x, value, data, callback, 1, 0)
#define list_countof(x, value) _LIBCDSB_Generic(libcdsb_list, count, value)(x, value)
#define list_remove(x, value) list_pop(x, value, 0, 0)
#define in_list(x, value) (list_find(x, value, 0, 0) == 0)
2022-06-04 21:58:04 +03:00
#define list_insert(x, index, value) _LIBCDSB_Generic(libcdsb_list, update, value)(x, index, value, -1)
#define list_replace(x, index, value) _LIBCDSB_Generic(libcdsb_list, update, value)(x, index, value, 0)
#define list_push_back(x, value) _LIBCDSB_Generic(libcdsb_list, update, value)(x, -1, value, 1)
#define list_push_front(x, value) _LIBCDSB_Generic(libcdsb_list, update, value)(x, 0, value, -1)
/*#####################################################################################################################*/
2022-06-09 16:29:10 +03:00
extern int libcdsb_list_find_pointer(vtype_list* x, const void* value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_cstring(vtype_list* x, const char* value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_string (vtype_list* x, const vtype_string* value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_array (vtype_list* x, const vtype_array* value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_list (vtype_list* x, const vtype_list* value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_map (vtype_list* x, const vtype_map* value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_vset (vtype_list* x, const vtype_set* value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_boolean(vtype_list* x, vtype_bool value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_int8 (vtype_list* x, vtype_int8 value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_int16 (vtype_list* x, vtype_int16 value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_int32 (vtype_list* x, vtype_int32 value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_int64 (vtype_list* x, vtype_int64 value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_uint8 (vtype_list* x, vtype_uint8 value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_uint16 (vtype_list* x, vtype_uint16 value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_uint32 (vtype_list* x, vtype_uint32 value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_uint64 (vtype_list* x, vtype_uint64 value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_float (vtype_list* x, vtype_float value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_double (vtype_list* x, vtype_double value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_ldouble(vtype_list* x, vtype_ldouble value, void* data, list_access_callback, bool reverse, bool cut);
2022-06-04 21:58:04 +03:00
extern size_t libcdsb_list_count_pointer(const vtype_list* s, const void* value);
extern size_t libcdsb_list_count_cstring(const vtype_list* s, const char* value);
extern size_t libcdsb_list_count_string (const vtype_list* s, const vtype_string* value);
extern size_t libcdsb_list_count_array (const vtype_list* s, const vtype_array* value);
extern size_t libcdsb_list_count_list (const vtype_list* s, const vtype_list* value);
extern size_t libcdsb_list_count_map (const vtype_list* s, const vtype_map* value);
extern size_t libcdsb_list_count_vset (const vtype_list* s, const vtype_set* value);
extern size_t libcdsb_list_count_boolean(const vtype_list* s, vtype_bool value);
extern size_t libcdsb_list_count_int8 (const vtype_list* s, vtype_int8 value);
extern size_t libcdsb_list_count_int16 (const vtype_list* s, vtype_int16 value);
extern size_t libcdsb_list_count_int32 (const vtype_list* s, vtype_int32 value);
extern size_t libcdsb_list_count_int64 (const vtype_list* s, vtype_int64 value);
extern size_t libcdsb_list_count_uint8 (const vtype_list* s, vtype_uint8 value);
extern size_t libcdsb_list_count_uint16 (const vtype_list* s, vtype_uint16 value);
extern size_t libcdsb_list_count_uint32 (const vtype_list* s, vtype_uint32 value);
extern size_t libcdsb_list_count_uint64 (const vtype_list* s, vtype_uint64 value);
extern size_t libcdsb_list_count_float (const vtype_list* s, vtype_float value);
extern size_t libcdsb_list_count_double (const vtype_list* s, vtype_double value);
extern size_t libcdsb_list_count_ldouble(const vtype_list* s, vtype_ldouble value);
2022-06-09 16:29:10 +03:00
extern bool libcdsb_list_update_pointer(vtype_list* x, ssize_t index, const void* value, int ins_direction);
extern bool libcdsb_list_update_cstring(vtype_list* x, ssize_t index, const char* value, int ins_direction);
extern bool libcdsb_list_update_string (vtype_list* x, ssize_t index, const vtype_string* value, int ins_direction);
extern bool libcdsb_list_update_array (vtype_list* x, ssize_t index, const vtype_array* value, int ins_direction);
extern bool libcdsb_list_update_list (vtype_list* x, ssize_t index, const vtype_list* value, int ins_direction);
extern bool libcdsb_list_update_map (vtype_list* x, ssize_t index, const vtype_map* value, int ins_direction);
extern bool libcdsb_list_update_vset (vtype_list* x, ssize_t index, const vtype_set* value, int ins_direction);
extern bool libcdsb_list_update_boolean(vtype_list* x, ssize_t index, vtype_bool value, int ins_direction);
extern bool libcdsb_list_update_int8 (vtype_list* x, ssize_t index, vtype_int8 value, int ins_direction);
extern bool libcdsb_list_update_int16 (vtype_list* x, ssize_t index, vtype_int16 value, int ins_direction);
extern bool libcdsb_list_update_int32 (vtype_list* x, ssize_t index, vtype_int32 value, int ins_direction);
extern bool libcdsb_list_update_int64 (vtype_list* x, ssize_t index, vtype_int64 value, int ins_direction);
extern bool libcdsb_list_update_uint8 (vtype_list* x, ssize_t index, vtype_uint8 value, int ins_direction);
extern bool libcdsb_list_update_uint16 (vtype_list* x, ssize_t index, vtype_uint16 value, int ins_direction);
extern bool libcdsb_list_update_uint32 (vtype_list* x, ssize_t index, vtype_uint32 value, int ins_direction);
extern bool libcdsb_list_update_uint64 (vtype_list* x, ssize_t index, vtype_uint64 value, int ins_direction);
extern bool libcdsb_list_update_float (vtype_list* x, ssize_t index, vtype_float value, int ins_direction);
extern bool libcdsb_list_update_double (vtype_list* x, ssize_t index, vtype_double value, int ins_direction);
extern bool libcdsb_list_update_ldouble(vtype_list* x, ssize_t index, vtype_ldouble value, int ins_direction);
2022-06-04 21:58:04 +03:00
#endif /* LIBCDSB_LIST_H */