From 57a8a08234d4752b62b0b61a7a5fc207a27ae982 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Fri, 19 Aug 2022 13:41:19 +0300 Subject: [PATCH 01/18] Refactor array, add attaching functional --- examples/array.c | 2 +- include/__generics.h | 55 +++++++++++++++ include/array.h | 103 ++++++++------------------- include/extra/array.h | 21 ------ src/array/{extra.c => access.c} | 42 ++--------- src/array/base.c | 119 -------------------------------- src/array/comparison.c | 35 ++++++++++ src/array/compute.c | 48 +++++++++++++ src/array/copy.c | 17 ----- src/array/generics.c | 67 ------------------ src/array/include.h | 18 ++++- src/array/memory.c | 49 +++++++++++++ src/array/modify.c | 55 +++++++++++++++ tests/src/array/plug.h | 2 +- tests/src/global/plug.h | 2 +- 15 files changed, 294 insertions(+), 341 deletions(-) delete mode 100644 include/extra/array.h rename src/array/{extra.c => access.c} (69%) delete mode 100644 src/array/base.c create mode 100644 src/array/comparison.c create mode 100644 src/array/compute.c delete mode 100644 src/array/generics.c create mode 100644 src/array/memory.c create mode 100644 src/array/modify.c diff --git a/examples/array.c b/examples/array.c index 29108c4..7dc68be 100644 --- a/examples/array.c +++ b/examples/array.c @@ -3,7 +3,7 @@ #include #include -#include "../include/extra/array.h" +#include "../include/array.h" typedef vtype_array arr_t; diff --git a/include/__generics.h b/include/__generics.h index 3f93adb..2bda8e2 100644 --- a/include/__generics.h +++ b/include/__generics.h @@ -4,6 +4,38 @@ #ifndef LIBCDSB_CORE_GENERICS_H #define LIBCDSB_CORE_GENERICS_H +#define vtypeof(x) (vtype)(_Generic((x),\ + const void*: VTYPE_POINTER, void*: VTYPE_POINTER,\ + const char**: VTYPE_STRING, char**: VTYPE_STRING,\ + const vtype_string*: VTYPE_STRING, vtype_string*: VTYPE_STRING,\ + const vtype_array*: VTYPE_ARRAY, vtype_array*: VTYPE_ARRAY,\ + const vtype_list*: VTYPE_LIST, vtype_list*: VTYPE_LIST,\ + const vtype_map*: VTYPE_MAP, vtype_map*: VTYPE_MAP,\ + const vtype_set*: VTYPE_SET, vtype_set*: VTYPE_SET,\ + const vtype_dict*: VTYPE_DICT, vtype_dict*: VTYPE_DICT,\ + vtype_bool: VTYPE_BOOLEAN,\ + vtype_uint8: VTYPE_UINT8,\ + vtype_uint16: VTYPE_UINT16,\ + vtype_uint32: VTYPE_UINT32,\ + vtype_uint64: VTYPE_UINT64,\ + vtype_int8: VTYPE_INT8,\ + vtype_int16: VTYPE_INT16,\ + vtype_int32: VTYPE_INT32,\ + vtype_int64: VTYPE_INT64,\ + vtype_float: VTYPE_FLOAT,\ + vtype_double: VTYPE_DOUBLE,\ + vtype_ldouble: VTYPE_LDOUBLE)) + +#define _LIBCDSB_vtypeof(x) vtypeof(_Generic((x), default: (x), const char*: &(x), char*: &(x))) +#define _LIBCDSB_value_pointer(x) _Generic((x), default: &(x),\ + vtype_string*: (x), const vtype_string*: (x),\ + vtype_array*: (x), const vtype_array*: (x),\ + vtype_list*: (x), const vtype_list*: (x),\ + vtype_map*: (x), const vtype_map*: (x),\ + vtype_set*: (x), const vtype_set*: (x),\ + vtype_dict*: (x), const vtype_dict*: (x)) + + #define _LIBCDSB_Generic(T, f, v) _Generic((v),\ void*: T ## _ ## f ## _pointer, const void*: T ## _ ## f ## _pointer,\ char*: T ## _ ## f ## _cstring, const char*: T ## _ ## f ## _cstring,\ @@ -50,6 +82,29 @@ vtype_ldouble: _LIBCDSB_Generic(T, f ## _ldouble, v)\ ) +#define _LIBCDSB_Generic_attach(T, ins_f, att_f, v) _Generic((v),\ + void*: T ## _ ## ins_f ## _pointer, const void*: T ## _ ## ins_f ## _pointer,\ + char*: T ## _ ## ins_f ## _cstring, const char*: T ## _ ## ins_f ## _cstring,\ + vtype_string*: T ## _ ## att_f ## _string, const vtype_string*: T ## _ ## att_f ## _string,\ + vtype_array*: T ## _ ## att_f ## _array, const vtype_array*: T ## _ ## att_f ## _array,\ + vtype_list*: T ## _ ## att_f ## _list, const vtype_list*: T ## _ ## att_f ## _list,\ + vtype_map*: T ## _ ## att_f ## _map, const vtype_map*: T ## _ ## att_f ## _map,\ + vtype_set*: T ## _ ## att_f ## _vset, const vtype_set*: T ## _ ## att_f ## _vset,\ + vtype_dict*: T ## _ ## att_f ## _dict, const vtype_dict*: T ## _ ## att_f ## _dict,\ + vtype_bool: T ## _ ## ins_f ## _boolean,\ + vtype_uint8: T ## _ ## ins_f ## _uint8,\ + vtype_uint16: T ## _ ## ins_f ## _uint16,\ + vtype_uint32: T ## _ ## ins_f ## _uint32,\ + vtype_uint64: T ## _ ## ins_f ## _uint64,\ + vtype_int8: T ## _ ## ins_f ## _int8,\ + vtype_int16: T ## _ ## ins_f ## _int16,\ + vtype_int32: T ## _ ## ins_f ## _int32,\ + vtype_int64: T ## _ ## ins_f ## _int64,\ + vtype_float: T ## _ ## ins_f ## _float,\ + vtype_double: T ## _ ## ins_f ## _double,\ + vtype_ldouble: T ## _ ## ins_f ## _ldouble\ +) + #define _LIBCDSB_GenericS(T, f, v) _Generic((v),\ void*: T ## _ ## f ## _cstring, const void*: T ## _ ## f ## _cstring,\ char*: T ## _ ## f ## _cstring, const char*: T ## _ ## f ## _cstring,\ diff --git a/include/array.h b/include/array.h index 5b6d177..0e54ed0 100644 --- a/include/array.h +++ b/include/array.h @@ -7,89 +7,42 @@ #ifndef LIBCDSB_ARRAY_H #define LIBCDSB_ARRAY_H -/*#####################################################################################################################*/ - typedef int (*array_access_callback)(void* value, ssize_t index, vtype type, void* data); -extern void array_init (vtype_array* x, vtype type) Nonnull__(1); -extern void* array_at (const vtype_array* s, ssize_t index) 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 array_init (vtype_array* x, vtype type) 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); -#define array_pop(x, value, data, callback) _LIBCDSB_Generic(libcdsb_array, find, value)(x, value, data, callback, 0, 1) -#define array_find(x, value, data, callback) _LIBCDSB_Generic(libcdsb_array, find, value)(x, value, data, callback, 0, 0) -#define array_rfind(x, value, data, callback) _LIBCDSB_Generic(libcdsb_array, find, value)(x, value, data, callback, 1, 0) -#define array_countof(x, value) _LIBCDSB_Generic(libcdsb_array, count, value)(x, value) -#define array_remove(x, value) array_pop(x, value, 0, 0) -#define in_array(x, value) (array_find(x, value, 0, 0) == 0) - -#define array_push_back(x, value) _LIBCDSB_Generic(libcdsb_array, push, value)(x, value) +extern void* at_array(const vtype_array* s, ssize_t index) Nonnull__(1); /*#####################################################################################################################*/ -extern void libcdsb_array_push_pointer(vtype_array* x, const void* value) Nonnull__(1); -extern void libcdsb_array_push_cstring(vtype_array* x, const char* value) Nonnull__(1,2); -extern void libcdsb_array_push_string (vtype_array* x, const vtype_string* value) Nonnull__(1,2); -extern void libcdsb_array_push_array (vtype_array* x, const vtype_array* value) Nonnull__(1,2); -extern void libcdsb_array_push_list (vtype_array* x, const vtype_list* value) Nonnull__(1,2); -extern void libcdsb_array_push_map (vtype_array* x, const vtype_map* value) Nonnull__(1,2); -extern void libcdsb_array_push_vset (vtype_array* x, const vtype_set* value) Nonnull__(1,2); -extern void libcdsb_array_push_dict (vtype_array* x, const vtype_dict* value) Nonnull__(1,2); -extern void libcdsb_array_push_boolean(vtype_array* x, vtype_bool value) Nonnull__(1); -extern void libcdsb_array_push_uint8 (vtype_array* x, vtype_uint8 value) Nonnull__(1); -extern void libcdsb_array_push_uint16 (vtype_array* x, vtype_uint16 value) Nonnull__(1); -extern void libcdsb_array_push_uint32 (vtype_array* x, vtype_uint32 value) Nonnull__(1); -extern void libcdsb_array_push_uint64 (vtype_array* x, vtype_uint64 value) Nonnull__(1); -extern void libcdsb_array_push_int8 (vtype_array* x, vtype_int8 value) Nonnull__(1); -extern void libcdsb_array_push_int16 (vtype_array* x, vtype_int16 value) Nonnull__(1); -extern void libcdsb_array_push_int32 (vtype_array* x, vtype_int32 value) Nonnull__(1); -extern void libcdsb_array_push_int64 (vtype_array* x, vtype_int64 value) Nonnull__(1); -extern void libcdsb_array_push_float (vtype_array* x, vtype_float value) Nonnull__(1); -extern void libcdsb_array_push_double (vtype_array* x, vtype_double value) Nonnull__(1); -extern void libcdsb_array_push_ldouble(vtype_array* x, vtype_ldouble value) Nonnull__(1); +#define array_pop(x, value, data, callback) libcdsb_array_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(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_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0, 0) +#define array_rfind(x, value, data, callback) libcdsb_array_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 1, 0) +#define array_countof(x, value) libcdsb_array_count (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) +#define array_push_back(x, value) libcdsb_array_insert (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) +#define array_attach_back(x, value) libcdsb_array_attach (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(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) -extern size_t libcdsb_array_count_pointer(const vtype_array* s, const void* value) Nonnull__(1); -extern size_t libcdsb_array_count_cstring(const vtype_array* s, const char* value) Nonnull__(1,2); -extern size_t libcdsb_array_count_string (const vtype_array* s, const vtype_string* value) Nonnull__(1,2); -extern size_t libcdsb_array_count_array (const vtype_array* s, const vtype_array* value) Nonnull__(1,2); -extern size_t libcdsb_array_count_list (const vtype_array* s, const vtype_list* value) Nonnull__(1,2); -extern size_t libcdsb_array_count_map (const vtype_array* s, const vtype_map* value) Nonnull__(1,2); -extern size_t libcdsb_array_count_vset (const vtype_array* s, const vtype_set* value) Nonnull__(1,2); -extern size_t libcdsb_array_count_dict (const vtype_array* s, const vtype_dict* value) Nonnull__(1,2); -extern size_t libcdsb_array_count_boolean(const vtype_array* s, vtype_bool value) Nonnull__(1); -extern size_t libcdsb_array_count_int8 (const vtype_array* s, vtype_int8 value) Nonnull__(1); -extern size_t libcdsb_array_count_int16 (const vtype_array* s, vtype_int16 value) Nonnull__(1); -extern size_t libcdsb_array_count_int32 (const vtype_array* s, vtype_int32 value) Nonnull__(1); -extern size_t libcdsb_array_count_int64 (const vtype_array* s, vtype_int64 value) Nonnull__(1); -extern size_t libcdsb_array_count_uint8 (const vtype_array* s, vtype_uint8 value) Nonnull__(1); -extern size_t libcdsb_array_count_uint16 (const vtype_array* s, vtype_uint16 value) Nonnull__(1); -extern size_t libcdsb_array_count_uint32 (const vtype_array* s, vtype_uint32 value) Nonnull__(1); -extern size_t libcdsb_array_count_uint64 (const vtype_array* s, vtype_uint64 value) Nonnull__(1); -extern size_t libcdsb_array_count_float (const vtype_array* s, vtype_float value) Nonnull__(1); -extern size_t libcdsb_array_count_double (const vtype_array* s, vtype_double value) Nonnull__(1); -extern size_t libcdsb_array_count_ldouble(const vtype_array* s, vtype_ldouble value) Nonnull__(1); +#define in_array(x, value) (array_get(x, value, 0, 0) == 0) -extern int libcdsb_array_find_pointer(vtype_array* x, const void* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_array_find_cstring(vtype_array* x, const char* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_array_find_string (vtype_array* x, const vtype_string* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_array_find_array (vtype_array* x, const vtype_array* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_array_find_list (vtype_array* x, const vtype_list* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_array_find_map (vtype_array* x, const vtype_map* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_array_find_vset (vtype_array* x, const vtype_set* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_array_find_dict (vtype_array* x, const vtype_dict* value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_array_find_boolean(vtype_array* x, vtype_bool value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_array_find_uint8 (vtype_array* x, vtype_uint8 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_array_find_uint16 (vtype_array* x, vtype_uint16 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_array_find_uint32 (vtype_array* x, vtype_uint32 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_array_find_uint64 (vtype_array* x, vtype_uint64 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_array_find_int8 (vtype_array* x, vtype_int8 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_array_find_int16 (vtype_array* x, vtype_int16 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_array_find_int32 (vtype_array* x, vtype_int32 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_array_find_int64 (vtype_array* x, vtype_int64 value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_array_find_float (vtype_array* x, vtype_float value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_array_find_double (vtype_array* x, vtype_double value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_array_find_ldouble(vtype_array* x, vtype_ldouble value, void* data, array_access_callback, bool reverse, bool cut) Nonnull__(1); +/*#####################################################################################################################*/ + +extern ssize_t libcdsb_array_insert (vtype_array* x, const void* value, vtype type) Nonnull__(1); +extern ssize_t libcdsb_array_attach (vtype_array* x, const void* value, vtype type) Nonnull__(1); +extern int libcdsb_array_find (vtype_array* x, const void* value, vtype type, 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, const void* value, vtype type) Pure__ Warn_unused_result__ Nonnull__(1); #endif /* LIBCDSB_ARRAY_H */ diff --git a/include/extra/array.h b/include/extra/array.h deleted file mode 100644 index 3728d2f..0000000 --- a/include/extra/array.h +++ /dev/null @@ -1,21 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "../array.h" - -#ifndef LIBCDSB_EXTRA_ARRAY_H -#define LIBCDSB_EXTRA_ARRAY_H - -#define array_get_by_index(s, index, data, callback) libcdsb_array_get(s, index, data, callback, 0) -#define array_pop_by_index(s, index, data, callback) libcdsb_array_get(s, index, data, callback, 1) -#define array_remove_by_index(s, index) libcdsb_array_get(s, index, 0, 0, 1) - -#define array_foreach(x, data, callback) libcdsb_array_foreach(x, data, callback, 0) - -extern ssize_t libcdsb_array_push (vtype_array* x, const void* value, vtype value_type) Nonnull__(1); -extern size_t libcdsb_array_count (const vtype_array* s, const void* value, vtype type) Pure__ Warn_unused_result__ Nonnull__(1); -extern int libcdsb_array_find (vtype_array* x, const void* value, vtype type, 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); - -#endif /* LIBCDSB_EXTRA_ARRAY_H */ diff --git a/src/array/extra.c b/src/array/access.c similarity index 69% rename from src/array/extra.c rename to src/array/access.c index 1b35a78..d787eda 100644 --- a/src/array/extra.c +++ b/src/array/access.c @@ -2,45 +2,13 @@ /* Copyright © 2022 Gregory Lirent */ #include "include.h" -#include "../__internal/assert.h" -#include "../__internal/vnode.h" -ssize_t libcdsb_array_push(arr_t* x, const void* v, vtype t) { - ssize_t i = x->size; - vnode_t n = vnode_tcreate(x->type, v, t); - - x->mem = realloc(x->mem, ++x->size * vtype_size(x->type)); - memcpy(array_internal_at(x, i), vnode_peek(&n, x->type), vtype_size(x->type)); - - if (vtype_size(x->type) > sizeof(void*) && x->type < VTYPE_STRING) - vnode_free(&n, x->type); - - return i; +void* at_array(const arr_t* x, ssize_t i) { + if (i < 0 && (i += x->size) < 0) + i = 0; + return x->mem + i * vtype_size(x->type); } - -size_t libcdsb_array_count(const arr_t* s, const void* v, vtype t) { - void *p; - void *e; - int cmp; - size_t n; - - p = s->mem; - e = array_end(s); - n = 0; - - do { - cmp = vtype_compare(p, s->type, v, t); - - if (cmp == 0) ++n; - - p += vtype_size(s->type); - } while (p < e); - - return n; -} - - int libcdsb_array_get(vtype_array* x, ssize_t i, void* _, array_access_callback callback, vtype_bool cut) { int r = 0; @@ -55,7 +23,6 @@ int libcdsb_array_get(vtype_array* x, ssize_t i, void* _, array_access_callback return r; } - int libcdsb_array_find(arr_t* x, const void* v, vtype t, void* _, array_access_callback callback, bool r, bool cut) { void *p; ssize_t i; @@ -97,7 +64,6 @@ int libcdsb_array_find(arr_t* x, const void* v, vtype t, void* _, array_access_c return cmp; } - int libcdsb_array_foreach(vtype_array* x, void* data, array_access_callback callback, bool flush) { void* p; diff --git a/src/array/base.c b/src/array/base.c deleted file mode 100644 index f674b0c..0000000 --- a/src/array/base.c +++ /dev/null @@ -1,119 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" -#include "../__internal/assert.h" - -typedef void (*type_free)(void*); - -static inline type_free get_type_free(vtype type) { - switch (type) { - default: - #ifndef NDEBUG - abort(); - #endif - case VTYPE_STRING: return (void*)string_free; - case VTYPE_ARRAY: return (void*) array_free; - case VTYPE_LIST: return (void*) list_free; - case VTYPE_MAP: return (void*) map_free; - case VTYPE_SET: return (void*) vset_free; - case VTYPE_DICT: return (void*) dict_free; - } -} - -/*#####################################################################################################################*/ - -hash_t array_hash(const arr_t* s) { - hash_t hash = 0; - - if (s->size > 0) - hash = vtype_hash(s->mem, s->type); - - if (s->size > 1) - hash += vtype_hash(array_internal_at(s, s->size - 1), s->type); - - hash ^= s->size; - - return hash + VTYPE_ARRAY; -} - -void array_init(arr_t* x, vtype t) { - x->type = t; - x->size = 0; - x->mem = nullptr; -} - -void array_free(arr_t* x) { - if (x->size && x->type >= VTYPE_STRING) { - void* p = x->mem; - type_free free_; - - assert(!is_null(p)); - - free_ = get_type_free(x->type); - - do { - free_(p); - p += vtype_size(x->type); - } while (--x->size); - } - - free(x->mem); - memset(x, 0, sizeof(*x)); -} - -/*#####################################################################################################################*/ - -size_t array_size (const arr_t* x) { - return x->size; -} - -size_t array_nmemb(const arr_t* x) { - return x->size*vtype_size(x->type); -} - -void* array_at(const arr_t* x, ssize_t i) { - if (i < 0 && (i += x->size) < 0) i = 0; - return x->mem + i*vtype_size(x->type); -} - -/*#####################################################################################################################*/ - -int array_compare(const arr_t* s0, const arr_t* s1) { - - void *e; - void *p0; - void *p1; - int c; - - if (s0 == s1) - return 0; - - if (s0->type != s1->type) - return (s0->type < s1->type) ? -1 : 1; - - if (s0->size != s1->size) - return (s0->size < s1->size) ? -1 : 1; - - if (!s0->size && !s0->size) - return 0; - - assert(!is_null(s0->mem) && !is_null(s1->mem)); - - p0 = s0->mem; - p1 = s1->mem; - - e = array_end(s0); - - do { - c = vtype_compare_eq(p0, p1, s0->type); - - if (c == 0) { - p0 += vtype_size(s0->type); - p1 += vtype_size(s0->type); - } else return c; - - } while (p0 < e); - - return 0; -} diff --git a/src/array/comparison.c b/src/array/comparison.c new file mode 100644 index 0000000..f073b46 --- /dev/null +++ b/src/array/comparison.c @@ -0,0 +1,35 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +int array_compare(const arr_t* s0, const arr_t* s1) { + void *e, *p0, *p1; + int cmp; + + if (s0 == s1 || (!s0->size && !s0->size)) + return 0; + + if (s0->type != s1->type) + return (s0->type < s1->type) ? -1 : 1; + + if (s0->size != s1->size) + return (s0->size < s1->size) ? -1 : 1; + + p0 = s0->mem; + p1 = s1->mem; + + e = array_end(s0); + + do { + cmp = vtype_compare_eq(p0, p1, s0->type); + + if (cmp == 0) { + p0 += vtype_size(s0->type); + p1 += vtype_size(s0->type); + } else return cmp; + + } while (p0 < e); + + return 0; +} diff --git a/src/array/compute.c b/src/array/compute.c new file mode 100644 index 0000000..eee0bdd --- /dev/null +++ b/src/array/compute.c @@ -0,0 +1,48 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" +#include "../__internal/assert.h" + +size_t array_size (const arr_t* x) { + return x->size; +} + +size_t array_nmemb(const arr_t* x) { + return x->size*vtype_size(x->type); +} + +hash_t array_hash(const arr_t* s) { + hash_t hash = 0; + + if (s->size > 0) + hash = vtype_hash(s->mem, s->type); + + if (s->size > 1) + hash += vtype_hash(array_internal_at(s, s->size - 1), s->type); + + hash ^= s->size; + + return hash + VTYPE_ARRAY; +} + +size_t libcdsb_array_count(const arr_t* s, const void* v, vtype t) { + void *p; + void *e; + int cmp; + size_t n; + + p = s->mem; + e = array_end(s); + n = 0; + + do { + cmp = vtype_compare(p, s->type, v, t); + + if (cmp == 0) ++n; + + p += vtype_size(s->type); + } while (p < e); + + return n; +} diff --git a/src/array/copy.c b/src/array/copy.c index 0100ce7..7f2194e 100644 --- a/src/array/copy.c +++ b/src/array/copy.c @@ -4,23 +4,6 @@ #include "include.h" #include "../__internal/assert.h" -typedef void (*type_initializer)(void*, const void*); - -static inline type_initializer get_type_initializer(vtype type) { - switch (type) { - default: - #ifndef NDEBUG - abort(); - #endif - case VTYPE_STRING: return (void*)string_copy_init; - case VTYPE_ARRAY: return (void*) array_copy_init; - case VTYPE_LIST: return (void*) list_copy_init; - case VTYPE_MAP: return (void*) map_copy_init; - case VTYPE_SET: return (void*) vset_copy_init; - case VTYPE_DICT: return (void*) dict_copy_init; - } -} - arr_t array_copy(const arr_t* s) { arr_t x = { .mem = 0, .size = 0, .type = 0 }; diff --git a/src/array/generics.c b/src/array/generics.c deleted file mode 100644 index e34028a..0000000 --- a/src/array/generics.c +++ /dev/null @@ -1,67 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - -int libcdsb_array_find_pointer(arr_t* x, const void* v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_cstring(arr_t* x, const char* v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_string (arr_t* x, const str_t* v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, v, vtypeof( v), _, cb, r, cut); } -int libcdsb_array_find_array (arr_t* x, const arr_t* v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, v, vtypeof( v), _, cb, r, cut); } -int libcdsb_array_find_list (arr_t* x, const list_t* v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, v, vtypeof( v), _, cb, r, cut); } -int libcdsb_array_find_map (arr_t* x, const map_t* v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, v, vtypeof( v), _, cb, r, cut); } -int libcdsb_array_find_vset (arr_t* x, const set_t* v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, v, vtypeof( v), _, cb, r, cut); } -int libcdsb_array_find_dict (arr_t* x, const dict_t* v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, v, vtypeof( v), _, cb, r, cut); } -int libcdsb_array_find_boolean(arr_t* x, bool v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_int8 (arr_t* x, s8_t v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_int16 (arr_t* x, s16_t v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_int32 (arr_t* x, s32_t v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_int64 (arr_t* x, s64_t v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_uint8 (arr_t* x, u8_t v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_uint16 (arr_t* x, u16_t v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_uint32 (arr_t* x, u32_t v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_uint64 (arr_t* x, u64_t v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_float (arr_t* x, fl_t v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_double (arr_t* x, dbl_t v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_array_find_ldouble(arr_t* x, ldbl_t v, void* _, array_access_callback cb, bool r, bool cut) { return libcdsb_array_find(x, &v, vtypeof(&v), _, cb, r, cut); } - -size_t libcdsb_array_count_pointer(const arr_t* x, const void* v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_cstring(const arr_t* x, const char* v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_string (const arr_t* x, const str_t* v) { return libcdsb_array_count(x, v, vtypeof( v)); } -size_t libcdsb_array_count_array (const arr_t* x, const arr_t* v) { return libcdsb_array_count(x, v, vtypeof( v)); } -size_t libcdsb_array_count_list (const arr_t* x, const list_t* v) { return libcdsb_array_count(x, v, vtypeof( v)); } -size_t libcdsb_array_count_map (const arr_t* x, const map_t* v) { return libcdsb_array_count(x, v, vtypeof( v)); } -size_t libcdsb_array_count_vset (const arr_t* x, const set_t* v) { return libcdsb_array_count(x, v, vtypeof( v)); } -size_t libcdsb_array_count_dict (const arr_t* x, const dict_t* v) { return libcdsb_array_count(x, v, vtypeof( v)); } -size_t libcdsb_array_count_boolean(const arr_t* x, bool v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_int8 (const arr_t* x, s8_t v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_int16 (const arr_t* x, s16_t v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_int32 (const arr_t* x, s32_t v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_int64 (const arr_t* x, s64_t v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_uint8 (const arr_t* x, u8_t v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_uint16 (const arr_t* x, u16_t v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_uint32 (const arr_t* x, u32_t v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_uint64 (const arr_t* x, u64_t v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_float (const arr_t* x, fl_t v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_double (const arr_t* x, dbl_t v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } -size_t libcdsb_array_count_ldouble(const arr_t* x, ldbl_t v) { return libcdsb_array_count(x, &v, vtypeof(&v)); } - -void libcdsb_array_push_pointer(arr_t* x, const void* v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_cstring(arr_t* x, const char* v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_string (arr_t* x, const str_t* v) { libcdsb_array_push(x, v, vtypeof( v)); } -void libcdsb_array_push_array (arr_t* x, const arr_t* v) { libcdsb_array_push(x, v, vtypeof( v)); } -void libcdsb_array_push_list (arr_t* x, const list_t* v) { libcdsb_array_push(x, v, vtypeof( v)); } -void libcdsb_array_push_map (arr_t* x, const map_t* v) { libcdsb_array_push(x, v, vtypeof( v)); } -void libcdsb_array_push_vset (arr_t* x, const set_t* v) { libcdsb_array_push(x, v, vtypeof( v)); } -void libcdsb_array_push_dict (arr_t* x, const dict_t* v) { libcdsb_array_push(x, v, vtypeof( v)); } -void libcdsb_array_push_boolean(arr_t* x, bool v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_int8 (arr_t* x, s8_t v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_int16 (arr_t* x, s16_t v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_int32 (arr_t* x, s32_t v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_int64 (arr_t* x, s64_t v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_uint8 (arr_t* x, u8_t v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_uint16 (arr_t* x, u16_t v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_uint32 (arr_t* x, u32_t v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_uint64 (arr_t* x, u64_t v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_float (arr_t* x, fl_t v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_double (arr_t* x, dbl_t v) { libcdsb_array_push(x, &v, vtypeof(&v)); } -void libcdsb_array_push_ldouble(arr_t* x, ldbl_t v) { libcdsb_array_push(x, &v, vtypeof(&v)); } diff --git a/src/array/include.h b/src/array/include.h index a9c17b8..38db83c 100644 --- a/src/array/include.h +++ b/src/array/include.h @@ -2,12 +2,28 @@ /* Copyright © 2022 Gregory Lirent */ #include "../../include/array.h" -#include "../../include/extra/array.h" #include "../__internal/include.h" #ifndef LIBCDSB_SRC_ARRAY_INCLUDE_H #define LIBCDSB_SRC_ARRAY_INCLUDE_H +typedef void (*type_initializer)(void*, const void*); + +ainline(type_initializer get_type_initializer(vtype type)) { + switch (type) { + default: + #ifndef NDEBUG + abort(); + #endif + case VTYPE_STRING: return (void*)string_copy_init; + case VTYPE_ARRAY: return (void*) array_copy_init; + case VTYPE_LIST: return (void*) list_copy_init; + case VTYPE_MAP: return (void*) map_copy_init; + case VTYPE_SET: return (void*) vset_copy_init; + case VTYPE_DICT: return (void*) dict_copy_init; + } +} + ainline(void array_cut(arr_t* x, size_t i, size_t n)) { void* v = x->mem + i*vtype_size(x->type); void* e = v + n*vtype_size(x->type); diff --git a/src/array/memory.c b/src/array/memory.c new file mode 100644 index 0000000..5a84119 --- /dev/null +++ b/src/array/memory.c @@ -0,0 +1,49 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" +#include "../__internal/assert.h" + +typedef void (*type_free)(void*); + +static inline type_free get_type_free(vtype type) { + switch (type) { + default: + #ifndef NDEBUG + abort(); + #endif + case VTYPE_STRING: return (void*)string_free; + case VTYPE_ARRAY: return (void*) array_free; + case VTYPE_LIST: return (void*) list_free; + case VTYPE_MAP: return (void*) map_free; + case VTYPE_SET: return (void*) vset_free; + case VTYPE_DICT: return (void*) dict_free; + } +} + +/*#####################################################################################################################*/ + +void array_init(arr_t* x, vtype t) { + x->type = t; + x->size = 0; + x->mem = nullptr; +} + +void array_free(arr_t* x) { + if (x->size && x->type >= VTYPE_STRING) { + void* p = x->mem; + type_free free_; + + assert(!is_null(p)); + + free_ = get_type_free(x->type); + + do { + free_(p); + p += vtype_size(x->type); + } while (--x->size); + } + + free(x->mem); + memset(x, 0, sizeof(*x)); +} diff --git a/src/array/modify.c b/src/array/modify.c new file mode 100644 index 0000000..0fe9e05 --- /dev/null +++ b/src/array/modify.c @@ -0,0 +1,55 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" +#include "../__internal/assert.h" +#include "../__internal/vnode.h" + +ssize_t libcdsb_array_insert(arr_t* x, const void* v, vtype t) { + ssize_t i; + vnode_t n; + + i = x->size; + n = vnode_tcreate(x->type, v, t); + x->mem = realloc(x->mem, ++x->size * vtype_size(x->type)); + + if (t < VTYPE_STRING) { + n = vnode_tcreate(x->type, v, t); + memcpy(array_internal_at(x, i), vnode_peek(&n, x->type), vtype_size(x->type)); + + if (vtype_size(x->type) > sizeof(vnode_t)) + vnode_free(&n, x->type); + + } else if (x->type == t) { + get_type_initializer(t)(array_internal_at(x, i), v); + } + #ifndef NDEBUG + else abort(); + #endif + + return i; +} + +ssize_t libcdsb_array_attach(arr_t* x, const void* v, vtype t) { + ssize_t i; + vnode_t n; + + i = x->size; + x->mem = realloc(x->mem, ++x->size * vtype_size(x->type)); + + if (t < VTYPE_STRING) { + n = vnode_tcreate(x->type, v, t); + memcpy(array_internal_at(x, i), vnode_peek(&n, x->type), vtype_size(x->type)); + + if (vtype_size(x->type) > sizeof(vnode_t)) + vnode_free(&n, x->type); + + } else if (x->type == t) { + memcpy(array_internal_at(x, i), v, vtype_size(t)); + } + #ifndef NDEBUG + else abort(); + #endif + + return i; +} diff --git a/tests/src/array/plug.h b/tests/src/array/plug.h index f852e45..0243a08 100644 --- a/tests/src/array/plug.h +++ b/tests/src/array/plug.h @@ -3,7 +3,7 @@ #include #include "../../../include/extra/vtype.h" -#include "../../../include/extra/array.h" +#include "../../../include/array.h" #include "../../include/random.h" #include "../../include/test.h" diff --git a/tests/src/global/plug.h b/tests/src/global/plug.h index 6b280eb..3692f9c 100644 --- a/tests/src/global/plug.h +++ b/tests/src/global/plug.h @@ -2,7 +2,7 @@ /* Copyright © 2022 Gregory Lirent */ #include "../../../include/extra/string.h" -#include "../../../include/extra/array.h" +#include "../../../include/array.h" #include "../../../include/extra/list.h" #include "../../../include/extra/set.h" #include "../../../include/extra/map.h" From 925a8855ed2536a317eae7b407e157d943fb40ac Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Fri, 19 Aug 2022 16:46:07 +0300 Subject: [PATCH 02/18] Refactor list, add attaching functional --- examples/list.c | 8 +-- include/extra/list.h | 22 ------- include/list.h | 100 +++++++++--------------------- src/list/{extra.c => access.c} | 71 ---------------------- src/list/base.c | 93 ---------------------------- src/list/comparison.c | 36 +++++++++++ src/list/compute.c | 57 ++++++++++++++++++ src/list/copy.c | 7 +-- src/list/generics.c | 67 --------------------- src/list/include.h | 2 +- src/list/memory.c | 25 ++++++++ src/list/modify.c | 107 +++++++++++++++++++++++++++++++++ tests/src/list/plug.h | 2 +- 13 files changed, 261 insertions(+), 336 deletions(-) delete mode 100644 include/extra/list.h rename src/list/{extra.c => access.c} (65%) delete mode 100644 src/list/base.c create mode 100644 src/list/comparison.c create mode 100644 src/list/compute.c delete mode 100644 src/list/generics.c create mode 100644 src/list/memory.c create mode 100644 src/list/modify.c diff --git a/examples/list.c b/examples/list.c index 449ba2d..83ca85a 100644 --- a/examples/list.c +++ b/examples/list.c @@ -3,7 +3,7 @@ #include #include -#include "../include/extra/list.h" +#include "../include/list.h" typedef vtype_list list_t; @@ -33,11 +33,11 @@ int main(int argc, char** argv) { list_init(&list); - for (size_t i = 0; i < 28; ++i) { + for (vtype_int32 i = 0; i < 28; ++i) { if (i%2) { - list_push_back(&list, (vtype_int32)i); + list_push_back(&list, i); } else { - list_push_back(&list, (vtype_float)fl); + list_push_back(&list, fl); fl += 0.05; } } diff --git a/include/extra/list.h b/include/extra/list.h deleted file mode 100644 index f83343d..0000000 --- a/include/extra/list.h +++ /dev/null @@ -1,22 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "../list.h" - -#ifndef LIBCDSB_EXTRA_LIST_H -#define LIBCDSB_EXTRA_LIST_H - -#define list_get_by_index(x, index, data, callback) libcdsb_list_get(x, index, data, callback, 0) -#define list_pop_by_index(x, index, data, callback) libcdsb_list_get(x, index, data, callback, 1) -#define list_remove_by_index(x, index) libcdsb_list_get(x, index, 0, 0, 1) - -#define list_foreach(x, data, callback) libcdsb_list_foreach(x, data, callback, 0) - -extern bool libcdsb_list_update(vtype_list* x, ssize_t index, const void* value, vtype type, int ins_direction) Nonnull__(1); -extern size_t libcdsb_list_count(const vtype_list* s, const void* value, vtype type) Pure__ Warn_unused_result__ Nonnull__(1); - -extern int libcdsb_list_find (vtype_list* x, const void* value, vtype type, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_get (vtype_list* x, ssize_t index, void* data, list_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_list_foreach(vtype_list* x, void* data, list_access_callback, bool flush) Nonnull__(1,3); - -#endif /* LIBCDSB_EXTRA_LIST_H */ diff --git a/include/list.h b/include/list.h index 2cde5b4..31b545a 100644 --- a/include/list.h +++ b/include/list.h @@ -7,91 +7,45 @@ #ifndef LIBCDSB_LIST_H #define LIBCDSB_LIST_H -/*#####################################################################################################################*/ - typedef int (*list_access_callback)(void* value, ssize_t index, vtype type, void* data); +/*#####################################################################################################################*/ + extern void list_init (vtype_list* x) Nonnull__(1); extern void list_extend (vtype_list* x, const vtype_list* s) Nonnull__(1,2); extern size_t list_slice (vtype_list* x, vtype_list* src, ssize_t index, size_t count, bool cut) Nonnull__(1,2); extern void list_sort (vtype_list* x) Nonnull__(1); extern void list_reverse(vtype_list* x) Nonnull__(1); -#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) +/*#####################################################################################################################*/ -#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) +#define list_pop(x, value, data, callback) libcdsb_list_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0, 1) +#define list_get list_find +#define list_pop_by_index(x, index, data, callback) libcdsb_list_get (x, index, data, callback, 1) +#define list_get_by_index(x, index, data, callback) libcdsb_list_get (x, index, data, callback, 0) +#define list_find(x, value, data, callback) libcdsb_list_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0, 0) +#define list_rfind(x, value, data, callback) libcdsb_list_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 1, 0) +#define list_countof(x, value) libcdsb_list_count (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) +#define list_insert(x, index, value) libcdsb_list_insert (x, index, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), -1) +#define list_replace(x, index, value) libcdsb_list_insert (x, index, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), 0) +#define list_push_back(x, value) libcdsb_list_insert (x, -1, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), 1) +#define list_push_front(x, value) libcdsb_list_insert (x, 0, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), -1) +#define list_attach_back(x, value) libcdsb_list_attach (x, -1, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), 1) +#define list_attach_front(x, value) libcdsb_list_attach (x, 0, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), -1) +#define list_foreach(x, data, callback) libcdsb_list_foreach(x, data, callback, 0) +#define list_remove(x, value) list_pop (x, value, 0, 0) +#define list_remove_by_index(x, index) list_pop_by_index (x, index, 0, 0) + +#define in_list(x, value) (list_get(x, value, 0, 0) == 0) /*#####################################################################################################################*/ -extern int libcdsb_list_find_pointer(vtype_list* x, const void* value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_find_cstring(vtype_list* x, const char* value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_list_find_string (vtype_list* x, const vtype_string* value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_list_find_array (vtype_list* x, const vtype_array* value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_list_find_list (vtype_list* x, const vtype_list* value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_list_find_map (vtype_list* x, const vtype_map* value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_list_find_vset (vtype_list* x, const vtype_set* value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_list_find_dict (vtype_list* x, const vtype_dict* value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1,2); -extern int libcdsb_list_find_boolean(vtype_list* x, vtype_bool value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_find_int8 (vtype_list* x, vtype_int8 value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_find_int16 (vtype_list* x, vtype_int16 value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_find_int32 (vtype_list* x, vtype_int32 value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_find_int64 (vtype_list* x, vtype_int64 value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_find_uint8 (vtype_list* x, vtype_uint8 value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_find_uint16 (vtype_list* x, vtype_uint16 value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_find_uint32 (vtype_list* x, vtype_uint32 value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_find_uint64 (vtype_list* x, vtype_uint64 value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_find_float (vtype_list* x, vtype_float value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_find_double (vtype_list* x, vtype_double value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); -extern int libcdsb_list_find_ldouble(vtype_list* x, vtype_ldouble value, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); +extern bool libcdsb_list_insert (vtype_list* x, ssize_t index, const void* value, vtype type, int ins_direction) Nonnull__(1); +extern bool libcdsb_list_attach (vtype_list* x, ssize_t index, const void* value, vtype type, int ins_direction) Nonnull__(1); +extern int libcdsb_list_find (vtype_list* x, const void* value, vtype type, void* data, list_access_callback, bool reverse, bool cut) Nonnull__(1); +extern int libcdsb_list_get (vtype_list* x, ssize_t index, void* data, list_access_callback, bool cut) Nonnull__(1); +extern int libcdsb_list_foreach (vtype_list* x, void* data, list_access_callback, bool flush) Nonnull__(1,3); -extern size_t libcdsb_list_count_pointer(const vtype_list* s, const void* value) Nonnull__(1); -extern size_t libcdsb_list_count_cstring(const vtype_list* s, const char* value) Nonnull__(1,2); -extern size_t libcdsb_list_count_string (const vtype_list* s, const vtype_string* value) Nonnull__(1,2); -extern size_t libcdsb_list_count_array (const vtype_list* s, const vtype_array* value) Nonnull__(1,2); -extern size_t libcdsb_list_count_list (const vtype_list* s, const vtype_list* value) Nonnull__(1,2); -extern size_t libcdsb_list_count_map (const vtype_list* s, const vtype_map* value) Nonnull__(1,2); -extern size_t libcdsb_list_count_vset (const vtype_list* s, const vtype_set* value) Nonnull__(1,2); -extern size_t libcdsb_list_count_dict (const vtype_list* s, const vtype_dict* value) Nonnull__(1,2); -extern size_t libcdsb_list_count_boolean(const vtype_list* s, vtype_bool value) Nonnull__(1); -extern size_t libcdsb_list_count_int8 (const vtype_list* s, vtype_int8 value) Nonnull__(1); -extern size_t libcdsb_list_count_int16 (const vtype_list* s, vtype_int16 value) Nonnull__(1); -extern size_t libcdsb_list_count_int32 (const vtype_list* s, vtype_int32 value) Nonnull__(1); -extern size_t libcdsb_list_count_int64 (const vtype_list* s, vtype_int64 value) Nonnull__(1); -extern size_t libcdsb_list_count_uint8 (const vtype_list* s, vtype_uint8 value) Nonnull__(1); -extern size_t libcdsb_list_count_uint16 (const vtype_list* s, vtype_uint16 value) Nonnull__(1); -extern size_t libcdsb_list_count_uint32 (const vtype_list* s, vtype_uint32 value) Nonnull__(1); -extern size_t libcdsb_list_count_uint64 (const vtype_list* s, vtype_uint64 value) Nonnull__(1); -extern size_t libcdsb_list_count_float (const vtype_list* s, vtype_float value) Nonnull__(1); -extern size_t libcdsb_list_count_double (const vtype_list* s, vtype_double value) Nonnull__(1); -extern size_t libcdsb_list_count_ldouble(const vtype_list* s, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_list_update_pointer(vtype_list* x, ssize_t index, const void* value, int ins_direction) Nonnull__(1); -extern bool libcdsb_list_update_cstring(vtype_list* x, ssize_t index, const char* value, int ins_direction) Nonnull__(1,3); -extern bool libcdsb_list_update_string (vtype_list* x, ssize_t index, const vtype_string* value, int ins_direction) Nonnull__(1,3); -extern bool libcdsb_list_update_array (vtype_list* x, ssize_t index, const vtype_array* value, int ins_direction) Nonnull__(1,3); -extern bool libcdsb_list_update_list (vtype_list* x, ssize_t index, const vtype_list* value, int ins_direction) Nonnull__(1,3); -extern bool libcdsb_list_update_map (vtype_list* x, ssize_t index, const vtype_map* value, int ins_direction) Nonnull__(1,3); -extern bool libcdsb_list_update_vset (vtype_list* x, ssize_t index, const vtype_set* value, int ins_direction) Nonnull__(1,3); -extern bool libcdsb_list_update_dict (vtype_list* x, ssize_t index, const vtype_dict* value, int ins_direction) Nonnull__(1,3); -extern bool libcdsb_list_update_boolean(vtype_list* x, ssize_t index, vtype_bool value, int ins_direction) Nonnull__(1); -extern bool libcdsb_list_update_int8 (vtype_list* x, ssize_t index, vtype_int8 value, int ins_direction) Nonnull__(1); -extern bool libcdsb_list_update_int16 (vtype_list* x, ssize_t index, vtype_int16 value, int ins_direction) Nonnull__(1); -extern bool libcdsb_list_update_int32 (vtype_list* x, ssize_t index, vtype_int32 value, int ins_direction) Nonnull__(1); -extern bool libcdsb_list_update_int64 (vtype_list* x, ssize_t index, vtype_int64 value, int ins_direction) Nonnull__(1); -extern bool libcdsb_list_update_uint8 (vtype_list* x, ssize_t index, vtype_uint8 value, int ins_direction) Nonnull__(1); -extern bool libcdsb_list_update_uint16 (vtype_list* x, ssize_t index, vtype_uint16 value, int ins_direction) Nonnull__(1); -extern bool libcdsb_list_update_uint32 (vtype_list* x, ssize_t index, vtype_uint32 value, int ins_direction) Nonnull__(1); -extern bool libcdsb_list_update_uint64 (vtype_list* x, ssize_t index, vtype_uint64 value, int ins_direction) Nonnull__(1); -extern bool libcdsb_list_update_float (vtype_list* x, ssize_t index, vtype_float value, int ins_direction) Nonnull__(1); -extern bool libcdsb_list_update_double (vtype_list* x, ssize_t index, vtype_double value, int ins_direction) Nonnull__(1); -extern bool libcdsb_list_update_ldouble(vtype_list* x, ssize_t index, vtype_ldouble value, int ins_direction) Nonnull__(1); +extern size_t libcdsb_list_count(const vtype_list* s, const void* value, vtype type) Pure__ Warn_unused_result__ Nonnull__(1); #endif /* LIBCDSB_LIST_H */ diff --git a/src/list/extra.c b/src/list/access.c similarity index 65% rename from src/list/extra.c rename to src/list/access.c index 305c7e9..4232de7 100644 --- a/src/list/extra.c +++ b/src/list/access.c @@ -18,79 +18,8 @@ static void lnode_cut(list_t* s, lnode_t* cur) { free(cur); } - /*#####################################################################################################################*/ - -bool libcdsb_list_update(list_t* x, ssize_t i, const void* v, vtype t, int ins) { - - ldir_t dir; - lnode_t* c; - - if (i < 0) { - i = ~i; - dir = LD_PREV; - } else dir = LD_NEXT; - - c = ldir_dir((lnode_t*)x, dir); - - while (i && !is_null(c)) { - c = ldir_dir(c, dir); - --i; - } - - if (i && dir == LD_PREV) { - c = x->first; - } else if (i) return false; - - if (is_null(c)) { - x->first = x->last = c = calloc(sizeof(*c), 1); - } else if (ins) { - lnode_t *v = malloc(sizeof(*v)); - - dir = (ins < 0) ? LD_PREV : LD_NEXT; - - ldir_dir(v, dir) = ldir_dir(c, dir); - ldir_inv(v, dir) = c; - - c = v; - - if (!is_null(ldir_dir(c, dir))) { - ldir_inv(ldir_dir(c, dir), dir) = c; - } else ldir_inv((lnode_t*)x, dir) = c; - - ldir_dir(ldir_inv(c, dir), dir) = c; - - } else vnode_free(&c->node, c->type); - - c->node = vnode_create(v, t); - c->type = t; - - return true; -} - - -size_t libcdsb_list_count(const list_t* s, const void* v, vtype t) { - - lnode_t* c; - size_t n; - int cmp; - - c = s->first; - n = 0; - - while (!is_null(c)) { - cmp = vtype_compare(vnode_peek(&c->node, c->type), c->type, v, t); - - if (cmp == 0) ++n; - - c = c->next; - } - - return n; -} - - int libcdsb_list_get(vtype_list* x, ssize_t i, void* _, list_access_callback callback, bool cut) { ldir_t dir; diff --git a/src/list/base.c b/src/list/base.c deleted file mode 100644 index 57071fb..0000000 --- a/src/list/base.c +++ /dev/null @@ -1,93 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - -/*#####################################################################################################################*/ - -hash_t list_hash(const list_t* s) { - - hash_t hash = 0; - - if (!is_null(s->first)) { - hash = vnode_hash(&s->first->node, s->first->type); - - if (s->first != s->last) { - hash += vnode_hash(&s->first->node, s->first->type); - hash ^= list_size(s); - } else hash ^= 1; - } - - return hash + VTYPE_LIST; -} - -void list_init(list_t* x) { - memset(x, 0, sizeof(*x)); -} - -void list_free(list_t* x) { - lnode_t* c; - lnode_t* next; - - c = x->first; - - while (!is_null(c)) { - next = c->next; - vnode_free(&c->node, c->type); - free(c); - c = next; - } - - memset(x, 0, sizeof(*x)); -} - -/*#####################################################################################################################*/ - -size_t list_size(const list_t* x) { - lnode_t* c; - size_t n; - - c = x->first; - n = 0; - - while (!is_null(c)) { - c = c->next; - ++n; - } - - return n; -} - -/*#####################################################################################################################*/ - -int list_compare(const list_t* s0, const list_t* s1) { - lnode_t *c0, *c1; - int c; - - if (s0 == s1) return 0; - - c0 = s0->first; - c1 = s1->first; - - for (;;) { - if (is_null(c0) || is_null(c1)) { - return (c0 == c1) ? 0 : (ssize_t)c0 - (ssize_t)c1; - } - - c = lnode_compare(c0, c1); - - if (c != 0) break; - - c0 = c0->next; - c1 = c1->next; - } - - for (;;) { - c0 = c0->next; - c1 = c1->next; - - if (is_null(c0) || is_null(c1)) { - return (c0 == c1) ? 0 : (ssize_t)c0 - (ssize_t)c1; - } - } -} diff --git a/src/list/comparison.c b/src/list/comparison.c new file mode 100644 index 0000000..0292fc4 --- /dev/null +++ b/src/list/comparison.c @@ -0,0 +1,36 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +int list_compare(const list_t* s0, const list_t* s1) { + lnode_t *c0, *c1; + int c; + + if (s0 == s1) return 0; + + c0 = s0->first; + c1 = s1->first; + + for (;;) { + if (is_null(c0) || is_null(c1)) { + return (c0 == c1) ? 0 : (ssize_t)c0 - (ssize_t)c1; + } + + c = lnode_compare(c0, c1); + + if (c != 0) break; + + c0 = c0->next; + c1 = c1->next; + } + + for (;;) { + c0 = c0->next; + c1 = c1->next; + + if (is_null(c0) || is_null(c1)) { + return (c0 == c1) ? 0 : (ssize_t)c0 - (ssize_t)c1; + } + } +} diff --git a/src/list/compute.c b/src/list/compute.c new file mode 100644 index 0000000..7d40aee --- /dev/null +++ b/src/list/compute.c @@ -0,0 +1,57 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +size_t list_size(const list_t* x) { + lnode_t* c; + size_t n; + + c = x->first; + n = 0; + + while (!is_null(c)) { + c = c->next; + ++n; + } + + return n; +} + + +hash_t list_hash(const list_t* s) { + + hash_t hash = 0; + + if (!is_null(s->first)) { + hash = vnode_hash(&s->first->node, s->first->type); + + if (s->first != s->last) { + hash += vnode_hash(&s->first->node, s->first->type); + hash ^= list_size(s); + } else hash ^= 1; + } + + return hash + VTYPE_LIST; +} + + +size_t libcdsb_list_count(const list_t* s, const void* v, vtype t) { + + lnode_t* c; + size_t n; + int cmp; + + c = s->first; + n = 0; + + while (!is_null(c)) { + cmp = vtype_compare(vnode_peek(&c->node, c->type), c->type, v, t); + + if (cmp == 0) ++n; + + c = c->next; + } + + return n; +} diff --git a/src/list/copy.c b/src/list/copy.c index ba45032..3e1fae4 100644 --- a/src/list/copy.c +++ b/src/list/copy.c @@ -3,8 +3,6 @@ #include "include.h" -/*#####################################################################################################################*/ - static void init_first(list_t* x, vnode_t v, vtype t) { lnode_t* node = malloc(sizeof(*node)); @@ -17,6 +15,7 @@ static void init_first(list_t* x, vnode_t v, vtype t) { x->last = node; } + static void push_next(list_t* x, vnode_t v, vtype t) { lnode_t* node = malloc(sizeof(*node)); @@ -50,6 +49,7 @@ list_t list_copy(const list_t* s) { return x; } + list_t* list_duplicate(const list_t* s) { list_t* x; lnode_t* c; @@ -69,6 +69,7 @@ list_t* list_duplicate(const list_t* s) { return x; } + void list_copy_init(list_t* x, const list_t* s) { lnode_t* c; @@ -85,7 +86,6 @@ void list_copy_init(list_t* x, const list_t* s) { } } -/*#####################################################################################################################*/ void list_extend(list_t* x, const list_t* s) { lnode_t* c; @@ -109,7 +109,6 @@ void list_extend(list_t* x, const list_t* s) { } - size_t list_slice(list_t* x, list_t* s, ssize_t i, size_t n, _Bool cut) { lnode_t* c; diff --git a/src/list/generics.c b/src/list/generics.c deleted file mode 100644 index c2157e6..0000000 --- a/src/list/generics.c +++ /dev/null @@ -1,67 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - -int libcdsb_list_find_pointer(list_t* x, const void* v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_cstring(list_t* x, const char* v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_string (list_t* x, const str_t* v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, v, vtypeof( v), _, cb, r, cut); } -int libcdsb_list_find_array (list_t* x, const arr_t* v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, v, vtypeof( v), _, cb, r, cut); } -int libcdsb_list_find_list (list_t* x, const list_t* v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, v, vtypeof( v), _, cb, r, cut); } -int libcdsb_list_find_map (list_t* x, const map_t* v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, v, vtypeof( v), _, cb, r, cut); } -int libcdsb_list_find_vset (list_t* x, const set_t* v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, v, vtypeof( v), _, cb, r, cut); } -int libcdsb_list_find_dict (list_t* x, const dict_t* v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, v, vtypeof( v), _, cb, r, cut); } -int libcdsb_list_find_boolean(list_t* x, bool v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_int8 (list_t* x, s8_t v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_int16 (list_t* x, s16_t v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_int32 (list_t* x, s32_t v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_int64 (list_t* x, s64_t v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_uint8 (list_t* x, u8_t v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_uint16 (list_t* x, u16_t v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_uint32 (list_t* x, u32_t v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_uint64 (list_t* x, u64_t v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_float (list_t* x, fl_t v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_double (list_t* x, dbl_t v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } -int libcdsb_list_find_ldouble(list_t* x, ldbl_t v, void* _, list_access_callback cb, bool r, bool cut) { return libcdsb_list_find(x, &v, vtypeof(&v), _, cb, r, cut); } - -size_t libcdsb_list_count_pointer(const list_t* s, const void* v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_cstring(const list_t* s, const char* v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_string (const list_t* s, const str_t* v) { return libcdsb_list_count((void*)s, v, vtypeof( v)); } -size_t libcdsb_list_count_array (const list_t* s, const arr_t* v) { return libcdsb_list_count((void*)s, v, vtypeof( v)); } -size_t libcdsb_list_count_list (const list_t* s, const list_t* v) { return libcdsb_list_count((void*)s, v, vtypeof( v)); } -size_t libcdsb_list_count_map (const list_t* s, const map_t* v) { return libcdsb_list_count((void*)s, v, vtypeof( v)); } -size_t libcdsb_list_count_vset (const list_t* s, const set_t* v) { return libcdsb_list_count((void*)s, v, vtypeof( v)); } -size_t libcdsb_list_count_dict (const list_t* s, const dict_t* v) { return libcdsb_list_count((void*)s, v, vtypeof( v)); } -size_t libcdsb_list_count_boolean(const list_t* s, bool v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_int8 (const list_t* s, s8_t v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_int16 (const list_t* s, s16_t v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_int32 (const list_t* s, s32_t v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_int64 (const list_t* s, s64_t v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_uint8 (const list_t* s, u8_t v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_uint16 (const list_t* s, u16_t v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_uint32 (const list_t* s, u32_t v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_uint64 (const list_t* s, u64_t v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_float (const list_t* s, fl_t v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_double (const list_t* s, dbl_t v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } -size_t libcdsb_list_count_ldouble(const list_t* s, ldbl_t v) { return libcdsb_list_count((void*)s, &v, vtypeof(&v)); } - -bool libcdsb_list_update_pointer(list_t* x, ssize_t i, const void* v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_cstring(list_t* x, ssize_t i, const char* v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_string (list_t* x, ssize_t i, const str_t* v, int ins) { return libcdsb_list_update(x, i, v, vtypeof( v), ins); } -bool libcdsb_list_update_array (list_t* x, ssize_t i, const arr_t* v, int ins) { return libcdsb_list_update(x, i, v, vtypeof( v), ins); } -bool libcdsb_list_update_list (list_t* x, ssize_t i, const list_t* v, int ins) { return libcdsb_list_update(x, i, v, vtypeof( v), ins); } -bool libcdsb_list_update_map (list_t* x, ssize_t i, const map_t* v, int ins) { return libcdsb_list_update(x, i, v, vtypeof( v), ins); } -bool libcdsb_list_update_vset (list_t* x, ssize_t i, const set_t* v, int ins) { return libcdsb_list_update(x, i, v, vtypeof( v), ins); } -bool libcdsb_list_update_dict (list_t* x, ssize_t i, const dict_t* v, int ins) { return libcdsb_list_update(x, i, v, vtypeof( v), ins); } -bool libcdsb_list_update_boolean(list_t* x, ssize_t i, bool v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_int8 (list_t* x, ssize_t i, s8_t v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_int16 (list_t* x, ssize_t i, s16_t v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_int32 (list_t* x, ssize_t i, s32_t v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_int64 (list_t* x, ssize_t i, s64_t v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_uint8 (list_t* x, ssize_t i, u8_t v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_uint16 (list_t* x, ssize_t i, u16_t v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_uint32 (list_t* x, ssize_t i, u32_t v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_uint64 (list_t* x, ssize_t i, u64_t v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_float (list_t* x, ssize_t i, fl_t v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_double (list_t* x, ssize_t i, dbl_t v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } -bool libcdsb_list_update_ldouble(list_t* x, ssize_t i, ldbl_t v, int ins) { return libcdsb_list_update(x, i, &v, vtypeof(&v), ins); } diff --git a/src/list/include.h b/src/list/include.h index 402b952..463e872 100644 --- a/src/list/include.h +++ b/src/list/include.h @@ -1,7 +1,7 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "../../include/extra/list.h" +#include "../../include/list.h" #include "../__internal/vnode.h" #ifndef LIBCDSB_SRC_LIST_INCLUDE_H diff --git a/src/list/memory.c b/src/list/memory.c new file mode 100644 index 0000000..d3a1c53 --- /dev/null +++ b/src/list/memory.c @@ -0,0 +1,25 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +void list_init(list_t* x) { + memset(x, 0, sizeof(*x)); +} + + +void list_free(list_t* x) { + lnode_t* c; + lnode_t* next; + + c = x->first; + + while (!is_null(c)) { + next = c->next; + vnode_free(&c->node, c->type); + free(c); + c = next; + } + + memset(x, 0, sizeof(*x)); +} diff --git a/src/list/modify.c b/src/list/modify.c new file mode 100644 index 0000000..3dd9593 --- /dev/null +++ b/src/list/modify.c @@ -0,0 +1,107 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +bool libcdsb_list_insert(list_t* x, ssize_t i, const void* v, vtype t, int ins) { + + ldir_t dir; + lnode_t* c; + + if (i < 0) { + i = ~i; + dir = LD_PREV; + } else dir = LD_NEXT; + + c = ldir_dir((lnode_t*)x, dir); + + while (i && !is_null(c)) { + c = ldir_dir(c, dir); + --i; + } + + if (i && dir == LD_PREV) { + c = x->first; + } else if (i) return false; + + if (is_null(c)) { + x->first = x->last = c = calloc(sizeof(*c), 1); + } else if (ins) { + lnode_t *v = malloc(sizeof(*v)); + + dir = (ins < 0) ? LD_PREV : LD_NEXT; + + ldir_dir(v, dir) = ldir_dir(c, dir); + ldir_inv(v, dir) = c; + + c = v; + + if (!is_null(ldir_dir(c, dir))) { + ldir_inv(ldir_dir(c, dir), dir) = c; + } else ldir_inv((lnode_t*)x, dir) = c; + + ldir_dir(ldir_inv(c, dir), dir) = c; + + } else vnode_free(&c->node, c->type); + + c->node = vnode_create(v, t); + c->type = t; + + return true; +} + + +bool libcdsb_list_attach(list_t* x, ssize_t i, const void* v, vtype t, int ins) { + + ldir_t dir; + lnode_t* c; + + if (i < 0) { + i = ~i; + dir = LD_PREV; + } else dir = LD_NEXT; + + c = ldir_dir((lnode_t*)x, dir); + + while (i && !is_null(c)) { + c = ldir_dir(c, dir); + --i; + } + + if (i && dir == LD_PREV) { + c = x->first; + } else if (i) return false; + + if (is_null(c)) { + x->first = x->last = c = calloc(sizeof(*c), 1); + } else if (ins) { + lnode_t *v = malloc(sizeof(*v)); + + dir = (ins < 0) ? LD_PREV : LD_NEXT; + + ldir_dir(v, dir) = ldir_dir(c, dir); + ldir_inv(v, dir) = c; + + c = v; + + if (!is_null(ldir_dir(c, dir))) { + ldir_inv(ldir_dir(c, dir), dir) = c; + } else ldir_inv((lnode_t*)x, dir) = c; + + ldir_dir(ldir_inv(c, dir), dir) = c; + + } else vnode_free(&c->node, c->type); + + if (t < VTYPE_STRING) { + c->node = vnode_create(v, t); + } else if (sizeof(str_t) == sizeof(void*) && t == VTYPE_STRING) { + c->node = *(char**)v; + } else { + c->node = malloc(vtype_size(t)); + memcpy(c->node, v, vtype_size(t)); + } + + c->type = t; + + return true; +} diff --git a/tests/src/list/plug.h b/tests/src/list/plug.h index 21c7aa5..e27549d 100644 --- a/tests/src/list/plug.h +++ b/tests/src/list/plug.h @@ -1,7 +1,7 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "../../../include/extra/list.h" +#include "../../../include/list.h" #include "../../include/random.h" #include "../../include/test.h" From b789b133e2d38ee1ffc137ee76daa6b2fc6c0314 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Fri, 19 Aug 2022 17:19:22 +0300 Subject: [PATCH 03/18] Refactor set, add attaching functional --- examples/set.c | 10 ++- include/extra/set.h | 15 ---- include/set.h | 63 ++++--------- src/__internal/rbtree.h | 2 +- src/set/{extra.c => access.c} | 40 +-------- src/set/base.c | 161 ---------------------------------- src/set/comparison.c | 55 ++++++++++++ src/set/compute.c | 71 +++++++++++++++ src/set/generics.c | 47 ---------- src/set/memory.c | 39 ++++++++ src/set/modify.c | 88 +++++++++++++++++++ tests/src/set/plug.h | 2 +- 12 files changed, 278 insertions(+), 315 deletions(-) delete mode 100644 include/extra/set.h rename src/set/{extra.c => access.c} (67%) delete mode 100644 src/set/base.c create mode 100644 src/set/comparison.c create mode 100644 src/set/compute.c delete mode 100644 src/set/generics.c create mode 100644 src/set/memory.c create mode 100644 src/set/modify.c diff --git a/examples/set.c b/examples/set.c index 9b9b4d1..d05a978 100644 --- a/examples/set.c +++ b/examples/set.c @@ -3,7 +3,7 @@ #include #include -#include "../include/extra/set.h" +#include "../include/set.h" typedef vtype_set vset_t; @@ -22,6 +22,7 @@ int print_value(const void* value, vtype type, void* data) { int main(int argc, char** argv) { vset_t set; + int a, b; vset_init(&set, VTYPE_INT32); @@ -29,8 +30,11 @@ int main(int argc, char** argv) { vset_push(&set, i); } - vset_get(&set, 13, "Get value:", print_value); - vset_pop(&set, 18, "Pop value:", print_value); + a = 13; + b = 18; + + vset_get(&set, a, "Get value:", print_value); + vset_pop(&set, b, "Pop value:", print_value); vset_foreach(&set, "Foreach loop:", print_value); diff --git a/include/extra/set.h b/include/extra/set.h deleted file mode 100644 index 42be364..0000000 --- a/include/extra/set.h +++ /dev/null @@ -1,15 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "../set.h" - -#ifndef LIBCDSB_EXTRA_SET_H -#define LIBCDSB_EXTRA_SET_H - -#define vset_foreach(x, data, callback) libcdsb_vset_foreach(x, data, callback, 0) - -extern bool libcdsb_vset_insert (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); - -#endif /* LIBCDSB_EXTRA_SET_H */ diff --git a/include/set.h b/include/set.h index d679c98..f71d88b 100644 --- a/include/set.h +++ b/include/set.h @@ -7,61 +7,28 @@ #ifndef LIBCDSB_SET_H #define LIBCDSB_SET_H -/*#####################################################################################################################*/ - typedef int (*vset_access_callback)(const void* value, vtype type, void* data); +/*#####################################################################################################################*/ + extern void vset_init(vtype_set* x, vtype type) Nonnull__(1); -#define vset_pop(x, value, data, callback) _LIBCDSB_Generic (libcdsb_vset, find, value)(x, value, data, callback, 1) -#define vset_get(x, value, data, callback) _LIBCDSB_Generic (libcdsb_vset, find, value)(x, value, data, callback, 0) -#define vset_push(x, value) _LIBCDSB_Generic (libcdsb_vset, push, value)(x, value) -#define vset_remove(x, value) vset_pop(x, value, 0, 0) +/*#####################################################################################################################*/ -#define in_vset(x, value) (vset_get(&x, value, 0, 0) == 0) +#define vset_pop(x, value, data, callback) libcdsb_vset_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 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_remove(x, value) vset_pop (x, value, 0, 0) + +#define in_vset(x, value) (vset_get(x, value, 0, 0) == 0) /*#####################################################################################################################*/ -extern bool libcdsb_vset_push_pointer(vtype_set* x, const void* value) Nonnull__(1); -extern bool libcdsb_vset_push_cstring(vtype_set* x, const char* value) Nonnull__(1,2); -extern bool libcdsb_vset_push_string (vtype_set* x, const vtype_string* value) Nonnull__(1,2); -extern bool libcdsb_vset_push_array (vtype_set* x, const vtype_array* value) Nonnull__(1,2); -extern bool libcdsb_vset_push_list (vtype_set* x, const vtype_list* value) Nonnull__(1,2); -extern bool libcdsb_vset_push_map (vtype_set* x, const vtype_map* value) Nonnull__(1,2); -extern bool libcdsb_vset_push_vset (vtype_set* x, const vtype_set* value) Nonnull__(1,2); -extern bool libcdsb_vset_push_dict (vtype_set* x, const vtype_dict* value) Nonnull__(1,2); -extern bool libcdsb_vset_push_boolean(vtype_set* x, vtype_bool value) Nonnull__(1); -extern bool libcdsb_vset_push_uint8 (vtype_set* x, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_vset_push_uint16 (vtype_set* x, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_vset_push_uint32 (vtype_set* x, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_vset_push_uint64 (vtype_set* x, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_vset_push_int8 (vtype_set* x, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_vset_push_int16 (vtype_set* x, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_vset_push_int32 (vtype_set* x, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_vset_push_int64 (vtype_set* x, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_vset_push_float (vtype_set* x, vtype_float value) Nonnull__(1); -extern bool libcdsb_vset_push_double (vtype_set* x, vtype_double value) Nonnull__(1); -extern bool libcdsb_vset_push_ldouble(vtype_set* x, vtype_ldouble value) Nonnull__(1); - -extern int libcdsb_vset_find_pointer(vtype_set* x, const void* value, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_find_cstring(vtype_set* x, const char* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_vset_find_string (vtype_set* x, const vtype_string* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_vset_find_array (vtype_set* x, const vtype_array* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_vset_find_list (vtype_set* x, const vtype_list* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_vset_find_map (vtype_set* x, const vtype_map* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_vset_find_vset (vtype_set* x, const vtype_set* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_vset_find_dict (vtype_set* x, const vtype_dict* value, void* data, vset_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_vset_find_boolean(vtype_set* x, vtype_bool value, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_find_uint8 (vtype_set* x, vtype_uint8 value, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_find_uint16 (vtype_set* x, vtype_uint16 value, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_find_uint32 (vtype_set* x, vtype_uint32 value, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_find_uint64 (vtype_set* x, vtype_uint64 value, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_find_int8 (vtype_set* x, vtype_int8 value, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_find_int16 (vtype_set* x, vtype_int16 value, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_find_int32 (vtype_set* x, vtype_int32 value, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_find_int64 (vtype_set* x, vtype_int64 value, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_find_float (vtype_set* x, vtype_float value, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_find_double (vtype_set* x, vtype_double value, void* data, vset_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_vset_find_ldouble(vtype_set* x, vtype_ldouble value, void* data, vset_access_callback, bool cut) 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); #endif /* LIBCDSB_SET_H */ diff --git a/src/__internal/rbtree.h b/src/__internal/rbtree.h index 01a5c10..93ecb97 100644 --- a/src/__internal/rbtree.h +++ b/src/__internal/rbtree.h @@ -17,7 +17,7 @@ typedef struct libcdsb_rbtree_node { extern rbnode_t LIBCDSB_RBTREE_NODE_EMPTY[1]; -extern void* libcdsb_rbtree_node_create(void* value, rbnode_t* parent, int colored, int size) Nonnull__(1,2); +extern void* libcdsb_rbtree_node_create(void* value, rbnode_t* parent, int colored, int size) Nonnull__( 2); extern void libcdsb_rbtree_node_fixup (rbnode_t** root, rbnode_t* node) Nonnull__(1,2); extern rbnode_t* libcdsb_rbtree_node_delete(rbnode_t** root, rbnode_t* node) Nonnull__(1,2); diff --git a/src/set/extra.c b/src/set/access.c similarity index 67% rename from src/set/extra.c rename to src/set/access.c index b18926b..2f022c1 100644 --- a/src/set/extra.c +++ b/src/set/access.c @@ -1,47 +1,9 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "../../include/extra/set.h" +#include "../../include/set.h" #include "../__internal/rbtree.h" -bool libcdsb_vset_insert(set_t* x, const void* v, vtype t) { - int cmp; - rbnode_t* n; - rbnode_t* p; - vnode_t vn; - - n = x->root; - vn = vnode_tcreate(x->type, v, t); - t = x->type; - v = vnode_peek(&vn, t); - - if (!rbnode_is_empty(n)) { - do { - p = n; - cmp = vtype_compare(v, t, vnode_peek(&n->value, t), t); - - if (cmp == 0) { - vnode_free(&vn, t); - return false; - } - - n = (cmp < 0) ? n->left : n->right; - } while (!rbnode_is_empty(n)); - - n = rbnode_create(vn, p, 1); - - if (cmp < 0) p->left = n; - else p->right = n; - - if (!rbnode_is_root(p)) - rbnode_fixup(&x->root, n); - - } else n = x->root = rbnode_create(vn, rbnode_empty, 0); - - return true; -} - - int libcdsb_vset_find(vtype_set* x, const void* v, vtype t, void* _, vset_access_callback callback, bool cut) { rbnode_t* c; void *val; diff --git a/src/set/base.c b/src/set/base.c deleted file mode 100644 index 7a85537..0000000 --- a/src/set/base.c +++ /dev/null @@ -1,161 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "../../include/set.h" -#include "../__internal/rbtree.h" - -/*#####################################################################################################################*/ - -static inline int rbnode_compare(const rbnode_t* s0, const rbnode_t* s1, vtype t) { - return vnode_compare(s0->value, t, s1->value, t); -} - -static inline hash_t rbnode_hash(const rbnode_t* s, vtype t) { - return vnode_hash(&s->value, t); -} - -/*#####################################################################################################################*/ - -hash_t vset_hash(const set_t* s) { - - stack_t z; - rbnode_t *c0, *c1; - hash_t hash, v; - - if (rbnode_is_empty(s->root)) - return 0; - - stack_init(&z); - stack_push(&z, s->root->left); - - hash = 1; - - if (!rbnode_is_empty(c0 = stack_pop(&z))) { - do { - ++hash; - if (!rbnode_is_empty(c0->right)) stack_push(&z, c0->right); - if (!rbnode_is_empty(c0->left)) stack_push(&z, c1 = c0->left); - } while (!is_null(c0 = stack_pop(&z))); - } - - v = rbnode_hash(c1, s->type); - stack_push(&z, s->root->right); - - if (!rbnode_is_empty(c0 = stack_pop(&z))) { - do { - ++hash; - if (!rbnode_is_empty(c0->right)) stack_push(&z, c1 = c0->right); - if (!rbnode_is_empty(c0->left)) stack_push(&z, c0->left); - } while (!is_null(c0 = stack_pop(&z))); - } - - v += rbnode_hash(c1, s->type); - - return (hash ^ v) + VTYPE_SET; -} - -/*#####################################################################################################################*/ - -void vset_init(set_t* x, vtype t) { - x->root = rbnode_empty; - x->type = t; -} - - -void vset_free(set_t* x) { - rbnode_t *t, *c; - - c = x->root; - - while (!rbnode_is_empty(x->root)) { - if (!rbnode_is_empty(c->left)) { - c = c->left; - } else if (!rbnode_is_empty(c->right)) { - c = c->right; - } else if (!rbnode_is_root(c)) { - vnode_free(&c->value, x->type); - - t = c; - c = c->parent; - - if (t == c->left) c->left = rbnode_empty; - else c->right = rbnode_empty; - - free(t); - } else { - vnode_free(&c->value, x->type); - x->root = rbnode_empty; - } - } - - x->type = 0; -} - -/*#####################################################################################################################*/ - -size_t vset_size(const set_t* x) { - stack_t z; - size_t n; - rbnode_t* c; - - stack_init(&z); - stack_push(&z, x->root); - - n = 0; - - if (!rbnode_is_empty(x->root)) { - while ((c = stack_pop(&z))) { - ++n; - if (!rbnode_is_empty(c->right)) stack_push(&z, c->right); - if (!rbnode_is_empty(c->left)) stack_push(&z, c->left); - } - } - - return n; -} - -/*#####################################################################################################################*/ - -int vset_compare(const set_t* s0, const set_t* s1) { - stack_t z; - rbnode_t *c0, *c1; - int cmp; - - if (s0 == s1 || s0->root == s1->root) - return 0; - if (s0->type != s1->type) - return s0->type - s1->type; - - stack_init(&z); - stack_push_many(&z, 2, (void*)s1, (void*)s0); - - cmp = 0; - - do { - c0 = stack_pop(&z); - c1 = stack_pop(&z); - - if (rbnode_is_empty(c0) || rbnode_is_empty(c1)) { - if (c0 != c1) { - stack_flush(&z); - return rbnode_is_empty(c0) ? -1 : 1; - } - } else if ((cmp = rbnode_compare(c0, c1, s0->type))) { - if (c0->left == c1->right) { // == rbnode_empty - cmp = rbnode_compare(c0->right, c1, s0->type); - if (!cmp) cmp = rbnode_compare(c0, c1->left, s0->type); - } else if (c0->right == c1->left) { // == rbnode_empty - cmp = rbnode_compare(c0, c1->right, s0->type); - if (!cmp) cmp = rbnode_compare(c0->left, c1, s0->type); - } - - if (cmp) { - stack_flush(&z); - return cmp; - } - } else stack_push_many(&z, 4, c1->right, c0->right, c1->left, c0->left); - - } while (!is_null(z.value)); - - return 0; -} diff --git a/src/set/comparison.c b/src/set/comparison.c new file mode 100644 index 0000000..4a3dabc --- /dev/null +++ b/src/set/comparison.c @@ -0,0 +1,55 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "../../include/set.h" +#include "../__internal/rbtree.h" + +static inline int rbnode_compare(const rbnode_t* s0, const rbnode_t* s1, vtype t) { + return vnode_compare(s0->value, t, s1->value, t); +} + +/*#####################################################################################################################*/ + +int vset_compare(const set_t* s0, const set_t* s1) { + stack_t z; + rbnode_t *c0, *c1; + int cmp; + + if (s0 == s1 || s0->root == s1->root) + return 0; + if (s0->type != s1->type) + return s0->type - s1->type; + + stack_init(&z); + stack_push_many(&z, 2, (void*)s1, (void*)s0); + + cmp = 0; + + do { + c0 = stack_pop(&z); + c1 = stack_pop(&z); + + if (rbnode_is_empty(c0) || rbnode_is_empty(c1)) { + if (c0 != c1) { + stack_flush(&z); + return rbnode_is_empty(c0) ? -1 : 1; + } + } else if ((cmp = rbnode_compare(c0, c1, s0->type))) { + if (c0->left == c1->right) { // == rbnode_empty + cmp = rbnode_compare(c0->right, c1, s0->type); + if (!cmp) cmp = rbnode_compare(c0, c1->left, s0->type); + } else if (c0->right == c1->left) { // == rbnode_empty + cmp = rbnode_compare(c0, c1->right, s0->type); + if (!cmp) cmp = rbnode_compare(c0->left, c1, s0->type); + } + + if (cmp) { + stack_flush(&z); + return cmp; + } + } else stack_push_many(&z, 4, c1->right, c0->right, c1->left, c0->left); + + } while (!is_null(z.value)); + + return 0; +} diff --git a/src/set/compute.c b/src/set/compute.c new file mode 100644 index 0000000..3f3bb78 --- /dev/null +++ b/src/set/compute.c @@ -0,0 +1,71 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "../../include/set.h" +#include "../__internal/rbtree.h" + +static inline hash_t rbnode_hash(const rbnode_t* s, vtype t) { + return vnode_hash(&s->value, t); +} + +/*#####################################################################################################################*/ + +size_t vset_size(const set_t* x) { + stack_t z; + size_t n; + rbnode_t* c; + + stack_init(&z); + stack_push(&z, x->root); + + n = 0; + + if (!rbnode_is_empty(x->root)) { + while ((c = stack_pop(&z))) { + ++n; + if (!rbnode_is_empty(c->right)) stack_push(&z, c->right); + if (!rbnode_is_empty(c->left)) stack_push(&z, c->left); + } + } + + return n; +} + + +hash_t vset_hash(const set_t* s) { + + stack_t z; + rbnode_t *c0, *c1; + hash_t hash, v; + + if (rbnode_is_empty(s->root)) + return 0; + + stack_init(&z); + stack_push(&z, s->root->left); + + hash = 1; + + if (!rbnode_is_empty(c0 = stack_pop(&z))) { + do { + ++hash; + if (!rbnode_is_empty(c0->right)) stack_push(&z, c0->right); + if (!rbnode_is_empty(c0->left)) stack_push(&z, c1 = c0->left); + } while (!is_null(c0 = stack_pop(&z))); + } + + v = rbnode_hash(c1, s->type); + stack_push(&z, s->root->right); + + if (!rbnode_is_empty(c0 = stack_pop(&z))) { + do { + ++hash; + if (!rbnode_is_empty(c0->right)) stack_push(&z, c1 = c0->right); + if (!rbnode_is_empty(c0->left)) stack_push(&z, c0->left); + } while (!is_null(c0 = stack_pop(&z))); + } + + v += rbnode_hash(c1, s->type); + + return (hash ^ v) + VTYPE_SET; +} diff --git a/src/set/generics.c b/src/set/generics.c deleted file mode 100644 index bd88199..0000000 --- a/src/set/generics.c +++ /dev/null @@ -1,47 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "../../include/extra/set.h" -#include "../__internal/include.h" - -int libcdsb_vset_find_pointer(set_t* x, const void* v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_cstring(set_t* x, const char* v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_string (set_t* x, const str_t* v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, v, vtypeof( v), _, cb, cut); } -int libcdsb_vset_find_array (set_t* x, const arr_t* v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, v, vtypeof( v), _, cb, cut); } -int libcdsb_vset_find_list (set_t* x, const list_t* v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, v, vtypeof( v), _, cb, cut); } -int libcdsb_vset_find_map (set_t* x, const map_t* v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, v, vtypeof( v), _, cb, cut); } -int libcdsb_vset_find_vset (set_t* x, const set_t* v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, v, vtypeof( v), _, cb, cut); } -int libcdsb_vset_find_dict (set_t* x, const dict_t* v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, v, vtypeof( v), _, cb, cut); } -int libcdsb_vset_find_boolean(set_t* x, bool v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_int8 (set_t* x, s8_t v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_int16 (set_t* x, s16_t v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_int32 (set_t* x, s32_t v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_int64 (set_t* x, s64_t v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_uint8 (set_t* x, u8_t v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_uint16 (set_t* x, u16_t v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_uint32 (set_t* x, u32_t v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_uint64 (set_t* x, u64_t v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_float (set_t* x, fl_t v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_double (set_t* x, dbl_t v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } -int libcdsb_vset_find_ldouble(set_t* x, ldbl_t v, void* _, vset_access_callback cb, bool cut) { return libcdsb_vset_find(x, &v, vtypeof(&v), _, cb, cut); } - -bool libcdsb_vset_push_pointer(set_t* x, const void* v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_cstring(set_t* x, const char* v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_string (set_t* x, const str_t* v) { return libcdsb_vset_insert(x, v, vtypeof( v)); } -bool libcdsb_vset_push_array (set_t* x, const arr_t* v) { return libcdsb_vset_insert(x, v, vtypeof( v)); } -bool libcdsb_vset_push_list (set_t* x, const list_t* v) { return libcdsb_vset_insert(x, v, vtypeof( v)); } -bool libcdsb_vset_push_map (set_t* x, const map_t* v) { return libcdsb_vset_insert(x, v, vtypeof( v)); } -bool libcdsb_vset_push_vset (set_t* x, const set_t* v) { return libcdsb_vset_insert(x, v, vtypeof( v)); } -bool libcdsb_vset_push_dict (set_t* x, const dict_t* v) { return libcdsb_vset_insert(x, v, vtypeof( v)); } -bool libcdsb_vset_push_boolean(set_t* x, bool v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_int8 (set_t* x, s8_t v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_int16 (set_t* x, s16_t v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_int32 (set_t* x, s32_t v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_int64 (set_t* x, s64_t v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_uint8 (set_t* x, u8_t v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_uint16 (set_t* x, u16_t v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_uint32 (set_t* x, u32_t v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_uint64 (set_t* x, u64_t v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_float (set_t* x, fl_t v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_double (set_t* x, dbl_t v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } -bool libcdsb_vset_push_ldouble(set_t* x, ldbl_t v) { return libcdsb_vset_insert(x, &v, vtypeof(&v)); } diff --git a/src/set/memory.c b/src/set/memory.c new file mode 100644 index 0000000..e0e3c2b --- /dev/null +++ b/src/set/memory.c @@ -0,0 +1,39 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "../../include/set.h" +#include "../__internal/rbtree.h" + +void vset_init(set_t* x, vtype t) { + x->root = rbnode_empty; + x->type = t; +} + +void vset_free(set_t* x) { + rbnode_t *t, *c; + + c = x->root; + + while (!rbnode_is_empty(x->root)) { + if (!rbnode_is_empty(c->left)) { + c = c->left; + } else if (!rbnode_is_empty(c->right)) { + c = c->right; + } else if (!rbnode_is_root(c)) { + vnode_free(&c->value, x->type); + + t = c; + c = c->parent; + + if (t == c->left) c->left = rbnode_empty; + else c->right = rbnode_empty; + + free(t); + } else { + vnode_free(&c->value, x->type); + x->root = rbnode_empty; + } + } + + x->type = 0; +} diff --git a/src/set/modify.c b/src/set/modify.c new file mode 100644 index 0000000..dd5e4c2 --- /dev/null +++ b/src/set/modify.c @@ -0,0 +1,88 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "../../include/set.h" +#include "../__internal/rbtree.h" +#include "../__internal/assert.h" + +bool libcdsb_vset_insert(set_t* x, const void* v, vtype t) { + int cmp; + rbnode_t* n; + rbnode_t* p; + vnode_t vn; + + n = x->root; + vn = vnode_tcreate(x->type, v, t); + t = x->type; + v = vnode_peek(&vn, t); + + if (!rbnode_is_empty(n)) { + do { + p = n; + cmp = vtype_compare(v, t, vnode_peek(&n->value, t), t); + + if (cmp == 0) { + vnode_free(&vn, t); + return false; + } + + n = (cmp < 0) ? n->left : n->right; + } while (!rbnode_is_empty(n)); + + n = rbnode_create(vn, p, 1); + + if (cmp < 0) p->left = n; + else p->right = n; + + if (!rbnode_is_root(p)) + rbnode_fixup(&x->root, n); + + } else n = x->root = rbnode_create(vn, rbnode_empty, 0); + + return true; +} + + +bool libcdsb_vset_attach(set_t* x, const void* v, vtype t) { + int cmp; + rbnode_t* n; + rbnode_t* p; + + n = x->root; + t = x->type; + + if (!rbnode_is_empty(n)) { + do { + p = n; + cmp = vtype_compare(v, t, vnode_peek(&n->value, t), t); + + if (cmp == 0) return false; + + n = (cmp < 0) ? n->left : n->right; + } while (!rbnode_is_empty(n)); + + n = rbnode_create(nullptr, p, 1); + + if (cmp < 0) p->left = n; + else p->right = n; + + if (!rbnode_is_root(p)) + rbnode_fixup(&x->root, n); + + } else n = x->root = rbnode_create(nullptr, rbnode_empty, 0); + + if (t < VTYPE_STRING) { + n->value = vnode_tcreate(x->type, v, t); + } else { + type_assert(x->type, t); + + if (sizeof(str_t) == sizeof(void*) && t == VTYPE_STRING) { + n->value = *(char**)v; + } else { + n->value = malloc(vtype_size(t)); + memcpy(n->value, v, vtype_size(t)); + } + } + + return true; +} diff --git a/tests/src/set/plug.h b/tests/src/set/plug.h index 756e649..5e430b8 100644 --- a/tests/src/set/plug.h +++ b/tests/src/set/plug.h @@ -1,7 +1,7 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "../../../include/extra/set.h" +#include "../../../include/set.h" #include "../../../src/__internal/rbtree.h" #include "../../include/random.h" From 36f03d3d232743d68231362ce6874d00ed721dd2 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Fri, 19 Aug 2022 18:46:51 +0300 Subject: [PATCH 04/18] Refactor map, add attaching functional --- examples/map.c | 16 +- include/extra/map.h | 42 ---- include/map.h | 462 ++-------------------------------- include/vtype.h | 115 +++------ src/__internal/vnode.h | 27 ++ src/map/{extra.c => access.c} | 47 ---- src/map/base.c | 163 ------------ src/map/comparison.c | 56 +++++ src/map/compute.c | 70 ++++++ src/map/copy.c | 2 - src/map/generics.c | 445 -------------------------------- src/map/include.h | 15 +- src/map/memory.c | 41 +++ src/map/modify.c | 88 +++++++ tests/src/global/plug.h | 6 +- 15 files changed, 353 insertions(+), 1242 deletions(-) delete mode 100644 include/extra/map.h rename src/map/{extra.c => access.c} (65%) delete mode 100644 src/map/base.c create mode 100644 src/map/comparison.c create mode 100644 src/map/compute.c delete mode 100644 src/map/generics.c create mode 100644 src/map/memory.c create mode 100644 src/map/modify.c diff --git a/examples/map.c b/examples/map.c index 115dc2e..30c8a2a 100644 --- a/examples/map.c +++ b/examples/map.c @@ -4,7 +4,7 @@ #include #include #include -#include "../include/extra/map.h" +#include "../include/map.h" typedef vtype_map map_t; @@ -34,20 +34,24 @@ int main(int argc, char** argv) { map_t map; vtype_float fl = 0.0; + int a, b; map_init(&map, VTYPE_INT32); - for (size_t i = 0; i < 28; ++i) { + for (vtype_int32 i = 0; i < 28; ++i) { if (i%2) { - map_update(&map, i, (vtype_int32)i); + map_update(&map, i, i); } else { - map_update(&map, i, (vtype_float)fl); + map_update(&map, i, fl); fl += 0.05; } } - map_get(&map, 13, "Get value:", print_value); - map_pop(&map, 18, "Pop value:", print_value); + a = 13; + b = 18; + + map_get(&map, a, "Get value:", print_value); + map_pop(&map, b, "Pop value:", print_value); map_foreach(&map, "Foreach loop:", print_value); diff --git a/include/extra/map.h b/include/extra/map.h deleted file mode 100644 index a8f2f78..0000000 --- a/include/extra/map.h +++ /dev/null @@ -1,42 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "../map.h" - -#ifndef LIBCDSB_EXTRA_MAP_H -#define LIBCDSB_EXTRA_MAP_H - -#define map_foreach(x, data, callback) libcdsb_map_foreach(x, data, callback, 0) - -extern bool libcdsb_map_update (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); - -#endif /* LIBCDSB_EXTRA_MAP_H */ - - -#if defined(LIBCDSB_SET_H) && !defined(LIBCDSB_EXTRA_MAP_H_EXT) -#define LIBCDSB_EXTRA_MAP_H_EXT - -#define map_copy_keys(s) _Generic((s),\ - const vtype_map*: vset_copy, vtype_map*: vset_copy,\ - const void*: vset_copy, void*: vset_copy\ -)((set_t*)(s)) - -#define map_duplicate_keys(s) _Generic((s),\ - const vtype_map*: vset_duplicate, vtype_map*: vset_duplicate,\ - const void*: vset_duplicate, void*: vset_duplicate\ -)((set_t*)(s)) - -#define map_copy_init_keys(x, s) _Generic((x),\ - vtype_set*: _Generic((s),\ - const vtype_map*: vset_copy_init, vtype_map*: vset_copy_init,\ - const void*: vset_copy_init, void*: vset_copy_init\ - ),\ - void*: _Generic((s),\ - const vtype_map*: vset_copy_init, vtype_map*: vset_copy_init,\ - const void*: vset_copy_init, void*: vset_copy_init\ - )\ -)((x), (set_t*)(s)) - -#endif /* LIBCDSB_EXTRA_MAP_H_EXT */ diff --git a/include/map.h b/include/map.h index 85755bf..4c499c9 100644 --- a/include/map.h +++ b/include/map.h @@ -7,460 +7,28 @@ #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_Generic (libcdsb_map, find, key)(x, key, data, callback, 1) -#define map_get(x, key, data, callback) _LIBCDSB_Generic (libcdsb_map, find, key)(x, key, data, callback, 0) -#define map_update(x, key, value) _LIBCDSB_Generic2(libcdsb_map, update, key, value)(x, key, value) -#define map_remove(x, key) map_pop(x, key, 0, 0) +/*#####################################################################################################################*/ -#define in_map(x, key) (map_get(&x, key, 0, 0) == 0) +#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, 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 int libcdsb_map_find_pointer(vtype_map* x, const void* key, void* data, map_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_map_find_cstring(vtype_map* x, const char* key, void* data, map_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_map_find_string (vtype_map* x, const vtype_string* key, void* data, map_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_map_find_array (vtype_map* x, const vtype_array* key, void* data, map_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_map_find_list (vtype_map* x, const vtype_list* key, void* data, map_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_map_find_map (vtype_map* x, const vtype_map* key, void* data, map_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_map_find_vset (vtype_map* x, const vtype_set* key, void* data, map_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_map_find_dict (vtype_map* x, const vtype_dict* key, void* data, map_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_map_find_boolean(vtype_map* x, vtype_bool key, void* data, map_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_map_find_int8 (vtype_map* x, vtype_int8 key, void* data, map_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_map_find_int16 (vtype_map* x, vtype_int16 key, void* data, map_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_map_find_int32 (vtype_map* x, vtype_int32 key, void* data, map_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_map_find_int64 (vtype_map* x, vtype_int64 key, void* data, map_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_map_find_uint8 (vtype_map* x, vtype_uint8 key, void* data, map_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_map_find_uint16 (vtype_map* x, vtype_uint16 key, void* data, map_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_map_find_uint32 (vtype_map* x, vtype_uint32 key, void* data, map_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_map_find_uint64 (vtype_map* x, vtype_uint64 key, void* data, map_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_map_find_float (vtype_map* x, vtype_float key, void* data, map_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_map_find_double (vtype_map* x, vtype_double key, void* data, map_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_map_find_ldouble(vtype_map* x, vtype_ldouble key, void* data, map_access_callback, bool cut) Nonnull__(1); - -extern bool libcdsb_map_update_pointer_pointer(vtype_map* x, const void* key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_pointer_cstring(vtype_map* x, const void* key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_pointer_string (vtype_map* x, const void* key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_pointer_array (vtype_map* x, const void* key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_pointer_list (vtype_map* x, const void* key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_pointer_map (vtype_map* x, const void* key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_pointer_vset (vtype_map* x, const void* key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_pointer_dict (vtype_map* x, const void* key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_pointer_boolean(vtype_map* x, const void* key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_pointer_int8 (vtype_map* x, const void* key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_pointer_int16 (vtype_map* x, const void* key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_pointer_int32 (vtype_map* x, const void* key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_pointer_int64 (vtype_map* x, const void* key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_pointer_uint8 (vtype_map* x, const void* key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_pointer_uint16 (vtype_map* x, const void* key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_pointer_uint32 (vtype_map* x, const void* key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_pointer_uint64 (vtype_map* x, const void* key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_pointer_float (vtype_map* x, const void* key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_pointer_double (vtype_map* x, const void* key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_pointer_ldouble(vtype_map* x, const void* key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_map_update_cstring_pointer(vtype_map* x, const char* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_map_update_cstring_cstring(vtype_map* x, const char* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_cstring_string (vtype_map* x, const char* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_cstring_array (vtype_map* x, const char* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_cstring_list (vtype_map* x, const char* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_cstring_map (vtype_map* x, const char* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_cstring_vset (vtype_map* x, const char* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_cstring_dict (vtype_map* x, const char* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_cstring_boolean(vtype_map* x, const char* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_map_update_cstring_int8 (vtype_map* x, const char* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_cstring_int16 (vtype_map* x, const char* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_cstring_int32 (vtype_map* x, const char* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_cstring_int64 (vtype_map* x, const char* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_cstring_uint8 (vtype_map* x, const char* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_cstring_uint16 (vtype_map* x, const char* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_cstring_uint32 (vtype_map* x, const char* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_cstring_uint64 (vtype_map* x, const char* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_cstring_float (vtype_map* x, const char* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_map_update_cstring_double (vtype_map* x, const char* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_map_update_cstring_ldouble(vtype_map* x, const char* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_map_update_string_pointer(vtype_map* x, const vtype_string* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_map_update_string_cstring(vtype_map* x, const vtype_string* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_string_string (vtype_map* x, const vtype_string* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_string_array (vtype_map* x, const vtype_string* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_string_list (vtype_map* x, const vtype_string* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_string_map (vtype_map* x, const vtype_string* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_string_vset (vtype_map* x, const vtype_string* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_string_dict (vtype_map* x, const vtype_string* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_string_boolean(vtype_map* x, const vtype_string* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_map_update_string_int8 (vtype_map* x, const vtype_string* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_string_int16 (vtype_map* x, const vtype_string* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_string_int32 (vtype_map* x, const vtype_string* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_string_int64 (vtype_map* x, const vtype_string* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_string_uint8 (vtype_map* x, const vtype_string* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_string_uint16 (vtype_map* x, const vtype_string* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_string_uint32 (vtype_map* x, const vtype_string* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_string_uint64 (vtype_map* x, const vtype_string* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_string_float (vtype_map* x, const vtype_string* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_map_update_string_double (vtype_map* x, const vtype_string* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_map_update_string_ldouble(vtype_map* x, const vtype_string* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_map_update_array_pointer(vtype_map* x, const vtype_array* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_map_update_array_cstring(vtype_map* x, const vtype_array* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_array_string (vtype_map* x, const vtype_array* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_array_array (vtype_map* x, const vtype_array* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_array_list (vtype_map* x, const vtype_array* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_array_map (vtype_map* x, const vtype_array* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_array_vset (vtype_map* x, const vtype_array* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_array_dict (vtype_map* x, const vtype_array* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_array_boolean(vtype_map* x, const vtype_array* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_map_update_array_int8 (vtype_map* x, const vtype_array* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_array_int16 (vtype_map* x, const vtype_array* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_array_int32 (vtype_map* x, const vtype_array* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_array_int64 (vtype_map* x, const vtype_array* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_array_uint8 (vtype_map* x, const vtype_array* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_array_uint16 (vtype_map* x, const vtype_array* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_array_uint32 (vtype_map* x, const vtype_array* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_array_uint64 (vtype_map* x, const vtype_array* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_array_float (vtype_map* x, const vtype_array* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_map_update_array_double (vtype_map* x, const vtype_array* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_map_update_array_ldouble(vtype_map* x, const vtype_array* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_map_update_list_pointer(vtype_map* x, const vtype_list* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_map_update_list_cstring(vtype_map* x, const vtype_list* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_list_string (vtype_map* x, const vtype_list* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_list_array (vtype_map* x, const vtype_list* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_list_list (vtype_map* x, const vtype_list* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_list_map (vtype_map* x, const vtype_list* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_list_vset (vtype_map* x, const vtype_list* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_list_dict (vtype_map* x, const vtype_list* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_list_boolean(vtype_map* x, const vtype_list* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_map_update_list_int8 (vtype_map* x, const vtype_list* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_list_int16 (vtype_map* x, const vtype_list* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_list_int32 (vtype_map* x, const vtype_list* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_list_int64 (vtype_map* x, const vtype_list* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_list_uint8 (vtype_map* x, const vtype_list* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_list_uint16 (vtype_map* x, const vtype_list* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_list_uint32 (vtype_map* x, const vtype_list* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_list_uint64 (vtype_map* x, const vtype_list* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_list_float (vtype_map* x, const vtype_list* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_map_update_list_double (vtype_map* x, const vtype_list* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_map_update_list_ldouble(vtype_map* x, const vtype_list* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_map_update_map_pointer(vtype_map* x, const vtype_map* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_map_update_map_cstring(vtype_map* x, const vtype_map* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_map_string (vtype_map* x, const vtype_map* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_map_array (vtype_map* x, const vtype_map* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_map_list (vtype_map* x, const vtype_map* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_map_map (vtype_map* x, const vtype_map* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_map_vset (vtype_map* x, const vtype_map* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_map_dict (vtype_map* x, const vtype_map* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_map_boolean(vtype_map* x, const vtype_map* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_map_update_map_int8 (vtype_map* x, const vtype_map* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_map_int16 (vtype_map* x, const vtype_map* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_map_int32 (vtype_map* x, const vtype_map* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_map_int64 (vtype_map* x, const vtype_map* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_map_uint8 (vtype_map* x, const vtype_map* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_map_uint16 (vtype_map* x, const vtype_map* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_map_uint32 (vtype_map* x, const vtype_map* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_map_uint64 (vtype_map* x, const vtype_map* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_map_float (vtype_map* x, const vtype_map* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_map_update_map_double (vtype_map* x, const vtype_map* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_map_update_map_ldouble(vtype_map* x, const vtype_map* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_map_update_vset_pointer(vtype_map* x, const vtype_set* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_map_update_vset_cstring(vtype_map* x, const vtype_set* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_vset_string (vtype_map* x, const vtype_set* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_vset_array (vtype_map* x, const vtype_set* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_vset_list (vtype_map* x, const vtype_set* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_vset_map (vtype_map* x, const vtype_set* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_vset_vset (vtype_map* x, const vtype_set* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_vset_dict (vtype_map* x, const vtype_set* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_vset_boolean(vtype_map* x, const vtype_set* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_map_update_vset_int8 (vtype_map* x, const vtype_set* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_vset_int16 (vtype_map* x, const vtype_set* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_vset_int32 (vtype_map* x, const vtype_set* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_vset_int64 (vtype_map* x, const vtype_set* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_vset_uint8 (vtype_map* x, const vtype_set* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_vset_uint16 (vtype_map* x, const vtype_set* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_vset_uint32 (vtype_map* x, const vtype_set* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_vset_uint64 (vtype_map* x, const vtype_set* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_vset_float (vtype_map* x, const vtype_set* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_map_update_vset_double (vtype_map* x, const vtype_set* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_map_update_vset_ldouble(vtype_map* x, const vtype_set* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_map_update_dict_pointer(vtype_map* x, const vtype_dict* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_map_update_dict_cstring(vtype_map* x, const vtype_dict* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_dict_string (vtype_map* x, const vtype_dict* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_dict_array (vtype_map* x, const vtype_dict* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_dict_list (vtype_map* x, const vtype_dict* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_dict_map (vtype_map* x, const vtype_dict* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_dict_vset (vtype_map* x, const vtype_dict* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_dict_dict (vtype_map* x, const vtype_dict* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_map_update_dict_boolean(vtype_map* x, const vtype_dict* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_map_update_dict_int8 (vtype_map* x, const vtype_dict* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_dict_int16 (vtype_map* x, const vtype_dict* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_dict_int32 (vtype_map* x, const vtype_dict* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_dict_int64 (vtype_map* x, const vtype_dict* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_dict_uint8 (vtype_map* x, const vtype_dict* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_map_update_dict_uint16 (vtype_map* x, const vtype_dict* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_map_update_dict_uint32 (vtype_map* x, const vtype_dict* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_map_update_dict_uint64 (vtype_map* x, const vtype_dict* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_map_update_dict_float (vtype_map* x, const vtype_dict* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_map_update_dict_double (vtype_map* x, const vtype_dict* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_map_update_dict_ldouble(vtype_map* x, const vtype_dict* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_map_update_boolean_pointer(vtype_map* x, vtype_bool key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_boolean_cstring(vtype_map* x, vtype_bool key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_boolean_string (vtype_map* x, vtype_bool key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_boolean_array (vtype_map* x, vtype_bool key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_boolean_list (vtype_map* x, vtype_bool key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_boolean_map (vtype_map* x, vtype_bool key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_boolean_vset (vtype_map* x, vtype_bool key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_boolean_dict (vtype_map* x, vtype_bool key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_boolean_boolean(vtype_map* x, vtype_bool key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_boolean_int8 (vtype_map* x, vtype_bool key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_boolean_int16 (vtype_map* x, vtype_bool key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_boolean_int32 (vtype_map* x, vtype_bool key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_boolean_int64 (vtype_map* x, vtype_bool key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_boolean_uint8 (vtype_map* x, vtype_bool key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_boolean_uint16 (vtype_map* x, vtype_bool key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_boolean_uint32 (vtype_map* x, vtype_bool key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_boolean_uint64 (vtype_map* x, vtype_bool key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_boolean_float (vtype_map* x, vtype_bool key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_boolean_double (vtype_map* x, vtype_bool key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_boolean_ldouble(vtype_map* x, vtype_bool key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_map_update_uint8_pointer(vtype_map* x, vtype_uint8 key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_uint8_cstring(vtype_map* x, vtype_uint8 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint8_string (vtype_map* x, vtype_uint8 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint8_array (vtype_map* x, vtype_uint8 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint8_list (vtype_map* x, vtype_uint8 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint8_map (vtype_map* x, vtype_uint8 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint8_vset (vtype_map* x, vtype_uint8 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint8_dict (vtype_map* x, vtype_uint8 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint8_boolean(vtype_map* x, vtype_uint8 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_uint8_int8 (vtype_map* x, vtype_uint8 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_uint8_int16 (vtype_map* x, vtype_uint8 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_uint8_int32 (vtype_map* x, vtype_uint8 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_uint8_int64 (vtype_map* x, vtype_uint8 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_uint8_uint8 (vtype_map* x, vtype_uint8 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_uint8_uint16 (vtype_map* x, vtype_uint8 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_uint8_uint32 (vtype_map* x, vtype_uint8 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_uint8_uint64 (vtype_map* x, vtype_uint8 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_uint8_float (vtype_map* x, vtype_uint8 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_uint8_double (vtype_map* x, vtype_uint8 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_uint8_ldouble(vtype_map* x, vtype_uint8 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_map_update_uint16_pointer(vtype_map* x, vtype_uint16 key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_uint16_cstring(vtype_map* x, vtype_uint16 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint16_string (vtype_map* x, vtype_uint16 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint16_array (vtype_map* x, vtype_uint16 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint16_list (vtype_map* x, vtype_uint16 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint16_map (vtype_map* x, vtype_uint16 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint16_vset (vtype_map* x, vtype_uint16 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint16_dict (vtype_map* x, vtype_uint16 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint16_boolean(vtype_map* x, vtype_uint16 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_uint16_int8 (vtype_map* x, vtype_uint16 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_uint16_int16 (vtype_map* x, vtype_uint16 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_uint16_int32 (vtype_map* x, vtype_uint16 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_uint16_int64 (vtype_map* x, vtype_uint16 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_uint16_uint8 (vtype_map* x, vtype_uint16 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_uint16_uint16 (vtype_map* x, vtype_uint16 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_uint16_uint32 (vtype_map* x, vtype_uint16 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_uint16_uint64 (vtype_map* x, vtype_uint16 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_uint16_float (vtype_map* x, vtype_uint16 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_uint16_double (vtype_map* x, vtype_uint16 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_uint16_ldouble(vtype_map* x, vtype_uint16 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_map_update_uint32_pointer(vtype_map* x, vtype_uint32 key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_uint32_cstring(vtype_map* x, vtype_uint32 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint32_string (vtype_map* x, vtype_uint32 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint32_array (vtype_map* x, vtype_uint32 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint32_list (vtype_map* x, vtype_uint32 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint32_map (vtype_map* x, vtype_uint32 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint32_vset (vtype_map* x, vtype_uint32 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint32_dict (vtype_map* x, vtype_uint32 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint32_boolean(vtype_map* x, vtype_uint32 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_uint32_int8 (vtype_map* x, vtype_uint32 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_uint32_int16 (vtype_map* x, vtype_uint32 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_uint32_int32 (vtype_map* x, vtype_uint32 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_uint32_int64 (vtype_map* x, vtype_uint32 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_uint32_uint8 (vtype_map* x, vtype_uint32 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_uint32_uint16 (vtype_map* x, vtype_uint32 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_uint32_uint32 (vtype_map* x, vtype_uint32 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_uint32_uint64 (vtype_map* x, vtype_uint32 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_uint32_float (vtype_map* x, vtype_uint32 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_uint32_double (vtype_map* x, vtype_uint32 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_uint32_ldouble(vtype_map* x, vtype_uint32 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_map_update_uint64_pointer(vtype_map* x, vtype_uint64 key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_uint64_cstring(vtype_map* x, vtype_uint64 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint64_string (vtype_map* x, vtype_uint64 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint64_array (vtype_map* x, vtype_uint64 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint64_list (vtype_map* x, vtype_uint64 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint64_map (vtype_map* x, vtype_uint64 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint64_vset (vtype_map* x, vtype_uint64 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint64_dict (vtype_map* x, vtype_uint64 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_uint64_boolean(vtype_map* x, vtype_uint64 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_uint64_int8 (vtype_map* x, vtype_uint64 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_uint64_int16 (vtype_map* x, vtype_uint64 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_uint64_int32 (vtype_map* x, vtype_uint64 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_uint64_int64 (vtype_map* x, vtype_uint64 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_uint64_uint8 (vtype_map* x, vtype_uint64 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_uint64_uint16 (vtype_map* x, vtype_uint64 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_uint64_uint32 (vtype_map* x, vtype_uint64 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_uint64_uint64 (vtype_map* x, vtype_uint64 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_uint64_float (vtype_map* x, vtype_uint64 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_uint64_double (vtype_map* x, vtype_uint64 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_uint64_ldouble(vtype_map* x, vtype_uint64 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_map_update_int8_pointer(vtype_map* x, vtype_int8 key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_int8_cstring(vtype_map* x, vtype_int8 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int8_string (vtype_map* x, vtype_int8 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int8_array (vtype_map* x, vtype_int8 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int8_list (vtype_map* x, vtype_int8 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int8_map (vtype_map* x, vtype_int8 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int8_vset (vtype_map* x, vtype_int8 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int8_dict (vtype_map* x, vtype_int8 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int8_boolean(vtype_map* x, vtype_int8 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_int8_int8 (vtype_map* x, vtype_int8 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_int8_int16 (vtype_map* x, vtype_int8 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_int8_int32 (vtype_map* x, vtype_int8 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_int8_int64 (vtype_map* x, vtype_int8 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_int8_uint8 (vtype_map* x, vtype_int8 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_int8_uint16 (vtype_map* x, vtype_int8 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_int8_uint32 (vtype_map* x, vtype_int8 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_int8_uint64 (vtype_map* x, vtype_int8 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_int8_float (vtype_map* x, vtype_int8 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_int8_double (vtype_map* x, vtype_int8 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_int8_ldouble(vtype_map* x, vtype_int8 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_map_update_int16_pointer(vtype_map* x, vtype_int16 key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_int16_cstring(vtype_map* x, vtype_int16 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int16_string (vtype_map* x, vtype_int16 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int16_array (vtype_map* x, vtype_int16 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int16_list (vtype_map* x, vtype_int16 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int16_map (vtype_map* x, vtype_int16 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int16_vset (vtype_map* x, vtype_int16 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int16_dict (vtype_map* x, vtype_int16 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int16_boolean(vtype_map* x, vtype_int16 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_int16_int8 (vtype_map* x, vtype_int16 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_int16_int16 (vtype_map* x, vtype_int16 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_int16_int32 (vtype_map* x, vtype_int16 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_int16_int64 (vtype_map* x, vtype_int16 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_int16_uint8 (vtype_map* x, vtype_int16 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_int16_uint16 (vtype_map* x, vtype_int16 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_int16_uint32 (vtype_map* x, vtype_int16 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_int16_uint64 (vtype_map* x, vtype_int16 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_int16_float (vtype_map* x, vtype_int16 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_int16_double (vtype_map* x, vtype_int16 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_int16_ldouble(vtype_map* x, vtype_int16 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_map_update_int32_pointer(vtype_map* x, vtype_int32 key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_int32_cstring(vtype_map* x, vtype_int32 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int32_string (vtype_map* x, vtype_int32 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int32_array (vtype_map* x, vtype_int32 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int32_list (vtype_map* x, vtype_int32 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int32_map (vtype_map* x, vtype_int32 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int32_vset (vtype_map* x, vtype_int32 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int32_dict (vtype_map* x, vtype_int32 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int32_boolean(vtype_map* x, vtype_int32 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_int32_int8 (vtype_map* x, vtype_int32 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_int32_int16 (vtype_map* x, vtype_int32 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_int32_int32 (vtype_map* x, vtype_int32 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_int32_int64 (vtype_map* x, vtype_int32 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_int32_uint8 (vtype_map* x, vtype_int32 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_int32_uint16 (vtype_map* x, vtype_int32 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_int32_uint32 (vtype_map* x, vtype_int32 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_int32_uint64 (vtype_map* x, vtype_int32 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_int32_float (vtype_map* x, vtype_int32 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_int32_double (vtype_map* x, vtype_int32 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_int32_ldouble(vtype_map* x, vtype_int32 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_map_update_int64_pointer(vtype_map* x, vtype_int64 key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_int64_cstring(vtype_map* x, vtype_int64 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int64_string (vtype_map* x, vtype_int64 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int64_array (vtype_map* x, vtype_int64 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int64_list (vtype_map* x, vtype_int64 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int64_map (vtype_map* x, vtype_int64 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int64_vset (vtype_map* x, vtype_int64 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int64_dict (vtype_map* x, vtype_int64 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_int64_boolean(vtype_map* x, vtype_int64 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_int64_int8 (vtype_map* x, vtype_int64 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_int64_int16 (vtype_map* x, vtype_int64 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_int64_int32 (vtype_map* x, vtype_int64 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_int64_int64 (vtype_map* x, vtype_int64 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_int64_uint8 (vtype_map* x, vtype_int64 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_int64_uint16 (vtype_map* x, vtype_int64 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_int64_uint32 (vtype_map* x, vtype_int64 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_int64_uint64 (vtype_map* x, vtype_int64 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_int64_float (vtype_map* x, vtype_int64 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_int64_double (vtype_map* x, vtype_int64 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_int64_ldouble(vtype_map* x, vtype_int64 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_map_update_float_pointer(vtype_map* x, vtype_float key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_float_cstring(vtype_map* x, vtype_float key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_float_string (vtype_map* x, vtype_float key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_float_array (vtype_map* x, vtype_float key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_float_list (vtype_map* x, vtype_float key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_float_map (vtype_map* x, vtype_float key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_float_vset (vtype_map* x, vtype_float key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_float_dict (vtype_map* x, vtype_float key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_float_boolean(vtype_map* x, vtype_float key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_float_int8 (vtype_map* x, vtype_float key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_float_int16 (vtype_map* x, vtype_float key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_float_int32 (vtype_map* x, vtype_float key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_float_int64 (vtype_map* x, vtype_float key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_float_uint8 (vtype_map* x, vtype_float key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_float_uint16 (vtype_map* x, vtype_float key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_float_uint32 (vtype_map* x, vtype_float key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_float_uint64 (vtype_map* x, vtype_float key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_float_float (vtype_map* x, vtype_float key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_float_double (vtype_map* x, vtype_float key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_float_ldouble(vtype_map* x, vtype_float key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_map_update_double_pointer(vtype_map* x, vtype_double key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_double_cstring(vtype_map* x, vtype_double key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_double_string (vtype_map* x, vtype_double key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_double_array (vtype_map* x, vtype_double key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_double_list (vtype_map* x, vtype_double key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_double_map (vtype_map* x, vtype_double key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_double_vset (vtype_map* x, vtype_double key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_double_dict (vtype_map* x, vtype_double key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_double_boolean(vtype_map* x, vtype_double key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_double_int8 (vtype_map* x, vtype_double key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_double_int16 (vtype_map* x, vtype_double key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_double_int32 (vtype_map* x, vtype_double key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_double_int64 (vtype_map* x, vtype_double key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_double_uint8 (vtype_map* x, vtype_double key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_double_uint16 (vtype_map* x, vtype_double key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_double_uint32 (vtype_map* x, vtype_double key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_double_uint64 (vtype_map* x, vtype_double key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_double_float (vtype_map* x, vtype_double key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_double_double (vtype_map* x, vtype_double key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_double_ldouble(vtype_map* x, vtype_double key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_map_update_ldouble_pointer(vtype_map* x, vtype_ldouble key, const void* value) Nonnull__(1); -extern bool libcdsb_map_update_ldouble_cstring(vtype_map* x, vtype_ldouble key, const char* value) Nonnull__(1,3); -extern bool libcdsb_map_update_ldouble_string (vtype_map* x, vtype_ldouble key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_map_update_ldouble_array (vtype_map* x, vtype_ldouble key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_map_update_ldouble_list (vtype_map* x, vtype_ldouble key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_map_update_ldouble_map (vtype_map* x, vtype_ldouble key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_map_update_ldouble_vset (vtype_map* x, vtype_ldouble key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_map_update_ldouble_dict (vtype_map* x, vtype_ldouble key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_map_update_ldouble_boolean(vtype_map* x, vtype_ldouble key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_map_update_ldouble_int8 (vtype_map* x, vtype_ldouble key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_map_update_ldouble_int16 (vtype_map* x, vtype_ldouble key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_map_update_ldouble_int32 (vtype_map* x, vtype_ldouble key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_map_update_ldouble_int64 (vtype_map* x, vtype_ldouble key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_map_update_ldouble_uint8 (vtype_map* x, vtype_ldouble key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_map_update_ldouble_uint16 (vtype_map* x, vtype_ldouble key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_map_update_ldouble_uint32 (vtype_map* x, vtype_ldouble key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_map_update_ldouble_uint64 (vtype_map* x, vtype_ldouble key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_map_update_ldouble_float (vtype_map* x, vtype_ldouble key, vtype_float value) Nonnull__(1); -extern bool libcdsb_map_update_ldouble_double (vtype_map* x, vtype_ldouble key, vtype_double value) Nonnull__(1); -extern bool libcdsb_map_update_ldouble_ldouble(vtype_map* x, vtype_ldouble key, vtype_ldouble value) 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); #endif /* LIBCDSB_MAP_H */ diff --git a/include/vtype.h b/include/vtype.h index 4ec686c..19fbee9 100644 --- a/include/vtype.h +++ b/include/vtype.h @@ -69,102 +69,59 @@ typedef struct libcdsb_list vtype_list; typedef struct libcdsb_dict vtype_dict; typedef struct libcdsb_string vtype_string; - -/* Get utf8 chars count in string */ extern size_t string_size(const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get string size in bytes */ extern size_t string_nmemb(const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get count of the array elements */ extern size_t array_size(const vtype_array* x) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get array size in bytes */ extern size_t array_nmemb(const vtype_array* x) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get count of the list elements */ extern size_t list_size(const vtype_list* x) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get count of the map elements */ extern size_t map_size(const vtype_map* x) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get count of the set elements */ extern size_t vset_size(const vtype_set* x) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get count of the dict elements */ extern size_t dict_size(const vtype_dict* x) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get count of the available nodes */ extern size_t dict_capacity(const vtype_dict* x) Pure__ Warn_unused_result__ Nonnull__(1); -/* Cpmpare 2 strings */ extern int string_compare(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -/* Compare 2 arrays */ -extern int array_compare(const vtype_array* s0, const vtype_array* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -/* Compare 2 lists */ -extern int list_compare(const vtype_list* s0, const vtype_list* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -/* Compare 2 maps */ -extern int map_compare(const vtype_map* s0, const vtype_map* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -/* Compare 2 sets */ -extern int vset_compare(const vtype_set* s0, const vtype_set* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -/* Compare 2 dicts */ -extern int dict_compare(const vtype_dict* s0, const vtype_dict* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); +extern int array_compare (const vtype_array* s0, const vtype_array* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); +extern int list_compare (const vtype_list* s0, const vtype_list* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); +extern int map_compare (const vtype_map* s0, const vtype_map* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); +extern int vset_compare (const vtype_set* s0, const vtype_set* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); +extern int dict_compare (const vtype_dict* s0, const vtype_dict* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -/* Copy string to another */ -extern vtype_string string_copy(const vtype_string* s) Pure__ Warn_unused_result__ Nonnull__(1); -/* Copy array to another */ -extern vtype_array array_copy(const vtype_array* s) Pure__ Warn_unused_result__ Nonnull__(1); -/* Copy list to another */ -extern vtype_list list_copy(const vtype_list* s) Pure__ Warn_unused_result__ Nonnull__(1); -/* Copy map to another */ -extern vtype_map map_copy(const vtype_map* s) Pure__ Warn_unused_result__ Nonnull__(1); -/* Copy set to another */ -extern vtype_set vset_copy(const vtype_set* s) Pure__ Warn_unused_result__ Nonnull__(1); -/* Copy set to another */ -extern vtype_dict dict_copy(const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_string string_copy (const vtype_string* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_array array_copy (const vtype_array* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_list list_copy (const vtype_list* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_map map_copy (const vtype_map* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_set vset_copy (const vtype_set* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_dict dict_copy (const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); +#define map_copy_keys(s) vset_copy((vtype_set*)s) -/* Duplicate string memory block */ -extern vtype_string* string_duplicate(const vtype_string* s) Warn_unused_result__ Nonnull__(1); -/* Duplicate array memory block */ -extern vtype_array* array_duplicate(const vtype_array* s) Warn_unused_result__ Nonnull__(1); -/* Duplicate list memory block */ -extern vtype_list* list_duplicate(const vtype_list* s) Warn_unused_result__ Nonnull__(1); -/* Duplicate map memory block */ -extern vtype_map* map_duplicate(const vtype_map* s) Warn_unused_result__ Nonnull__(1); -/* Duplicate set memory block */ -extern vtype_set* vset_duplicate(const vtype_set* s) Warn_unused_result__ Nonnull__(1); -/* Duplicate dict memory block */ -extern vtype_dict* dict_duplicate(const vtype_dict* s) Warn_unused_result__ Nonnull__(1); +extern vtype_string* string_duplicate (const vtype_string* s) Warn_unused_result__ Nonnull__(1); +extern vtype_array* array_duplicate (const vtype_array* s) Warn_unused_result__ Nonnull__(1); +extern vtype_list* list_duplicate (const vtype_list* s) Warn_unused_result__ Nonnull__(1); +extern vtype_map* map_duplicate (const vtype_map* s) Warn_unused_result__ Nonnull__(1); +extern vtype_set* vset_duplicate (const vtype_set* s) Warn_unused_result__ Nonnull__(1); +extern vtype_dict* dict_duplicate (const vtype_dict* s) Warn_unused_result__ Nonnull__(1); +#define map_duplicate_keys(s) vset_duplicate((vtype_set*)s) -/* Copy string and store result to the memory block */ -extern void string_copy_init(vtype_string* x, const vtype_string* s) Nonnull__(1,2); -/* Copy array and store result to the memory block */ -extern void array_copy_init(vtype_array* x, const vtype_array* s) Nonnull__(1,2); -/* Copy list and store result to the memory block */ -extern void list_copy_init(vtype_list* x, const vtype_list* s) Nonnull__(1,2); -/* Copy map and store result to the memory block */ -extern void map_copy_init(vtype_map* x, const vtype_map* s) Nonnull__(1,2); -/* Copy set and store result to the memory block */ -extern void vset_copy_init(vtype_set* x, const vtype_set* s) Nonnull__(1,2); -/* Copy dict and store result to the memory block */ -extern void dict_copy_init(vtype_dict* x, const vtype_dict* s) Nonnull__(1,2); +extern void string_copy_init (vtype_string* x, const vtype_string* s) Nonnull__(1,2); +extern void array_copy_init (vtype_array* x, const vtype_array* s) Nonnull__(1,2); +extern void list_copy_init (vtype_list* x, const vtype_list* s) Nonnull__(1,2); +extern void map_copy_init (vtype_map* x, const vtype_map* s) Nonnull__(1,2); +extern void vset_copy_init (vtype_set* x, const vtype_set* s) Nonnull__(1,2); +extern void dict_copy_init (vtype_dict* x, const vtype_dict* s) Nonnull__(1,2); +#define map_copy_init_keys(x, s) vset_duplicate(x, (vtype_set*)s) -/* Free string resources */ extern void string_free(vtype_string* x); -/* Free array resources */ -extern void array_free(vtype_array* x); -/* Free list resources */ -extern void list_free(vtype_list* x); -/* Free map resources */ -extern void map_free(vtype_map* x); -/* Free set resources */ -extern void vset_free(vtype_set* x); -/* Free dict resources */ -extern void dict_free(vtype_dict* x); +extern void array_free (vtype_array* x); +extern void list_free (vtype_list* x); +extern void map_free (vtype_map* x); +extern void vset_free (vtype_set* x); +extern void dict_free (vtype_dict* x); -/* Get hash of the string */ extern vtype_hash string_hash(const vtype_string* s) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get hash of the array */ -extern vtype_hash array_hash(const vtype_array* s) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get hash of the list */ -extern vtype_hash list_hash(const vtype_list* s) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get hash of the map */ -extern vtype_hash map_hash(const vtype_map* s) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get hash of the set */ -extern vtype_hash vset_hash(const vtype_set* s) Pure__ Warn_unused_result__ Nonnull__(1); -/* Get hash of the dict */ -extern vtype_hash dict_hash(const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_hash array_hash (const vtype_array* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_hash list_hash (const vtype_list* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_hash map_hash (const vtype_map* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_hash vset_hash (const vtype_set* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_hash dict_hash (const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); #endif /* LIBCDSB_VTYPE_H */ diff --git a/src/__internal/vnode.h b/src/__internal/vnode.h index ad9a393..755730f 100644 --- a/src/__internal/vnode.h +++ b/src/__internal/vnode.h @@ -2,6 +2,7 @@ /* Copyright © 2022 Gregory Lirent */ #include "include.h" +#include "assert.h" #ifndef LIBCDSB_SRC_INTERNAL_VNODE_H #define LIBCDSB_SRC_INTERNAL_VNODE_H @@ -24,6 +25,32 @@ extern vnode_t libcdsb_vnode_create_target(vtype target_type, const void* value, extern void libcdsb_vnode_free(vnode_t* x, vtype type) Nonnull__(1); extern void* libcdsb_vnode_peek(const vnode_t* x, vtype type) pure__ wur__ Nonnull__(1); +ainline(void vnode_attach(vnode_t* node, const void* value, vtype type)) { + if (type < VTYPE_STRING) { + *node = libcdsb_vnode_create(value, type); + } else if (sizeof(str_t) == sizeof(void*) && type == VTYPE_STRING) { + *node = *(char**)value; + } else { + *node = malloc(vtype_size(type)); + memcpy(*node, value, vtype_size(type)); + } +} + +ainline(void vnode_tattach(vnode_t* node, vtype target_type, const void* value, vtype type)) { + if (type < VTYPE_STRING) { + *node = libcdsb_vnode_create_target(target_type, value, type); + } else { + type_assert(target_type, type); + + if (sizeof(str_t) == sizeof(void*) && type == VTYPE_STRING) { + *node = *(char**)value; + } else { + *node = malloc(vtype_size(type)); + memcpy(*node, value, vtype_size(type)); + } + } +} + #define vnode_create libcdsb_vnode_create #define vnode_tcreate libcdsb_vnode_create_target #define vnode_peek libcdsb_vnode_peek diff --git a/src/map/extra.c b/src/map/access.c similarity index 65% rename from src/map/extra.c rename to src/map/access.c index 0364e24..83c51fe 100644 --- a/src/map/extra.c +++ b/src/map/access.c @@ -3,53 +3,6 @@ #include "include.h" -bool libcdsb_map_update(map_t* x, const void* k, vtype kt, const void* v, vtype vt) { - int cmp; - mnode_t* n; - mnode_t* p; - vnode_t kn; - - n = x->root; - kn = vnode_tcreate(x->type, k, kt); - kt = x->type; - k = vnode_peek(&kn, kt); - - if (!mnode_is_empty(n)) { - do { - p = n; - cmp = vtype_compare(k, kt, vnode_peek(&n->key, kt), kt); - - if (cmp == 0) { - vnode_free(&n->key, x->type); - vnode_free(&n->value, n->type); - - n->key = kn; - n->value = vnode_create(v, vt); - n->type = vt; - - return true; - } - - n = (cmp < 0) ? n->left : n->right; - } while (!mnode_is_empty(n)); - - n = mnode_create(kn, p, 1); - - if (cmp < 0) p->left = n; - else p->right = n; - - if (!mnode_is_root(p)) - mnode_fixup(&x->root, n); - - } else n = x->root = mnode_create(kn, mnode_empty, 0); - - n->value = vnode_create(v, vt); - n->type = vt; - - return false; -} - - int libcdsb_map_find(map_t* x, const void* k, vtype t, void* _, map_access_callback callback, bool cut) { mnode_t* c; void *key; diff --git a/src/map/base.c b/src/map/base.c deleted file mode 100644 index d2fc45d..0000000 --- a/src/map/base.c +++ /dev/null @@ -1,163 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - -/*#####################################################################################################################*/ - -static inline int mnode_compare(const mnode_t* s0, const mnode_t* s1, vtype t) { - int c = vnode_compare_eq(&s0->key, &s1->key, t); - - return !c ? vnode_compare(&s0->value, s0->type, &s1->value, s1->type) : c; -} - -static inline hash_t mnode_hash(const mnode_t* s, vtype t) { - return vnode_hash(&s->key, t) + vnode_hash(&s->value, s->type) + t; -} - -/*#####################################################################################################################*/ - -hash_t map_hash(const map_t* s) { - - stack_t z; - mnode_t *c0, *c1; - hash_t hash, v; - - if (mnode_is_empty(s->root)) - return 0; - - stack_init(&z); - stack_push(&z, s->root->left); - - hash = 1; - - if (!mnode_is_empty(c0 = stack_pop(&z))) { - do { - ++hash; - if (!mnode_is_empty(c0->right)) stack_push(&z, c0->right); - if (!mnode_is_empty(c0->left)) stack_push(&z, c1 = c0->left); - } while (!is_null(c0 = stack_pop(&z))); - } - - v = mnode_hash(c1, s->type); - stack_push(&z, s->root->right); - - if (!mnode_is_empty(c0 = stack_pop(&z))) { - do { - ++hash; - if (!mnode_is_empty(c0->right)) stack_push(&z, c1 = c0->right); - if (!mnode_is_empty(c0->left)) stack_push(&z, c0->left); - } while (!is_null(c0 = stack_pop(&z))); - } - - v += mnode_hash(c1, s->type); - - return (hash ^ v) + VTYPE_MAP; -} - -/*#####################################################################################################################*/ - -void map_init(map_t* x, vtype t) { - x->root = mnode_empty; - x->type = t; -} - -void map_free(map_t* x) { - mnode_t *t, *c; - - c = x->root; - - while (!mnode_is_empty(x->root)) { - if (!mnode_is_empty(c->left)) { - c = c->left; - } else if (!mnode_is_empty(c->right)) { - c = c->right; - } else if (!mnode_is_root(c)) { - vnode_free(&c->key, x->type); - vnode_free(&c->value, c->type); - - t = c; - c = c->parent; - - if (t == c->left) c->left = mnode_empty; - else c->right = mnode_empty; - - free(t); - } else { - vnode_free(&c->key, x->type); - vnode_free(&c->value, c->type); - x->root = mnode_empty; - } - } - - x->type = 0; -} - -/*#####################################################################################################################*/ - -size_t map_size(const map_t* x) { - stack_t z; - size_t n; - rbnode_t* c; - - stack_init(&z); - stack_push(&z, x->root); - - n = 0; - - if (!mnode_is_empty(x->root)) { - while ((c = stack_pop(&z))) { - ++n; - if (!rbnode_is_empty(c->right)) stack_push(&z, c->right); - if (!rbnode_is_empty(c->left)) stack_push(&z, c->left); - } - } - - return n; -} - -/*#####################################################################################################################*/ - -int map_compare(const map_t* s0, const map_t* s1) { - stack_t z; - mnode_t *c0, *c1; - int cmp; - - if (s0 == s1 || s0->root == s1->root) - return 0; - if (s0->type != s1->type) - return s0->type - s1->type; - - stack_init(&z); - stack_push_many(&z, 2, (void*)s1, (void*)s0); - - cmp = 0; - - do { - c0 = stack_pop(&z); - c1 = stack_pop(&z); - - if (mnode_is_empty(c0) || mnode_is_empty(c1)) { - if (c0 != c1) { - stack_flush(&z); - return mnode_is_empty(c0) ? -1 : 1; - } - } else if ((cmp = mnode_compare(c0, c1, s0->type))) { - if (c0->left == c1->right) { // == mnode_empty - cmp = mnode_compare(c0->right, c1, s0->type); - if (!cmp) cmp = mnode_compare(c0, c1->left, s0->type); - } else if (c0->right == c1->left) { // == mnode_empty - cmp = mnode_compare(c0, c1->right, s0->type); - if (!cmp) cmp = mnode_compare(c0->left, c1, s0->type); - } - - if (cmp) { - stack_flush(&z); - return cmp; - } - } else stack_push_many(&z, 4, c1->right, c0->right, c1->left, c0->left); - - } while (!is_null(z.value)); - - return 0; -} diff --git a/src/map/comparison.c b/src/map/comparison.c new file mode 100644 index 0000000..9590767 --- /dev/null +++ b/src/map/comparison.c @@ -0,0 +1,56 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +static inline int mnode_compare(const mnode_t* s0, const mnode_t* s1, vtype t) { + int c = vnode_compare_eq(&s0->key, &s1->key, t); + + return !c ? vnode_compare(&s0->value, s0->type, &s1->value, s1->type) : c; +} + +/*#####################################################################################################################*/ + +int map_compare(const map_t* s0, const map_t* s1) { + stack_t z; + mnode_t *c0, *c1; + int cmp; + + if (s0 == s1 || s0->root == s1->root) + return 0; + if (s0->type != s1->type) + return s0->type - s1->type; + + stack_init(&z); + stack_push_many(&z, 2, (void*)s1, (void*)s0); + + cmp = 0; + + do { + c0 = stack_pop(&z); + c1 = stack_pop(&z); + + if (mnode_is_empty(c0) || mnode_is_empty(c1)) { + if (c0 != c1) { + stack_flush(&z); + return mnode_is_empty(c0) ? -1 : 1; + } + } else if ((cmp = mnode_compare(c0, c1, s0->type))) { + if (c0->left == c1->right) { // == mnode_empty + cmp = mnode_compare(c0->right, c1, s0->type); + if (!cmp) cmp = mnode_compare(c0, c1->left, s0->type); + } else if (c0->right == c1->left) { // == mnode_empty + cmp = mnode_compare(c0, c1->right, s0->type); + if (!cmp) cmp = mnode_compare(c0->left, c1, s0->type); + } + + if (cmp) { + stack_flush(&z); + return cmp; + } + } else stack_push_many(&z, 4, c1->right, c0->right, c1->left, c0->left); + + } while (!is_null(z.value)); + + return 0; +} diff --git a/src/map/compute.c b/src/map/compute.c new file mode 100644 index 0000000..8c03385 --- /dev/null +++ b/src/map/compute.c @@ -0,0 +1,70 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +static inline hash_t mnode_hash(const mnode_t* s, vtype t) { + return vnode_hash(&s->key, t) + vnode_hash(&s->value, s->type) + t; +} + +/*#####################################################################################################################*/ + +size_t map_size(const map_t* x) { + stack_t z; + size_t n; + rbnode_t* c; + + stack_init(&z); + stack_push(&z, x->root); + + n = 0; + + if (!mnode_is_empty(x->root)) { + while ((c = stack_pop(&z))) { + ++n; + if (!rbnode_is_empty(c->right)) stack_push(&z, c->right); + if (!rbnode_is_empty(c->left)) stack_push(&z, c->left); + } + } + + return n; +} + + +hash_t map_hash(const map_t* s) { + + stack_t z; + mnode_t *c0, *c1; + hash_t hash, v; + + if (mnode_is_empty(s->root)) + return 0; + + stack_init(&z); + stack_push(&z, s->root->left); + + hash = 1; + + if (!mnode_is_empty(c0 = stack_pop(&z))) { + do { + ++hash; + if (!mnode_is_empty(c0->right)) stack_push(&z, c0->right); + if (!mnode_is_empty(c0->left)) stack_push(&z, c1 = c0->left); + } while (!is_null(c0 = stack_pop(&z))); + } + + v = mnode_hash(c1, s->type); + stack_push(&z, s->root->right); + + if (!mnode_is_empty(c0 = stack_pop(&z))) { + do { + ++hash; + if (!mnode_is_empty(c0->right)) stack_push(&z, c1 = c0->right); + if (!mnode_is_empty(c0->left)) stack_push(&z, c0->left); + } while (!is_null(c0 = stack_pop(&z))); + } + + v += mnode_hash(c1, s->type); + + return (hash ^ v) + VTYPE_MAP; +} diff --git a/src/map/copy.c b/src/map/copy.c index abe107f..7fe7ecf 100644 --- a/src/map/copy.c +++ b/src/map/copy.c @@ -3,8 +3,6 @@ #include "include.h" -/*#####################################################################################################################*/ - static inline mnode_t* mnode_duplicate(const mnode_t* s, mnode_t* p, const vtype t) { mnode_t* x; diff --git a/src/map/generics.c b/src/map/generics.c deleted file mode 100644 index 649ed10..0000000 --- a/src/map/generics.c +++ /dev/null @@ -1,445 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - -int libcdsb_map_find_pointer(map_t* x, const void* k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_cstring(map_t* x, const char* k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_string (map_t* x, const str_t* k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, k, vtypeof( k), _, cb, cut); } -int libcdsb_map_find_array (map_t* x, const arr_t* k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, k, vtypeof( k), _, cb, cut); } -int libcdsb_map_find_list (map_t* x, const list_t* k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, k, vtypeof( k), _, cb, cut); } -int libcdsb_map_find_map (map_t* x, const map_t* k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, k, vtypeof( k), _, cb, cut); } -int libcdsb_map_find_vset (map_t* x, const set_t* k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, k, vtypeof( k), _, cb, cut); } -int libcdsb_map_find_dict (map_t* x, const dict_t* k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, k, vtypeof( k), _, cb, cut); } -int libcdsb_map_find_boolean(map_t* x, bool k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_int8 (map_t* x, s8_t k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_int16 (map_t* x, s16_t k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_int32 (map_t* x, s32_t k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_int64 (map_t* x, s64_t k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_uint8 (map_t* x, u8_t k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_uint16 (map_t* x, u16_t k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_uint32 (map_t* x, u32_t k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_uint64 (map_t* x, u64_t k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_float (map_t* x, fl_t k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_double (map_t* x, dbl_t k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_map_find_ldouble(map_t* x, ldbl_t k, void* _, map_access_callback cb, bool cut) { return libcdsb_map_find(x, &k, vtypeof(&k), _, cb, cut); } - -bool libcdsb_map_update_pointer_pointer(map_t* x, const void* k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_cstring(map_t* x, const void* k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_string (map_t* x, const void* k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_pointer_array (map_t* x, const void* k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_pointer_list (map_t* x, const void* k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_pointer_map (map_t* x, const void* k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_pointer_vset (map_t* x, const void* k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_pointer_dict (map_t* x, const void* k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_pointer_boolean(map_t* x, const void* k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_int8 (map_t* x, const void* k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_int16 (map_t* x, const void* k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_int32 (map_t* x, const void* k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_int64 (map_t* x, const void* k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_uint8 (map_t* x, const void* k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_uint16 (map_t* x, const void* k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_uint32 (map_t* x, const void* k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_uint64 (map_t* x, const void* k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_float (map_t* x, const void* k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_double (map_t* x, const void* k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_pointer_ldouble(map_t* x, const void* k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_cstring_pointer(map_t* x, const char* k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_cstring(map_t* x, const char* k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_string (map_t* x, const char* k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_cstring_array (map_t* x, const char* k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_cstring_list (map_t* x, const char* k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_cstring_map (map_t* x, const char* k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_cstring_vset (map_t* x, const char* k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_cstring_dict (map_t* x, const char* k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_cstring_boolean(map_t* x, const char* k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_int8 (map_t* x, const char* k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_int16 (map_t* x, const char* k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_int32 (map_t* x, const char* k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_int64 (map_t* x, const char* k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_uint8 (map_t* x, const char* k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_uint16 (map_t* x, const char* k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_uint32 (map_t* x, const char* k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_uint64 (map_t* x, const char* k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_float (map_t* x, const char* k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_double (map_t* x, const char* k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_cstring_ldouble(map_t* x, const char* k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_string_pointer(map_t* x, const str_t* k, const void* v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_cstring(map_t* x, const str_t* k, const char* v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_string (map_t* x, const str_t* k, const str_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_string_array (map_t* x, const str_t* k, const arr_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_string_list (map_t* x, const str_t* k, const list_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_string_map (map_t* x, const str_t* k, const map_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_string_vset (map_t* x, const str_t* k, const set_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_string_dict (map_t* x, const str_t* k, const dict_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_string_boolean(map_t* x, const str_t* k, bool v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_int8 (map_t* x, const str_t* k, s8_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_int16 (map_t* x, const str_t* k, s16_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_int32 (map_t* x, const str_t* k, s32_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_int64 (map_t* x, const str_t* k, s64_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_uint8 (map_t* x, const str_t* k, u8_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_uint16 (map_t* x, const str_t* k, u16_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_uint32 (map_t* x, const str_t* k, u32_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_uint64 (map_t* x, const str_t* k, u64_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_float (map_t* x, const str_t* k, fl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_double (map_t* x, const str_t* k, dbl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_string_ldouble(map_t* x, const str_t* k, ldbl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_array_pointer(map_t* x, const arr_t* k, const void* v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_cstring(map_t* x, const arr_t* k, const char* v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_string (map_t* x, const arr_t* k, const str_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_array_array (map_t* x, const arr_t* k, const arr_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_array_list (map_t* x, const arr_t* k, const list_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_array_map (map_t* x, const arr_t* k, const map_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_array_vset (map_t* x, const arr_t* k, const set_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_array_dict (map_t* x, const arr_t* k, const dict_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_array_boolean(map_t* x, const arr_t* k, bool v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_int8 (map_t* x, const arr_t* k, s8_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_int16 (map_t* x, const arr_t* k, s16_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_int32 (map_t* x, const arr_t* k, s32_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_int64 (map_t* x, const arr_t* k, s64_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_uint8 (map_t* x, const arr_t* k, u8_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_uint16 (map_t* x, const arr_t* k, u16_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_uint32 (map_t* x, const arr_t* k, u32_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_uint64 (map_t* x, const arr_t* k, u64_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_float (map_t* x, const arr_t* k, fl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_double (map_t* x, const arr_t* k, dbl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_array_ldouble(map_t* x, const arr_t* k, ldbl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_list_pointer(map_t* x, const list_t* k, const void* v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_cstring(map_t* x, const list_t* k, const char* v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_string (map_t* x, const list_t* k, const str_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_list_array (map_t* x, const list_t* k, const arr_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_list_list (map_t* x, const list_t* k, const list_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_list_map (map_t* x, const list_t* k, const map_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_list_vset (map_t* x, const list_t* k, const set_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_list_dict (map_t* x, const list_t* k, const dict_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_list_boolean(map_t* x, const list_t* k, bool v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_int8 (map_t* x, const list_t* k, s8_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_int16 (map_t* x, const list_t* k, s16_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_int32 (map_t* x, const list_t* k, s32_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_int64 (map_t* x, const list_t* k, s64_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_uint8 (map_t* x, const list_t* k, u8_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_uint16 (map_t* x, const list_t* k, u16_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_uint32 (map_t* x, const list_t* k, u32_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_uint64 (map_t* x, const list_t* k, u64_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_float (map_t* x, const list_t* k, fl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_double (map_t* x, const list_t* k, dbl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_list_ldouble(map_t* x, const list_t* k, ldbl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_map_pointer(map_t* x, const map_t* k, const void* v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_cstring(map_t* x, const map_t* k, const char* v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_string (map_t* x, const map_t* k, const str_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_map_array (map_t* x, const map_t* k, const arr_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_map_list (map_t* x, const map_t* k, const list_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_map_map (map_t* x, const map_t* k, const map_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_map_vset (map_t* x, const map_t* k, const set_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_map_dict (map_t* x, const map_t* k, const dict_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_map_boolean(map_t* x, const map_t* k, bool v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_int8 (map_t* x, const map_t* k, s8_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_int16 (map_t* x, const map_t* k, s16_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_int32 (map_t* x, const map_t* k, s32_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_int64 (map_t* x, const map_t* k, s64_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_uint8 (map_t* x, const map_t* k, u8_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_uint16 (map_t* x, const map_t* k, u16_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_uint32 (map_t* x, const map_t* k, u32_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_uint64 (map_t* x, const map_t* k, u64_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_float (map_t* x, const map_t* k, fl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_double (map_t* x, const map_t* k, dbl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_map_ldouble(map_t* x, const map_t* k, ldbl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_vset_pointer(map_t* x, const set_t* k, const void* v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_cstring(map_t* x, const set_t* k, const char* v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_string (map_t* x, const set_t* k, const str_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_vset_array (map_t* x, const set_t* k, const arr_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_vset_list (map_t* x, const set_t* k, const list_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_vset_map (map_t* x, const set_t* k, const map_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_vset_vset (map_t* x, const set_t* k, const set_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_vset_dict (map_t* x, const set_t* k, const dict_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_vset_boolean(map_t* x, const set_t* k, bool v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_int8 (map_t* x, const set_t* k, s8_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_int16 (map_t* x, const set_t* k, s16_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_int32 (map_t* x, const set_t* k, s32_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_int64 (map_t* x, const set_t* k, s64_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_uint8 (map_t* x, const set_t* k, u8_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_uint16 (map_t* x, const set_t* k, u16_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_uint32 (map_t* x, const set_t* k, u32_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_uint64 (map_t* x, const set_t* k, u64_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_float (map_t* x, const set_t* k, fl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_double (map_t* x, const set_t* k, dbl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_vset_ldouble(map_t* x, const set_t* k, ldbl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_dict_pointer(map_t* x, const dict_t* k, const void* v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_cstring(map_t* x, const dict_t* k, const char* v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_string (map_t* x, const dict_t* k, const str_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_dict_array (map_t* x, const dict_t* k, const arr_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_dict_list (map_t* x, const dict_t* k, const list_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_dict_map (map_t* x, const dict_t* k, const map_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_dict_vset (map_t* x, const dict_t* k, const set_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_dict_dict (map_t* x, const dict_t* k, const dict_t* v) { return libcdsb_map_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_map_update_dict_boolean(map_t* x, const dict_t* k, bool v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_int8 (map_t* x, const dict_t* k, s8_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_int16 (map_t* x, const dict_t* k, s16_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_int32 (map_t* x, const dict_t* k, s32_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_int64 (map_t* x, const dict_t* k, s64_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_uint8 (map_t* x, const dict_t* k, u8_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_uint16 (map_t* x, const dict_t* k, u16_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_uint32 (map_t* x, const dict_t* k, u32_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_uint64 (map_t* x, const dict_t* k, u64_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_float (map_t* x, const dict_t* k, fl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_double (map_t* x, const dict_t* k, dbl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_map_update_dict_ldouble(map_t* x, const dict_t* k, ldbl_t v) { return libcdsb_map_update(x, k, vtypeof(k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_boolean_pointer(map_t* x, const bool k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_cstring(map_t* x, const bool k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_string (map_t* x, const bool k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_boolean_array (map_t* x, const bool k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_boolean_list (map_t* x, const bool k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_boolean_map (map_t* x, const bool k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_boolean_vset (map_t* x, const bool k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_boolean_dict (map_t* x, const bool k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_boolean_boolean(map_t* x, const bool k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_int8 (map_t* x, const bool k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_int16 (map_t* x, const bool k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_int32 (map_t* x, const bool k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_int64 (map_t* x, const bool k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_uint8 (map_t* x, const bool k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_uint16 (map_t* x, const bool k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_uint32 (map_t* x, const bool k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_uint64 (map_t* x, const bool k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_float (map_t* x, const bool k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_double (map_t* x, const bool k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_boolean_ldouble(map_t* x, const bool k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_int8_pointer(map_t* x, const s8_t k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_cstring(map_t* x, const s8_t k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_string (map_t* x, const s8_t k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int8_array (map_t* x, const s8_t k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int8_list (map_t* x, const s8_t k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int8_map (map_t* x, const s8_t k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int8_vset (map_t* x, const s8_t k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int8_dict (map_t* x, const s8_t k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int8_boolean(map_t* x, const s8_t k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_int8 (map_t* x, const s8_t k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_int16 (map_t* x, const s8_t k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_int32 (map_t* x, const s8_t k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_int64 (map_t* x, const s8_t k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_uint8 (map_t* x, const s8_t k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_uint16 (map_t* x, const s8_t k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_uint32 (map_t* x, const s8_t k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_uint64 (map_t* x, const s8_t k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_float (map_t* x, const s8_t k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_double (map_t* x, const s8_t k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int8_ldouble(map_t* x, const s8_t k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_int16_pointer(map_t* x, const s16_t k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_cstring(map_t* x, const s16_t k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_string (map_t* x, const s16_t k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int16_array (map_t* x, const s16_t k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int16_list (map_t* x, const s16_t k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int16_map (map_t* x, const s16_t k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int16_vset (map_t* x, const s16_t k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int16_dict (map_t* x, const s16_t k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int16_boolean(map_t* x, const s16_t k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_int8 (map_t* x, const s16_t k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_int16 (map_t* x, const s16_t k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_int32 (map_t* x, const s16_t k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_int64 (map_t* x, const s16_t k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_uint8 (map_t* x, const s16_t k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_uint16 (map_t* x, const s16_t k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_uint32 (map_t* x, const s16_t k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_uint64 (map_t* x, const s16_t k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_float (map_t* x, const s16_t k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_double (map_t* x, const s16_t k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int16_ldouble(map_t* x, const s16_t k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_int32_pointer(map_t* x, const s32_t k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_cstring(map_t* x, const s32_t k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_string (map_t* x, const s32_t k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int32_array (map_t* x, const s32_t k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int32_list (map_t* x, const s32_t k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int32_map (map_t* x, const s32_t k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int32_vset (map_t* x, const s32_t k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int32_dict (map_t* x, const s32_t k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int32_boolean(map_t* x, const s32_t k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_int8 (map_t* x, const s32_t k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_int16 (map_t* x, const s32_t k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_int32 (map_t* x, const s32_t k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_int64 (map_t* x, const s32_t k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_uint8 (map_t* x, const s32_t k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_uint16 (map_t* x, const s32_t k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_uint32 (map_t* x, const s32_t k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_uint64 (map_t* x, const s32_t k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_float (map_t* x, const s32_t k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_double (map_t* x, const s32_t k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int32_ldouble(map_t* x, const s32_t k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_int64_pointer(map_t* x, const s64_t k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_cstring(map_t* x, const s64_t k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_string (map_t* x, const s64_t k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int64_array (map_t* x, const s64_t k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int64_list (map_t* x, const s64_t k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int64_map (map_t* x, const s64_t k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int64_vset (map_t* x, const s64_t k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int64_dict (map_t* x, const s64_t k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_int64_boolean(map_t* x, const s64_t k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_int8 (map_t* x, const s64_t k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_int16 (map_t* x, const s64_t k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_int32 (map_t* x, const s64_t k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_int64 (map_t* x, const s64_t k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_uint8 (map_t* x, const s64_t k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_uint16 (map_t* x, const s64_t k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_uint32 (map_t* x, const s64_t k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_uint64 (map_t* x, const s64_t k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_float (map_t* x, const s64_t k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_double (map_t* x, const s64_t k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_int64_ldouble(map_t* x, const s64_t k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_uint8_pointer(map_t* x, const u8_t k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_cstring(map_t* x, const u8_t k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_string (map_t* x, const u8_t k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint8_array (map_t* x, const u8_t k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint8_list (map_t* x, const u8_t k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint8_map (map_t* x, const u8_t k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint8_vset (map_t* x, const u8_t k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint8_dict (map_t* x, const u8_t k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint8_boolean(map_t* x, const u8_t k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_int8 (map_t* x, const u8_t k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_int16 (map_t* x, const u8_t k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_int32 (map_t* x, const u8_t k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_int64 (map_t* x, const u8_t k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_uint8 (map_t* x, const u8_t k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_uint16 (map_t* x, const u8_t k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_uint32 (map_t* x, const u8_t k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_uint64 (map_t* x, const u8_t k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_float (map_t* x, const u8_t k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_double (map_t* x, const u8_t k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint8_ldouble(map_t* x, const u8_t k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_uint16_pointer(map_t* x, const u16_t k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_cstring(map_t* x, const u16_t k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_string (map_t* x, const u16_t k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint16_array (map_t* x, const u16_t k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint16_list (map_t* x, const u16_t k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint16_map (map_t* x, const u16_t k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint16_vset (map_t* x, const u16_t k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint16_dict (map_t* x, const u16_t k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint16_boolean(map_t* x, const u16_t k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_int8 (map_t* x, const u16_t k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_int16 (map_t* x, const u16_t k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_int32 (map_t* x, const u16_t k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_int64 (map_t* x, const u16_t k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_uint8 (map_t* x, const u16_t k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_uint16 (map_t* x, const u16_t k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_uint32 (map_t* x, const u16_t k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_uint64 (map_t* x, const u16_t k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_float (map_t* x, const u16_t k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_double (map_t* x, const u16_t k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint16_ldouble(map_t* x, const u16_t k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_uint32_pointer(map_t* x, const u32_t k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_cstring(map_t* x, const u32_t k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_string (map_t* x, const u32_t k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint32_array (map_t* x, const u32_t k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint32_list (map_t* x, const u32_t k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint32_map (map_t* x, const u32_t k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint32_vset (map_t* x, const u32_t k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint32_dict (map_t* x, const u32_t k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint32_boolean(map_t* x, const u32_t k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_int8 (map_t* x, const u32_t k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_int16 (map_t* x, const u32_t k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_int32 (map_t* x, const u32_t k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_int64 (map_t* x, const u32_t k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_uint8 (map_t* x, const u32_t k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_uint16 (map_t* x, const u32_t k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_uint32 (map_t* x, const u32_t k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_uint64 (map_t* x, const u32_t k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_float (map_t* x, const u32_t k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_double (map_t* x, const u32_t k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint32_ldouble(map_t* x, const u32_t k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_uint64_pointer(map_t* x, const u64_t k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_cstring(map_t* x, const u64_t k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_string (map_t* x, const u64_t k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint64_array (map_t* x, const u64_t k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint64_list (map_t* x, const u64_t k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint64_map (map_t* x, const u64_t k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint64_vset (map_t* x, const u64_t k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint64_dict (map_t* x, const u64_t k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_uint64_boolean(map_t* x, const u64_t k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_int8 (map_t* x, const u64_t k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_int16 (map_t* x, const u64_t k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_int32 (map_t* x, const u64_t k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_int64 (map_t* x, const u64_t k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_uint8 (map_t* x, const u64_t k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_uint16 (map_t* x, const u64_t k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_uint32 (map_t* x, const u64_t k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_uint64 (map_t* x, const u64_t k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_float (map_t* x, const u64_t k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_double (map_t* x, const u64_t k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_uint64_ldouble(map_t* x, const u64_t k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_float_pointer(map_t* x, const fl_t k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_cstring(map_t* x, const fl_t k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_string (map_t* x, const fl_t k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_float_array (map_t* x, const fl_t k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_float_list (map_t* x, const fl_t k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_float_map (map_t* x, const fl_t k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_float_vset (map_t* x, const fl_t k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_float_dict (map_t* x, const fl_t k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_float_boolean(map_t* x, const fl_t k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_int8 (map_t* x, const fl_t k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_int16 (map_t* x, const fl_t k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_int32 (map_t* x, const fl_t k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_int64 (map_t* x, const fl_t k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_uint8 (map_t* x, const fl_t k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_uint16 (map_t* x, const fl_t k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_uint32 (map_t* x, const fl_t k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_uint64 (map_t* x, const fl_t k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_float (map_t* x, const fl_t k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_double (map_t* x, const fl_t k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_float_ldouble(map_t* x, const fl_t k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_double_pointer(map_t* x, const dbl_t k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_cstring(map_t* x, const dbl_t k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_string (map_t* x, const dbl_t k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_double_array (map_t* x, const dbl_t k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_double_list (map_t* x, const dbl_t k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_double_map (map_t* x, const dbl_t k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_double_vset (map_t* x, const dbl_t k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_double_dict (map_t* x, const dbl_t k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_double_boolean(map_t* x, const dbl_t k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_int8 (map_t* x, const dbl_t k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_int16 (map_t* x, const dbl_t k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_int32 (map_t* x, const dbl_t k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_int64 (map_t* x, const dbl_t k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_uint8 (map_t* x, const dbl_t k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_uint16 (map_t* x, const dbl_t k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_uint32 (map_t* x, const dbl_t k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_uint64 (map_t* x, const dbl_t k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_float (map_t* x, const dbl_t k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_double (map_t* x, const dbl_t k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_double_ldouble(map_t* x, const dbl_t k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_map_update_ldouble_pointer(map_t* x, const ldbl_t k, const void* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_cstring(map_t* x, const ldbl_t k, const char* v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_string (map_t* x, const ldbl_t k, const str_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_ldouble_array (map_t* x, const ldbl_t k, const arr_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_ldouble_list (map_t* x, const ldbl_t k, const list_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_ldouble_map (map_t* x, const ldbl_t k, const map_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_ldouble_vset (map_t* x, const ldbl_t k, const set_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_ldouble_dict (map_t* x, const ldbl_t k, const dict_t* v) { return libcdsb_map_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_map_update_ldouble_boolean(map_t* x, const ldbl_t k, bool v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_int8 (map_t* x, const ldbl_t k, s8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_int16 (map_t* x, const ldbl_t k, s16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_int32 (map_t* x, const ldbl_t k, s32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_int64 (map_t* x, const ldbl_t k, s64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_uint8 (map_t* x, const ldbl_t k, u8_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_uint16 (map_t* x, const ldbl_t k, u16_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_uint32 (map_t* x, const ldbl_t k, u32_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_uint64 (map_t* x, const ldbl_t k, u64_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_float (map_t* x, const ldbl_t k, fl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_double (map_t* x, const ldbl_t k, dbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_map_update_ldouble_ldouble(map_t* x, const ldbl_t k, ldbl_t v) { return libcdsb_map_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } diff --git a/src/map/include.h b/src/map/include.h index fe07b6b..de5185e 100644 --- a/src/map/include.h +++ b/src/map/include.h @@ -1,7 +1,7 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "../../include/extra/map.h" +#include "../../include/map.h" #include "../__internal/assert.h" #include "../__internal/rbtree.h" @@ -19,14 +19,13 @@ typedef struct libcdsb_map_node { vnode_t value; } mnode_t; -static_assert(offsetof(struct libcdsb_rbtree_node, left) == offsetof(struct libcdsb_map_node, left), "Implementation assert"); -static_assert(offsetof(struct libcdsb_rbtree_node, right) == offsetof(struct libcdsb_map_node, right), "Implementation assert"); -static_assert(offsetof(struct libcdsb_rbtree_node, parent) == offsetof(struct libcdsb_map_node, parent), "Implementation assert"); +static_assert(offsetof(struct libcdsb_rbtree_node, left) == offsetof(struct libcdsb_map_node, left), "Implementation assert"); +static_assert(offsetof(struct libcdsb_rbtree_node, right) == offsetof(struct libcdsb_map_node, right), "Implementation assert"); +static_assert(offsetof(struct libcdsb_rbtree_node, parent) == offsetof(struct libcdsb_map_node, parent), "Implementation assert"); static_assert(offsetof(struct libcdsb_rbtree_node, colored) == offsetof(struct libcdsb_map_node, colored), "Implementation assert"); -static_assert(offsetof(struct libcdsb_rbtree_node, value) == offsetof(struct libcdsb_map_node, key), "Implementation assert"); - -static_assert(offsetof(struct libcdsb_set, root) == offsetof(struct libcdsb_map, root), "Implementation assert"); -static_assert(offsetof(struct libcdsb_set, type) == offsetof(struct libcdsb_map, type), "Implementation assert"); +static_assert(offsetof(struct libcdsb_rbtree_node, value) == offsetof(struct libcdsb_map_node, key), "Implementation assert"); +static_assert(offsetof(struct libcdsb_set, root) == offsetof(struct libcdsb_map, root), "Implementation assert"); +static_assert(offsetof(struct libcdsb_set, type) == offsetof(struct libcdsb_map, type), "Implementation assert"); #define mnode_empty ((mnode_t*)LIBCDSB_RBTREE_NODE_EMPTY) #define mnode_create(k, p, c) ((mnode_t*)libcdsb_rbtree_node_create(k, (rbnode_t*)p, c, sizeof(mnode_t))) diff --git a/src/map/memory.c b/src/map/memory.c new file mode 100644 index 0000000..0d8c25a --- /dev/null +++ b/src/map/memory.c @@ -0,0 +1,41 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +void map_init(map_t* x, vtype t) { + x->root = mnode_empty; + x->type = t; +} + + +void map_free(map_t* x) { + mnode_t *t, *c; + + c = x->root; + + while (!mnode_is_empty(x->root)) { + if (!mnode_is_empty(c->left)) { + c = c->left; + } else if (!mnode_is_empty(c->right)) { + c = c->right; + } else if (!mnode_is_root(c)) { + vnode_free(&c->key, x->type); + vnode_free(&c->value, c->type); + + t = c; + c = c->parent; + + if (t == c->left) c->left = mnode_empty; + else c->right = mnode_empty; + + free(t); + } else { + vnode_free(&c->key, x->type); + vnode_free(&c->value, c->type); + x->root = mnode_empty; + } + } + + x->type = 0; +} diff --git a/src/map/modify.c b/src/map/modify.c new file mode 100644 index 0000000..400fa6a --- /dev/null +++ b/src/map/modify.c @@ -0,0 +1,88 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +bool libcdsb_map_update(map_t* x, const void* k, vtype kt, const void* v, vtype vt) { + int cmp; + mnode_t* n; + mnode_t* p; + + if (!mnode_is_empty(n = x->root)) { + do { + p = n; + cmp = vtype_compare(k, kt, vnode_peek(&n->key, kt), kt); + + if (cmp == 0) { + vnode_free(&n->value, n->type); + + n->value = vnode_create(v, vt); + n->type = vt; + + return true; + } + + n = (cmp < 0) ? n->left : n->right; + } while (!mnode_is_empty(n)); + + n = mnode_create(nullptr, p, 1); + + if (cmp < 0) p->left = n; + else p->right = n; + + if (!mnode_is_root(p)) + mnode_fixup(&x->root, n); + + } else n = x->root = mnode_create(nullptr, mnode_empty, 0); + + n->key = vnode_tcreate(x->type, k, kt); + n->value = vnode_create(v, vt); + n->type = vt; + + return false; +} + + +bool libcdsb_map_inject(map_t* x, const void* k, vtype kt, const void* v, vtype vt) { + int cmp; + mnode_t* n; + mnode_t* p; + vnode_t kn; + + vnode_tattach(&kn, x->type, k, kt); + n = x->root; + kt = x->type; + k = vnode_peek(&kn, kt); + + if (!mnode_is_empty(n)) { + do { + p = n; + cmp = vtype_compare(k, kt, vnode_peek(&n->key, kt), kt); + + if (cmp == 0) { + vnode_free(&n->key, x->type); + vnode_free(&n->value, n->type); + + n->key = kn; + vnode_attach(&n->value, v, n->type = vt); + + return true; + } + + n = (cmp < 0) ? n->left : n->right; + } while (!mnode_is_empty(n)); + + n = mnode_create(kn, p, 1); + + if (cmp < 0) p->left = n; + else p->right = n; + + if (!mnode_is_root(p)) + mnode_fixup(&x->root, n); + + } else n = x->root = mnode_create(kn, mnode_empty, 0); + + vnode_attach(&n->value, v, n->type = vt); + + return false; +} diff --git a/tests/src/global/plug.h b/tests/src/global/plug.h index 3692f9c..f9409d8 100644 --- a/tests/src/global/plug.h +++ b/tests/src/global/plug.h @@ -3,9 +3,9 @@ #include "../../../include/extra/string.h" #include "../../../include/array.h" -#include "../../../include/extra/list.h" -#include "../../../include/extra/set.h" -#include "../../../include/extra/map.h" +#include "../../../include/list.h" +#include "../../../include/set.h" +#include "../../../include/map.h" #include "../../../include/extra/dict.h" #include "../../include/random.h" From 7618294078886b9d8e9b1dbaabf9af84059107b9 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Fri, 19 Aug 2022 19:32:52 +0300 Subject: [PATCH 05/18] Refactor dict, add attaching functional --- examples/dict.c | 17 +- include/dict.h | 467 ++-------------------------------------- include/extra/dict.h | 29 --- include/vtype.h | 27 +-- src/dict/access.c | 87 ++++++++ src/dict/base.c | 111 ---------- src/dict/comparison.c | 44 ++++ src/dict/compute.c | 45 ++++ src/dict/copy.c | 68 +++++- src/dict/extra.c | 236 -------------------- src/dict/generics.c | 445 -------------------------------------- src/dict/include.h | 2 +- src/dict/memory.c | 23 ++ src/dict/modify.c | 189 ++++++++++++++++ tests/src/dict/plug.h | 2 +- tests/src/global/plug.h | 2 +- 16 files changed, 503 insertions(+), 1291 deletions(-) delete mode 100644 include/extra/dict.h create mode 100644 src/dict/access.c delete mode 100644 src/dict/base.c create mode 100644 src/dict/comparison.c create mode 100644 src/dict/compute.c delete mode 100644 src/dict/extra.c delete mode 100644 src/dict/generics.c create mode 100644 src/dict/memory.c create mode 100644 src/dict/modify.c diff --git a/examples/dict.c b/examples/dict.c index 1e548a4..c4bebbb 100644 --- a/examples/dict.c +++ b/examples/dict.c @@ -4,7 +4,7 @@ #include #include #include -#include "../include/extra/dict.h" +#include "../include/dict.h" typedef vtype_dict dict_t; @@ -40,20 +40,25 @@ int main(int argc, char** argv) { dict_t dict; vtype_float fl = 0.0; + int a; + vtype_float b; dict_init(&dict); - for (size_t i = 0; i < 28; ++i) { + for (vtype_int32 i = 0; i < 28; ++i) { if (i%2) { - dict_update(&dict, (vtype_float)fl, (vtype_int32)i); + dict_update(&dict, fl, i); } else { - dict_update(&dict, (vtype_int32)i, (vtype_float)fl); + dict_update(&dict, i, fl); } fl += 0.05; } - dict_get(&dict, 14, "Get value:", print_value); - dict_pop(&dict, 0.25, "Pop value:", print_value); + a = 13; + b = 0.25; + + dict_get(&dict, a, "Get value:", print_value); + dict_pop(&dict, b, "Pop value:", print_value); dict_foreach(&dict, "Foreach loop:", print_value); diff --git a/include/dict.h b/include/dict.h index d6f9963..c5a827b 100644 --- a/include/dict.h +++ b/include/dict.h @@ -7,460 +7,33 @@ #ifndef LIBCDSB_DICT_H #define LIBCDSB_DICT_H -/*#####################################################################################################################*/ - typedef int (*dict_access_callback)(const void* key, vtype key_type, void* value, vtype value_type, void* data); +/*#####################################################################################################################*/ + extern void dict_init(vtype_dict* x) Nonnull__(1); -#define dict_pop(x, key, data, callback) _LIBCDSB_Generic (libcdsb_dict, get_by, key)(x, key, data, callback, 1) -#define dict_get(x, key, data, callback) _LIBCDSB_Generic (libcdsb_dict, get_by, key)(x, key, data, callback, 0) -#define dict_update(x, key, value) _LIBCDSB_Generic2(libcdsb_dict, update, key, value)(x, key, value) -#define dict_remove(x, key) dict_pop(x, key, 0, 0) +/*#####################################################################################################################*/ -#define in_dict(x, key) (dict_get(&x, key, 0, 0) == 0) +#define dict_pop(x, key, data, callback) libcdsb_dict_find (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), data, callback, 1) +#define dict_get(x, key, data, callback) libcdsb_dict_find (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), data, callback, 0) +#define dict_update(x, key, value) libcdsb_dict_update (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) +#define dict_inject(x, key, value) libcdsb_dict_inject (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) +#define dict_inject_key(x, key, value) libcdsb_dict_inject_key (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) +#define dict_inject_value(x, key, value) libcdsb_dict_inject_value(x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) +#define dict_foreach(x, data, callback) libcdsb_dict_foreach (x, data, callback, 0) +#define dict_remove(x, key) dict_pop (x, key, 0, 0) + +#define in_dict(x, key) (dict_get(&x, key, 0, 0) == 0) /*#####################################################################################################################*/ -extern int libcdsb_dict_get_by_pointer(vtype_dict* x, const void* key, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_get_by_cstring(vtype_dict* x, const char* key, void* data, dict_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_dict_get_by_string (vtype_dict* x, const vtype_string* key, void* data, dict_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_dict_get_by_array (vtype_dict* x, const vtype_array* key, void* data, dict_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_dict_get_by_list (vtype_dict* x, const vtype_list* key, void* data, dict_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_dict_get_by_map (vtype_dict* x, const vtype_map* key, void* data, dict_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_dict_get_by_vset (vtype_dict* x, const vtype_set* key, void* data, dict_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_dict_get_by_dict (vtype_dict* x, const vtype_dict* key, void* data, dict_access_callback, bool cut) Nonnull__(1,2); -extern int libcdsb_dict_get_by_boolean(vtype_dict* x, vtype_bool key, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_get_by_int8 (vtype_dict* x, vtype_int8 key, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_get_by_int16 (vtype_dict* x, vtype_int16 key, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_get_by_int32 (vtype_dict* x, vtype_int32 key, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_get_by_int64 (vtype_dict* x, vtype_int64 key, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_get_by_uint8 (vtype_dict* x, vtype_uint8 key, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_get_by_uint16 (vtype_dict* x, vtype_uint16 key, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_get_by_uint32 (vtype_dict* x, vtype_uint32 key, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_get_by_uint64 (vtype_dict* x, vtype_uint64 key, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_get_by_float (vtype_dict* x, vtype_float key, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_get_by_double (vtype_dict* x, vtype_double key, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_get_by_ldouble(vtype_dict* x, vtype_ldouble key, void* data, dict_access_callback, bool cut) Nonnull__(1); - -extern bool libcdsb_dict_update_pointer_pointer(vtype_dict* x, const void* key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_pointer_cstring(vtype_dict* x, const void* key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_pointer_string (vtype_dict* x, const void* key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_pointer_array (vtype_dict* x, const void* key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_pointer_list (vtype_dict* x, const void* key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_pointer_map (vtype_dict* x, const void* key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_pointer_vset (vtype_dict* x, const void* key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_pointer_dict (vtype_dict* x, const void* key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_pointer_boolean(vtype_dict* x, const void* key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_pointer_int8 (vtype_dict* x, const void* key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_pointer_int16 (vtype_dict* x, const void* key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_pointer_int32 (vtype_dict* x, const void* key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_pointer_int64 (vtype_dict* x, const void* key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_pointer_uint8 (vtype_dict* x, const void* key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_pointer_uint16 (vtype_dict* x, const void* key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_pointer_uint32 (vtype_dict* x, const void* key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_pointer_uint64 (vtype_dict* x, const void* key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_pointer_float (vtype_dict* x, const void* key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_pointer_double (vtype_dict* x, const void* key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_pointer_ldouble(vtype_dict* x, const void* key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_dict_update_cstring_pointer(vtype_dict* x, const char* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_dict_update_cstring_cstring(vtype_dict* x, const char* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_cstring_string (vtype_dict* x, const char* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_cstring_array (vtype_dict* x, const char* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_cstring_list (vtype_dict* x, const char* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_cstring_map (vtype_dict* x, const char* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_cstring_vset (vtype_dict* x, const char* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_cstring_dict (vtype_dict* x, const char* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_cstring_boolean(vtype_dict* x, const char* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_dict_update_cstring_int8 (vtype_dict* x, const char* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_cstring_int16 (vtype_dict* x, const char* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_cstring_int32 (vtype_dict* x, const char* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_cstring_int64 (vtype_dict* x, const char* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_cstring_uint8 (vtype_dict* x, const char* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_cstring_uint16 (vtype_dict* x, const char* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_cstring_uint32 (vtype_dict* x, const char* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_cstring_uint64 (vtype_dict* x, const char* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_cstring_float (vtype_dict* x, const char* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_dict_update_cstring_double (vtype_dict* x, const char* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_dict_update_cstring_ldouble(vtype_dict* x, const char* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_dict_update_string_pointer(vtype_dict* x, const vtype_string* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_dict_update_string_cstring(vtype_dict* x, const vtype_string* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_string_string (vtype_dict* x, const vtype_string* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_string_array (vtype_dict* x, const vtype_string* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_string_list (vtype_dict* x, const vtype_string* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_string_map (vtype_dict* x, const vtype_string* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_string_vset (vtype_dict* x, const vtype_string* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_string_dict (vtype_dict* x, const vtype_string* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_string_boolean(vtype_dict* x, const vtype_string* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_dict_update_string_int8 (vtype_dict* x, const vtype_string* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_string_int16 (vtype_dict* x, const vtype_string* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_string_int32 (vtype_dict* x, const vtype_string* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_string_int64 (vtype_dict* x, const vtype_string* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_string_uint8 (vtype_dict* x, const vtype_string* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_string_uint16 (vtype_dict* x, const vtype_string* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_string_uint32 (vtype_dict* x, const vtype_string* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_string_uint64 (vtype_dict* x, const vtype_string* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_string_float (vtype_dict* x, const vtype_string* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_dict_update_string_double (vtype_dict* x, const vtype_string* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_dict_update_string_ldouble(vtype_dict* x, const vtype_string* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_dict_update_array_pointer(vtype_dict* x, const vtype_array* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_dict_update_array_cstring(vtype_dict* x, const vtype_array* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_array_string (vtype_dict* x, const vtype_array* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_array_array (vtype_dict* x, const vtype_array* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_array_list (vtype_dict* x, const vtype_array* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_array_map (vtype_dict* x, const vtype_array* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_array_vset (vtype_dict* x, const vtype_array* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_array_dict (vtype_dict* x, const vtype_array* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_array_boolean(vtype_dict* x, const vtype_array* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_dict_update_array_int8 (vtype_dict* x, const vtype_array* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_array_int16 (vtype_dict* x, const vtype_array* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_array_int32 (vtype_dict* x, const vtype_array* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_array_int64 (vtype_dict* x, const vtype_array* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_array_uint8 (vtype_dict* x, const vtype_array* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_array_uint16 (vtype_dict* x, const vtype_array* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_array_uint32 (vtype_dict* x, const vtype_array* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_array_uint64 (vtype_dict* x, const vtype_array* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_array_float (vtype_dict* x, const vtype_array* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_dict_update_array_double (vtype_dict* x, const vtype_array* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_dict_update_array_ldouble(vtype_dict* x, const vtype_array* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_dict_update_list_pointer(vtype_dict* x, const vtype_list* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_dict_update_list_cstring(vtype_dict* x, const vtype_list* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_list_string (vtype_dict* x, const vtype_list* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_list_array (vtype_dict* x, const vtype_list* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_list_list (vtype_dict* x, const vtype_list* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_list_map (vtype_dict* x, const vtype_list* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_list_vset (vtype_dict* x, const vtype_list* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_list_dict (vtype_dict* x, const vtype_list* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_list_boolean(vtype_dict* x, const vtype_list* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_dict_update_list_int8 (vtype_dict* x, const vtype_list* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_list_int16 (vtype_dict* x, const vtype_list* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_list_int32 (vtype_dict* x, const vtype_list* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_list_int64 (vtype_dict* x, const vtype_list* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_list_uint8 (vtype_dict* x, const vtype_list* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_list_uint16 (vtype_dict* x, const vtype_list* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_list_uint32 (vtype_dict* x, const vtype_list* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_list_uint64 (vtype_dict* x, const vtype_list* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_list_float (vtype_dict* x, const vtype_list* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_dict_update_list_double (vtype_dict* x, const vtype_list* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_dict_update_list_ldouble(vtype_dict* x, const vtype_list* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_dict_update_map_pointer(vtype_dict* x, const vtype_map* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_dict_update_map_cstring(vtype_dict* x, const vtype_map* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_map_string (vtype_dict* x, const vtype_map* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_map_array (vtype_dict* x, const vtype_map* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_map_list (vtype_dict* x, const vtype_map* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_map_map (vtype_dict* x, const vtype_map* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_map_vset (vtype_dict* x, const vtype_map* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_map_dict (vtype_dict* x, const vtype_map* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_map_boolean(vtype_dict* x, const vtype_map* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_dict_update_map_int8 (vtype_dict* x, const vtype_map* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_map_int16 (vtype_dict* x, const vtype_map* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_map_int32 (vtype_dict* x, const vtype_map* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_map_int64 (vtype_dict* x, const vtype_map* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_map_uint8 (vtype_dict* x, const vtype_map* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_map_uint16 (vtype_dict* x, const vtype_map* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_map_uint32 (vtype_dict* x, const vtype_map* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_map_uint64 (vtype_dict* x, const vtype_map* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_map_float (vtype_dict* x, const vtype_map* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_dict_update_map_double (vtype_dict* x, const vtype_map* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_dict_update_map_ldouble(vtype_dict* x, const vtype_map* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_dict_update_vset_pointer(vtype_dict* x, const vtype_set* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_dict_update_vset_cstring(vtype_dict* x, const vtype_set* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_vset_string (vtype_dict* x, const vtype_set* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_vset_array (vtype_dict* x, const vtype_set* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_vset_list (vtype_dict* x, const vtype_set* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_vset_map (vtype_dict* x, const vtype_set* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_vset_vset (vtype_dict* x, const vtype_set* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_vset_dict (vtype_dict* x, const vtype_set* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_vset_boolean(vtype_dict* x, const vtype_set* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_dict_update_vset_int8 (vtype_dict* x, const vtype_set* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_vset_int16 (vtype_dict* x, const vtype_set* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_vset_int32 (vtype_dict* x, const vtype_set* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_vset_int64 (vtype_dict* x, const vtype_set* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_vset_uint8 (vtype_dict* x, const vtype_set* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_vset_uint16 (vtype_dict* x, const vtype_set* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_vset_uint32 (vtype_dict* x, const vtype_set* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_vset_uint64 (vtype_dict* x, const vtype_set* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_vset_float (vtype_dict* x, const vtype_set* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_dict_update_vset_double (vtype_dict* x, const vtype_set* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_dict_update_vset_ldouble(vtype_dict* x, const vtype_set* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_dict_update_dict_pointer(vtype_dict* x, const vtype_dict* key, const void* value) Nonnull__(1,2); -extern bool libcdsb_dict_update_dict_cstring(vtype_dict* x, const vtype_dict* key, const char* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_dict_string (vtype_dict* x, const vtype_dict* key, const vtype_string* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_dict_array (vtype_dict* x, const vtype_dict* key, const vtype_array* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_dict_list (vtype_dict* x, const vtype_dict* key, const vtype_list* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_dict_map (vtype_dict* x, const vtype_dict* key, const vtype_map* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_dict_vset (vtype_dict* x, const vtype_dict* key, const vtype_set* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_dict_dict (vtype_dict* x, const vtype_dict* key, const vtype_dict* value) Nonnull__(1,2,3); -extern bool libcdsb_dict_update_dict_boolean(vtype_dict* x, const vtype_dict* key, vtype_bool value) Nonnull__(1,2); -extern bool libcdsb_dict_update_dict_int8 (vtype_dict* x, const vtype_dict* key, vtype_int8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_dict_int16 (vtype_dict* x, const vtype_dict* key, vtype_int16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_dict_int32 (vtype_dict* x, const vtype_dict* key, vtype_int32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_dict_int64 (vtype_dict* x, const vtype_dict* key, vtype_int64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_dict_uint8 (vtype_dict* x, const vtype_dict* key, vtype_uint8 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_dict_uint16 (vtype_dict* x, const vtype_dict* key, vtype_uint16 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_dict_uint32 (vtype_dict* x, const vtype_dict* key, vtype_uint32 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_dict_uint64 (vtype_dict* x, const vtype_dict* key, vtype_uint64 value) Nonnull__(1,2); -extern bool libcdsb_dict_update_dict_float (vtype_dict* x, const vtype_dict* key, vtype_float value) Nonnull__(1,2); -extern bool libcdsb_dict_update_dict_double (vtype_dict* x, const vtype_dict* key, vtype_double value) Nonnull__(1,2); -extern bool libcdsb_dict_update_dict_ldouble(vtype_dict* x, const vtype_dict* key, vtype_ldouble value) Nonnull__(1,2); - -extern bool libcdsb_dict_update_boolean_pointer(vtype_dict* x, vtype_bool key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_boolean_cstring(vtype_dict* x, vtype_bool key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_boolean_string (vtype_dict* x, vtype_bool key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_boolean_array (vtype_dict* x, vtype_bool key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_boolean_list (vtype_dict* x, vtype_bool key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_boolean_map (vtype_dict* x, vtype_bool key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_boolean_vset (vtype_dict* x, vtype_bool key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_boolean_dict (vtype_dict* x, vtype_bool key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_boolean_boolean(vtype_dict* x, vtype_bool key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_boolean_int8 (vtype_dict* x, vtype_bool key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_boolean_int16 (vtype_dict* x, vtype_bool key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_boolean_int32 (vtype_dict* x, vtype_bool key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_boolean_int64 (vtype_dict* x, vtype_bool key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_boolean_uint8 (vtype_dict* x, vtype_bool key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_boolean_uint16 (vtype_dict* x, vtype_bool key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_boolean_uint32 (vtype_dict* x, vtype_bool key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_boolean_uint64 (vtype_dict* x, vtype_bool key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_boolean_float (vtype_dict* x, vtype_bool key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_boolean_double (vtype_dict* x, vtype_bool key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_boolean_ldouble(vtype_dict* x, vtype_bool key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_dict_update_uint8_pointer(vtype_dict* x, vtype_uint8 key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_uint8_cstring(vtype_dict* x, vtype_uint8 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint8_string (vtype_dict* x, vtype_uint8 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint8_array (vtype_dict* x, vtype_uint8 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint8_list (vtype_dict* x, vtype_uint8 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint8_map (vtype_dict* x, vtype_uint8 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint8_vset (vtype_dict* x, vtype_uint8 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint8_dict (vtype_dict* x, vtype_uint8 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint8_boolean(vtype_dict* x, vtype_uint8 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_uint8_int8 (vtype_dict* x, vtype_uint8 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint8_int16 (vtype_dict* x, vtype_uint8 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint8_int32 (vtype_dict* x, vtype_uint8 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint8_int64 (vtype_dict* x, vtype_uint8 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint8_uint8 (vtype_dict* x, vtype_uint8 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint8_uint16 (vtype_dict* x, vtype_uint8 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint8_uint32 (vtype_dict* x, vtype_uint8 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint8_uint64 (vtype_dict* x, vtype_uint8 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint8_float (vtype_dict* x, vtype_uint8 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_uint8_double (vtype_dict* x, vtype_uint8 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_uint8_ldouble(vtype_dict* x, vtype_uint8 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_dict_update_uint16_pointer(vtype_dict* x, vtype_uint16 key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_uint16_cstring(vtype_dict* x, vtype_uint16 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint16_string (vtype_dict* x, vtype_uint16 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint16_array (vtype_dict* x, vtype_uint16 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint16_list (vtype_dict* x, vtype_uint16 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint16_map (vtype_dict* x, vtype_uint16 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint16_vset (vtype_dict* x, vtype_uint16 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint16_dict (vtype_dict* x, vtype_uint16 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint16_boolean(vtype_dict* x, vtype_uint16 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_uint16_int8 (vtype_dict* x, vtype_uint16 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint16_int16 (vtype_dict* x, vtype_uint16 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint16_int32 (vtype_dict* x, vtype_uint16 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint16_int64 (vtype_dict* x, vtype_uint16 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint16_uint8 (vtype_dict* x, vtype_uint16 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint16_uint16 (vtype_dict* x, vtype_uint16 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint16_uint32 (vtype_dict* x, vtype_uint16 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint16_uint64 (vtype_dict* x, vtype_uint16 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint16_float (vtype_dict* x, vtype_uint16 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_uint16_double (vtype_dict* x, vtype_uint16 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_uint16_ldouble(vtype_dict* x, vtype_uint16 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_dict_update_uint32_pointer(vtype_dict* x, vtype_uint32 key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_uint32_cstring(vtype_dict* x, vtype_uint32 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint32_string (vtype_dict* x, vtype_uint32 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint32_array (vtype_dict* x, vtype_uint32 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint32_list (vtype_dict* x, vtype_uint32 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint32_map (vtype_dict* x, vtype_uint32 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint32_vset (vtype_dict* x, vtype_uint32 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint32_dict (vtype_dict* x, vtype_uint32 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint32_boolean(vtype_dict* x, vtype_uint32 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_uint32_int8 (vtype_dict* x, vtype_uint32 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint32_int16 (vtype_dict* x, vtype_uint32 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint32_int32 (vtype_dict* x, vtype_uint32 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint32_int64 (vtype_dict* x, vtype_uint32 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint32_uint8 (vtype_dict* x, vtype_uint32 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint32_uint16 (vtype_dict* x, vtype_uint32 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint32_uint32 (vtype_dict* x, vtype_uint32 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint32_uint64 (vtype_dict* x, vtype_uint32 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint32_float (vtype_dict* x, vtype_uint32 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_uint32_double (vtype_dict* x, vtype_uint32 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_uint32_ldouble(vtype_dict* x, vtype_uint32 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_dict_update_uint64_pointer(vtype_dict* x, vtype_uint64 key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_uint64_cstring(vtype_dict* x, vtype_uint64 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint64_string (vtype_dict* x, vtype_uint64 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint64_array (vtype_dict* x, vtype_uint64 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint64_list (vtype_dict* x, vtype_uint64 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint64_map (vtype_dict* x, vtype_uint64 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint64_vset (vtype_dict* x, vtype_uint64 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint64_dict (vtype_dict* x, vtype_uint64 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_uint64_boolean(vtype_dict* x, vtype_uint64 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_uint64_int8 (vtype_dict* x, vtype_uint64 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint64_int16 (vtype_dict* x, vtype_uint64 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint64_int32 (vtype_dict* x, vtype_uint64 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint64_int64 (vtype_dict* x, vtype_uint64 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint64_uint8 (vtype_dict* x, vtype_uint64 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint64_uint16 (vtype_dict* x, vtype_uint64 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint64_uint32 (vtype_dict* x, vtype_uint64 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint64_uint64 (vtype_dict* x, vtype_uint64 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_uint64_float (vtype_dict* x, vtype_uint64 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_uint64_double (vtype_dict* x, vtype_uint64 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_uint64_ldouble(vtype_dict* x, vtype_uint64 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_dict_update_int8_pointer(vtype_dict* x, vtype_int8 key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_int8_cstring(vtype_dict* x, vtype_int8 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int8_string (vtype_dict* x, vtype_int8 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int8_array (vtype_dict* x, vtype_int8 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int8_list (vtype_dict* x, vtype_int8 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int8_map (vtype_dict* x, vtype_int8 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int8_vset (vtype_dict* x, vtype_int8 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int8_dict (vtype_dict* x, vtype_int8 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int8_boolean(vtype_dict* x, vtype_int8 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_int8_int8 (vtype_dict* x, vtype_int8 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_int8_int16 (vtype_dict* x, vtype_int8 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_int8_int32 (vtype_dict* x, vtype_int8 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_int8_int64 (vtype_dict* x, vtype_int8 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_int8_uint8 (vtype_dict* x, vtype_int8 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_int8_uint16 (vtype_dict* x, vtype_int8 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_int8_uint32 (vtype_dict* x, vtype_int8 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_int8_uint64 (vtype_dict* x, vtype_int8 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_int8_float (vtype_dict* x, vtype_int8 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_int8_double (vtype_dict* x, vtype_int8 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_int8_ldouble(vtype_dict* x, vtype_int8 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_dict_update_int16_pointer(vtype_dict* x, vtype_int16 key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_int16_cstring(vtype_dict* x, vtype_int16 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int16_string (vtype_dict* x, vtype_int16 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int16_array (vtype_dict* x, vtype_int16 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int16_list (vtype_dict* x, vtype_int16 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int16_map (vtype_dict* x, vtype_int16 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int16_vset (vtype_dict* x, vtype_int16 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int16_dict (vtype_dict* x, vtype_int16 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int16_boolean(vtype_dict* x, vtype_int16 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_int16_int8 (vtype_dict* x, vtype_int16 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_int16_int16 (vtype_dict* x, vtype_int16 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_int16_int32 (vtype_dict* x, vtype_int16 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_int16_int64 (vtype_dict* x, vtype_int16 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_int16_uint8 (vtype_dict* x, vtype_int16 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_int16_uint16 (vtype_dict* x, vtype_int16 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_int16_uint32 (vtype_dict* x, vtype_int16 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_int16_uint64 (vtype_dict* x, vtype_int16 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_int16_float (vtype_dict* x, vtype_int16 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_int16_double (vtype_dict* x, vtype_int16 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_int16_ldouble(vtype_dict* x, vtype_int16 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_dict_update_int32_pointer(vtype_dict* x, vtype_int32 key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_int32_cstring(vtype_dict* x, vtype_int32 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int32_string (vtype_dict* x, vtype_int32 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int32_array (vtype_dict* x, vtype_int32 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int32_list (vtype_dict* x, vtype_int32 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int32_map (vtype_dict* x, vtype_int32 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int32_vset (vtype_dict* x, vtype_int32 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int32_dict (vtype_dict* x, vtype_int32 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int32_boolean(vtype_dict* x, vtype_int32 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_int32_int8 (vtype_dict* x, vtype_int32 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_int32_int16 (vtype_dict* x, vtype_int32 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_int32_int32 (vtype_dict* x, vtype_int32 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_int32_int64 (vtype_dict* x, vtype_int32 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_int32_uint8 (vtype_dict* x, vtype_int32 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_int32_uint16 (vtype_dict* x, vtype_int32 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_int32_uint32 (vtype_dict* x, vtype_int32 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_int32_uint64 (vtype_dict* x, vtype_int32 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_int32_float (vtype_dict* x, vtype_int32 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_int32_double (vtype_dict* x, vtype_int32 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_int32_ldouble(vtype_dict* x, vtype_int32 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_dict_update_int64_pointer(vtype_dict* x, vtype_int64 key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_int64_cstring(vtype_dict* x, vtype_int64 key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int64_string (vtype_dict* x, vtype_int64 key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int64_array (vtype_dict* x, vtype_int64 key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int64_list (vtype_dict* x, vtype_int64 key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int64_map (vtype_dict* x, vtype_int64 key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int64_vset (vtype_dict* x, vtype_int64 key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int64_dict (vtype_dict* x, vtype_int64 key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_int64_boolean(vtype_dict* x, vtype_int64 key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_int64_int8 (vtype_dict* x, vtype_int64 key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_int64_int16 (vtype_dict* x, vtype_int64 key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_int64_int32 (vtype_dict* x, vtype_int64 key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_int64_int64 (vtype_dict* x, vtype_int64 key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_int64_uint8 (vtype_dict* x, vtype_int64 key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_int64_uint16 (vtype_dict* x, vtype_int64 key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_int64_uint32 (vtype_dict* x, vtype_int64 key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_int64_uint64 (vtype_dict* x, vtype_int64 key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_int64_float (vtype_dict* x, vtype_int64 key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_int64_double (vtype_dict* x, vtype_int64 key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_int64_ldouble(vtype_dict* x, vtype_int64 key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_dict_update_float_pointer(vtype_dict* x, vtype_float key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_float_cstring(vtype_dict* x, vtype_float key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_float_string (vtype_dict* x, vtype_float key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_float_array (vtype_dict* x, vtype_float key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_float_list (vtype_dict* x, vtype_float key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_float_map (vtype_dict* x, vtype_float key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_float_vset (vtype_dict* x, vtype_float key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_float_dict (vtype_dict* x, vtype_float key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_float_boolean(vtype_dict* x, vtype_float key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_float_int8 (vtype_dict* x, vtype_float key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_float_int16 (vtype_dict* x, vtype_float key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_float_int32 (vtype_dict* x, vtype_float key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_float_int64 (vtype_dict* x, vtype_float key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_float_uint8 (vtype_dict* x, vtype_float key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_float_uint16 (vtype_dict* x, vtype_float key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_float_uint32 (vtype_dict* x, vtype_float key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_float_uint64 (vtype_dict* x, vtype_float key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_float_float (vtype_dict* x, vtype_float key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_float_double (vtype_dict* x, vtype_float key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_float_ldouble(vtype_dict* x, vtype_float key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_dict_update_double_pointer(vtype_dict* x, vtype_double key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_double_cstring(vtype_dict* x, vtype_double key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_double_string (vtype_dict* x, vtype_double key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_double_array (vtype_dict* x, vtype_double key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_double_list (vtype_dict* x, vtype_double key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_double_map (vtype_dict* x, vtype_double key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_double_vset (vtype_dict* x, vtype_double key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_double_dict (vtype_dict* x, vtype_double key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_double_boolean(vtype_dict* x, vtype_double key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_double_int8 (vtype_dict* x, vtype_double key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_double_int16 (vtype_dict* x, vtype_double key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_double_int32 (vtype_dict* x, vtype_double key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_double_int64 (vtype_dict* x, vtype_double key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_double_uint8 (vtype_dict* x, vtype_double key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_double_uint16 (vtype_dict* x, vtype_double key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_double_uint32 (vtype_dict* x, vtype_double key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_double_uint64 (vtype_dict* x, vtype_double key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_double_float (vtype_dict* x, vtype_double key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_double_double (vtype_dict* x, vtype_double key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_double_ldouble(vtype_dict* x, vtype_double key, vtype_ldouble value) Nonnull__(1); - -extern bool libcdsb_dict_update_ldouble_pointer(vtype_dict* x, vtype_ldouble key, const void* value) Nonnull__(1); -extern bool libcdsb_dict_update_ldouble_cstring(vtype_dict* x, vtype_ldouble key, const char* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_ldouble_string (vtype_dict* x, vtype_ldouble key, const vtype_string* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_ldouble_array (vtype_dict* x, vtype_ldouble key, const vtype_array* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_ldouble_list (vtype_dict* x, vtype_ldouble key, const vtype_list* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_ldouble_map (vtype_dict* x, vtype_ldouble key, const vtype_map* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_ldouble_vset (vtype_dict* x, vtype_ldouble key, const vtype_set* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_ldouble_dict (vtype_dict* x, vtype_ldouble key, const vtype_dict* value) Nonnull__(1,3); -extern bool libcdsb_dict_update_ldouble_boolean(vtype_dict* x, vtype_ldouble key, vtype_bool value) Nonnull__(1); -extern bool libcdsb_dict_update_ldouble_int8 (vtype_dict* x, vtype_ldouble key, vtype_int8 value) Nonnull__(1); -extern bool libcdsb_dict_update_ldouble_int16 (vtype_dict* x, vtype_ldouble key, vtype_int16 value) Nonnull__(1); -extern bool libcdsb_dict_update_ldouble_int32 (vtype_dict* x, vtype_ldouble key, vtype_int32 value) Nonnull__(1); -extern bool libcdsb_dict_update_ldouble_int64 (vtype_dict* x, vtype_ldouble key, vtype_int64 value) Nonnull__(1); -extern bool libcdsb_dict_update_ldouble_uint8 (vtype_dict* x, vtype_ldouble key, vtype_uint8 value) Nonnull__(1); -extern bool libcdsb_dict_update_ldouble_uint16 (vtype_dict* x, vtype_ldouble key, vtype_uint16 value) Nonnull__(1); -extern bool libcdsb_dict_update_ldouble_uint32 (vtype_dict* x, vtype_ldouble key, vtype_uint32 value) Nonnull__(1); -extern bool libcdsb_dict_update_ldouble_uint64 (vtype_dict* x, vtype_ldouble key, vtype_uint64 value) Nonnull__(1); -extern bool libcdsb_dict_update_ldouble_float (vtype_dict* x, vtype_ldouble key, vtype_float value) Nonnull__(1); -extern bool libcdsb_dict_update_ldouble_double (vtype_dict* x, vtype_ldouble key, vtype_double value) Nonnull__(1); -extern bool libcdsb_dict_update_ldouble_ldouble(vtype_dict* x, vtype_ldouble key, vtype_ldouble value) Nonnull__(1); +extern bool libcdsb_dict_update (vtype_dict* x, const void* key, vtype key_type, const void* value, vtype value_type) Nonnull__(1); +extern bool libcdsb_dict_inject (vtype_dict* x, const void* key, vtype key_type, const void* value, vtype value_type) Nonnull__(1); +extern bool libcdsb_dict_inject_key (vtype_dict* x, const void* key, vtype key_type, const void* value, vtype value_type) Nonnull__(1); +extern bool libcdsb_dict_inject_value (vtype_dict* x, const void* key, vtype key_type, const void* value, vtype value_type) Nonnull__(1); +extern int libcdsb_dict_find (vtype_dict* x, const void* key, vtype key_type, void* data, dict_access_callback, bool cut) Nonnull__(1); +extern int libcdsb_dict_foreach (vtype_dict* x, void* data, dict_access_callback, bool flush) Nonnull__(1,3); +extern bool libcdsb_dict_shrink_to_fit(vtype_dict* x) Nonnull__(1); #endif /* LIBCDSB_DICT_H */ diff --git a/include/extra/dict.h b/include/extra/dict.h deleted file mode 100644 index 1f8edc5..0000000 --- a/include/extra/dict.h +++ /dev/null @@ -1,29 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "../dict.h" - -#ifndef LIBCDSB_EXTRA_DICT_H -#define LIBCDSB_EXTRA_DICT_H - -#define dict_foreach(x, data, callback) libcdsb_dict_foreach(x, data, callback, 0) - -extern bool libcdsb_dict_update (vtype_dict* x, const void* key, vtype key_type, const void* value, vtype value_type) Nonnull__(1); -extern int libcdsb_dict_find (vtype_dict* x, const void* key, vtype key_type, void* data, dict_access_callback, bool cut) Nonnull__(1); -extern int libcdsb_dict_foreach (vtype_dict* x, void* data, dict_access_callback, bool flush) Nonnull__(1,3); -extern bool libcdsb_dict_shrink_to_fit(vtype_dict* x) Nonnull__(1); - -#endif /* LIBCDSB_EXTRA_DICT_H */ - -#if defined(LIBCDSB_LIST_H) && !defined(LIBCDSB_EXTRA_DICT_H_EXT) -#define LIBCDSB_EXTRA_DICT_H_EXT - -#define dict_copy_keys libcdsb_dict_copy_keys -#define dict_duplicate_keys libcdsb_dict_duplicate_keys -#define dict_init_keys libcdsb_dict_init_keys - -extern vtype_list libcdsb_dict_copy_keys (const vtype_dict* s) Nonnull__(1); -extern vtype_list* libcdsb_dict_duplicate_keys(const vtype_dict* s) Nonnull__(1); -extern void libcdsb_dict_init_keys (vtype_list* x, const vtype_dict* s) Nonnull__(1,2); - -#endif /* LIBCDSB_EXTRA_DICT_H_EXT */ diff --git a/include/vtype.h b/include/vtype.h index 19fbee9..e3328f8 100644 --- a/include/vtype.h +++ b/include/vtype.h @@ -86,20 +86,22 @@ extern int map_compare (const vtype_map* s0, const vtype_map* s1) Pure__ extern int vset_compare (const vtype_set* s0, const vtype_set* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); extern int dict_compare (const vtype_dict* s0, const vtype_dict* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -extern vtype_string string_copy (const vtype_string* s) Pure__ Warn_unused_result__ Nonnull__(1); -extern vtype_array array_copy (const vtype_array* s) Pure__ Warn_unused_result__ Nonnull__(1); -extern vtype_list list_copy (const vtype_list* s) Pure__ Warn_unused_result__ Nonnull__(1); -extern vtype_map map_copy (const vtype_map* s) Pure__ Warn_unused_result__ Nonnull__(1); -extern vtype_set vset_copy (const vtype_set* s) Pure__ Warn_unused_result__ Nonnull__(1); -extern vtype_dict dict_copy (const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_string string_copy (const vtype_string* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_array array_copy (const vtype_array* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_list list_copy (const vtype_list* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_map map_copy (const vtype_map* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_set vset_copy (const vtype_set* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_dict dict_copy (const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_list dict_copy_keys(const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); #define map_copy_keys(s) vset_copy((vtype_set*)s) -extern vtype_string* string_duplicate (const vtype_string* s) Warn_unused_result__ Nonnull__(1); -extern vtype_array* array_duplicate (const vtype_array* s) Warn_unused_result__ Nonnull__(1); -extern vtype_list* list_duplicate (const vtype_list* s) Warn_unused_result__ Nonnull__(1); -extern vtype_map* map_duplicate (const vtype_map* s) Warn_unused_result__ Nonnull__(1); -extern vtype_set* vset_duplicate (const vtype_set* s) Warn_unused_result__ Nonnull__(1); -extern vtype_dict* dict_duplicate (const vtype_dict* s) Warn_unused_result__ Nonnull__(1); +extern vtype_string* string_duplicate (const vtype_string* s) Warn_unused_result__ Nonnull__(1); +extern vtype_array* array_duplicate (const vtype_array* s) Warn_unused_result__ Nonnull__(1); +extern vtype_list* list_duplicate (const vtype_list* s) Warn_unused_result__ Nonnull__(1); +extern vtype_map* map_duplicate (const vtype_map* s) Warn_unused_result__ Nonnull__(1); +extern vtype_set* vset_duplicate (const vtype_set* s) Warn_unused_result__ Nonnull__(1); +extern vtype_dict* dict_duplicate (const vtype_dict* s) Warn_unused_result__ Nonnull__(1); +extern vtype_list* dict_duplicate_keys(const vtype_dict* s) Warn_unused_result__ Nonnull__(1); #define map_duplicate_keys(s) vset_duplicate((vtype_set*)s) extern void string_copy_init (vtype_string* x, const vtype_string* s) Nonnull__(1,2); @@ -108,6 +110,7 @@ extern void list_copy_init (vtype_list* x, const vtype_list* s) Nonnull__ extern void map_copy_init (vtype_map* x, const vtype_map* s) Nonnull__(1,2); extern void vset_copy_init (vtype_set* x, const vtype_set* s) Nonnull__(1,2); extern void dict_copy_init (vtype_dict* x, const vtype_dict* s) Nonnull__(1,2); +extern void dict_init_keys (vtype_list* x, const vtype_dict* s) Nonnull__(1,2); #define map_copy_init_keys(x, s) vset_duplicate(x, (vtype_set*)s) extern void string_free(vtype_string* x); diff --git a/src/dict/access.c b/src/dict/access.c new file mode 100644 index 0000000..596fbb6 --- /dev/null +++ b/src/dict/access.c @@ -0,0 +1,87 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +int libcdsb_dict_find(dict_t* x, const void* k, vtype t, void* dt, dict_access_callback callback, bool cut) { + dnode_t *c, **p; + int r; + void* key; + + if (x->capacity) { + c = *(p = x->nodes + (vtype_hash(k, t) % x->capacity)); + + while (!is_null(c)) { + key = vnode_peek(&c->key, c->key_type); + if (vtype_compare(k, t, key, c->key_type) == 0) { + r = (callback) ? callback(key, c->key_type, vnode_peek(&c->value, c->value_type), c->value_type, dt) : 0; + + if (cut) { + *p = c->prev; + vnode_free(&c->key, c->key_type); + vnode_free(&c->value, c->value_type); + free(c); + --x->size; + } + + return r; + } else c = *(p = &c->prev); + } + } + + return -1; +} + + +int libcdsb_dict_foreach(dict_t* x, void* dt, dict_access_callback callback, bool flush) { + dnode_t *c; + ssize_t i; + int r; + + r = 0; + i = x->capacity; + + while (i) { + c = x->nodes[--i]; + + while (!is_null(c)) { + r = callback(vnode_peek(&c->key, c->key_type), c->key_type, + vnode_peek(&c->value, c->value_type), c->value_type, dt); + + c = c->prev; + + if (r) { + if (!flush) goto end_; + else goto flush_loop_; + } else if (flush) { + vnode_free(&x->nodes[i]->key, x->nodes[i]->key_type); + vnode_free(&x->nodes[i]->value, x->nodes[i]->value_type); + free(x->nodes[i]); + + x->nodes[i] = c; + } + } + } + + if (flush) { + while (i) { + --i; + + while (!is_null(x->nodes[i])) { flush_loop_: + vnode_free(&x->nodes[i]->key, x->nodes[i]->key_type); + vnode_free(&x->nodes[i]->value, x->nodes[i]->value_type); + + c = x->nodes[i]->prev; + free(x->nodes[i]); + + x->nodes[i] = c; + } + } + + free(x->nodes); + memset(x, 0, sizeof(*x)); + } + + end_: + return r; +} diff --git a/src/dict/base.c b/src/dict/base.c deleted file mode 100644 index 76f7632..0000000 --- a/src/dict/base.c +++ /dev/null @@ -1,111 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - -/*#####################################################################################################################*/ - -hash_t dict_hash(const dict_t* s) { - dnode_t *min, *max; - size_t i; - dnode_t *c; - hash_t hash; - - if (!s->size) - return 0; - - min = max = nullptr; - i = s->capacity; - - while (i--) { - c = s->nodes[i]; - - while (!is_null(c)) { - if (is_null(min) || vnode_compare(&c->key, c->key_type, &min->key, min->key_type) < 0) min = c; - if (is_null(max) || vnode_compare(&c->key, c->key_type, &max->key, max->key_type) > 0) max = c; - - c = c->prev; - } - } - - hash = vnode_hash(&min->key, min->key_type); - - if (s->size > 0) - hash += vnode_hash(&max->key, max->key_type); - - return (hash ^ s->size) + VTYPE_DICT; -} - - -void dict_init(dict_t* x) { - memset(x, 0, sizeof(*x)); -} - -/*#####################################################################################################################*/ - -void dict_free(dict_t* x) { - - while (x->capacity--) { - while (!is_null(x->nodes[x->capacity])) { - vnode_free(&x->nodes[x->capacity]->key, x->nodes[x->capacity]->key_type); - vnode_free(&x->nodes[x->capacity]->value, x->nodes[x->capacity]->value_type); - - x->nodes[x->capacity] = x->nodes[x->capacity]->prev; - } - } - - free(x->nodes); - memset(x, 0, sizeof(*x)); -} - -/*#####################################################################################################################*/ - -size_t dict_size(const dict_t* x) { - return x->size; -} - -size_t dict_capacity(const dict_t* x) { - return x->capacity; -} - -/*#####################################################################################################################*/ - -int dict_compare(const dict_t* s0, const dict_t* s1) { - dnode_t *c0, *c1; - size_t i; - int cmp; - - if (s0 == s1) - return 0; - - if (s0->size != s1->size) - return s0->size < s1->size ? -1 : 1; - - i = s0->capacity; - - while (i--) { - c0 = s0->nodes[i]; - - while (!is_null(c0)) { - - c1 = s1->nodes[vnode_hash(&c0->key, c0->key_type) % s1->capacity]; - cmp = -1; - - while (!is_null(c1)) { - if ((cmp = vnode_compare(&c0->key, c0->key_type, &c1->key, c1->key_type) == 0)) { - - cmp = vnode_compare(&c0->value, c0->value_type, &c1->value, c1->value_type); - break; - } - - c1 = c1->prev; - } - - if (cmp) return cmp; - - c0 = c0->prev; - } - } - - return 0; -} diff --git a/src/dict/comparison.c b/src/dict/comparison.c new file mode 100644 index 0000000..346651b --- /dev/null +++ b/src/dict/comparison.c @@ -0,0 +1,44 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +int dict_compare(const dict_t* s0, const dict_t* s1) { + dnode_t *c0, *c1; + size_t i; + int cmp; + + if (s0 == s1) + return 0; + + if (s0->size != s1->size) + return s0->size < s1->size ? -1 : 1; + + i = s0->capacity; + + while (i--) { + c0 = s0->nodes[i]; + + while (!is_null(c0)) { + + c1 = s1->nodes[vnode_hash(&c0->key, c0->key_type) % s1->capacity]; + cmp = -1; + + while (!is_null(c1)) { + if ((cmp = vnode_compare(&c0->key, c0->key_type, &c1->key, c1->key_type) == 0)) { + + cmp = vnode_compare(&c0->value, c0->value_type, &c1->value, c1->value_type); + break; + } + + c1 = c1->prev; + } + + if (cmp) return cmp; + + c0 = c0->prev; + } + } + + return 0; +} diff --git a/src/dict/compute.c b/src/dict/compute.c new file mode 100644 index 0000000..2750de4 --- /dev/null +++ b/src/dict/compute.c @@ -0,0 +1,45 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +size_t dict_size(const dict_t* x) { + return x->size; +} + + +size_t dict_capacity(const dict_t* x) { + return x->capacity; +} + + +hash_t dict_hash(const dict_t* s) { + dnode_t *min, *max; + size_t i; + dnode_t *c; + hash_t hash; + + if (!s->size) + return 0; + + min = max = nullptr; + i = s->capacity; + + while (i--) { + c = s->nodes[i]; + + while (!is_null(c)) { + if (is_null(min) || vnode_compare(&c->key, c->key_type, &min->key, min->key_type) < 0) min = c; + if (is_null(max) || vnode_compare(&c->key, c->key_type, &max->key, max->key_type) > 0) max = c; + + c = c->prev; + } + } + + hash = vnode_hash(&min->key, min->key_type); + + if (s->size > 0) + hash += vnode_hash(&max->key, max->key_type); + + return (hash ^ s->size) + VTYPE_DICT; +} diff --git a/src/dict/copy.c b/src/dict/copy.c index 35931a7..a9a6148 100644 --- a/src/dict/copy.c +++ b/src/dict/copy.c @@ -1,10 +1,9 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ +#include "../../include/list.h" #include "include.h" -/*#####################################################################################################################*/ - static inline dnode_t* dnode_duplicate(const dnode_t* s, dnode_t* p) { dnode_t* x = malloc(sizeof(*x)); @@ -80,3 +79,68 @@ void dict_copy_init(dict_t* x, const dict_t* s) { } } } + + +vtype_list libcdsb_dict_copy_keys(const vtype_dict* s) { + vtype_list x; + dnode_t *c; + size_t i; + + i = s->capacity; + + list_init(&x); + + while (i--) { + c = s->nodes[i]; + + while (!is_null(c)) { + libcdsb_list_insert(&x, -1, vnode_peek(&c->key, c->key_type), c->key_type, 1); + c = c->prev; + } + } + + return x; +} + + +vtype_list* libcdsb_dict_duplicate_keys(const vtype_dict* s) { + vtype_list* x; + dnode_t *c; + size_t i; + + x = malloc(sizeof(*x)); + i = s->capacity; + + list_init(x); + + while (i--) { + c = s->nodes[i]; + + while (!is_null(c)) { + libcdsb_list_insert(x, -1, vnode_peek(&c->key, c->key_type), c->key_type, 1); + c = c->prev; + } + } + + return x; +} + + +void libcdsb_dict_init_keys(vtype_list* x, const vtype_dict* s) { + dnode_t *c; + size_t i; + + x = malloc(sizeof(*x)); + i = s->capacity; + + list_init(x); + + while (i--) { + c = s->nodes[i]; + + while (!is_null(c)) { + libcdsb_list_insert(x, -1, vnode_peek(&c->key, c->key_type), c->key_type, 1); + c = c->prev; + } + } +} diff --git a/src/dict/extra.c b/src/dict/extra.c deleted file mode 100644 index 5732977..0000000 --- a/src/dict/extra.c +++ /dev/null @@ -1,236 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "../../include/extra/list.h" -#include "include.h" - -/*#####################################################################################################################*/ - -static void dict_rehash(dict_t* s, size_t capacity) { - dnode_t **nodes, *c, *n, **p; - size_t i; - - i = s->capacity; - nodes = calloc(sizeof(*nodes), capacity); - - while (i--) { - c = s->nodes[i]; - - while (!is_null(c)) { - p = nodes + (vnode_hash(&c->key, c->key_type) % capacity); - n = c->prev; - c->prev = *p; - - *p = c; - c = n; - } - } - - free(s->nodes); - s->nodes = nodes; - s->capacity = capacity; -} - -/*#####################################################################################################################*/ - -bool libcdsb_dict_shrink_to_fit(dict_t* s) { - - size_t capacity; - - capacity = (s->size / CAPACITY_BLOCK) + 1; - capacity *= CAPACITY_BLOCK; - - while (((double)s->size / capacity) > 0.65) - capacity += CAPACITY_BLOCK; - - if (capacity >= s->capacity) - return false; - - dict_rehash(s, capacity); - - return true; -} - - -bool libcdsb_dict_update(dict_t* x, const void* k, vtype kt, const void* v, vtype vt) { - dnode_t *c, **p; - - if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX) - dict_rehash(x, x->capacity + CAPACITY_BLOCK); - - c = *(p = x->nodes + (vtype_hash(k, kt) % x->capacity)); - - while (!is_null(c)) { - if (vtype_compare(k, kt, vnode_peek(&c->key, c->key_type), c->key_type) == 0) { - vnode_free(&c->value, c->value_type); - - c->value = vnode_create(v, vt); - c->value_type = vt; - - return true; - } else c = c->prev; - } - - c = malloc(sizeof(*c)); - - c->prev = *p; - c->key = vnode_create(k, kt); - c->value = vnode_create(v, vt); - c->key_type = kt; - c->value_type = vt; - - *p = c; - ++x->size; - - return false; -} - - -int libcdsb_dict_find(dict_t* x, const void* k, vtype t, void* dt, dict_access_callback callback, bool cut) { - dnode_t *c, **p; - int r; - void* key; - - if (x->capacity) { - c = *(p = x->nodes + (vtype_hash(k, t) % x->capacity)); - - while (!is_null(c)) { - key = vnode_peek(&c->key, c->key_type); - if (vtype_compare(k, t, key, c->key_type) == 0) { - r = (callback) ? callback(key, c->key_type, vnode_peek(&c->value, c->value_type), c->value_type, dt) : 0; - - if (cut) { - *p = c->prev; - vnode_free(&c->key, c->key_type); - vnode_free(&c->value, c->value_type); - free(c); - --x->size; - } - - return r; - } else c = *(p = &c->prev); - } - } - - return -1; -} - - -int libcdsb_dict_foreach(dict_t* x, void* dt, dict_access_callback callback, bool flush) { - dnode_t *c; - ssize_t i; - int r; - - r = 0; - i = x->capacity; - - while (i) { - c = x->nodes[--i]; - - while (!is_null(c)) { - r = callback(vnode_peek(&c->key, c->key_type), c->key_type, - vnode_peek(&c->value, c->value_type), c->value_type, dt); - - c = c->prev; - - if (r) { - if (!flush) goto end_; - else goto flush_loop_; - } else if (flush) { - vnode_free(&x->nodes[i]->key, x->nodes[i]->key_type); - vnode_free(&x->nodes[i]->value, x->nodes[i]->value_type); - free(x->nodes[i]); - - x->nodes[i] = c; - } - } - } - - if (flush) { - while (i) { - --i; - - while (!is_null(x->nodes[i])) { flush_loop_: - vnode_free(&x->nodes[i]->key, x->nodes[i]->key_type); - vnode_free(&x->nodes[i]->value, x->nodes[i]->value_type); - - c = x->nodes[i]->prev; - free(x->nodes[i]); - - x->nodes[i] = c; - } - } - - free(x->nodes); - memset(x, 0, sizeof(*x)); - } - - end_: - return r; -} - -/*#####################################################################################################################*/ - -vtype_list libcdsb_dict_copy_keys(const vtype_dict* s) { - vtype_list x; - dnode_t *c; - size_t i; - - i = s->capacity; - - list_init(&x); - - while (i--) { - c = s->nodes[i]; - - while (!is_null(c)) { - libcdsb_list_update(&x, -1, vnode_peek(&c->key, c->key_type), c->key_type, 1); - c = c->prev; - } - } - - return x; -} - - -vtype_list* libcdsb_dict_duplicate_keys(const vtype_dict* s) { - vtype_list* x; - dnode_t *c; - size_t i; - - x = malloc(sizeof(*x)); - i = s->capacity; - - list_init(x); - - while (i--) { - c = s->nodes[i]; - - while (!is_null(c)) { - libcdsb_list_update(x, -1, vnode_peek(&c->key, c->key_type), c->key_type, 1); - c = c->prev; - } - } - - return x; -} - - -void libcdsb_dict_init_keys(vtype_list* x, const vtype_dict* s) { - dnode_t *c; - size_t i; - - x = malloc(sizeof(*x)); - i = s->capacity; - - list_init(x); - - while (i--) { - c = s->nodes[i]; - - while (!is_null(c)) { - libcdsb_list_update(x, -1, vnode_peek(&c->key, c->key_type), c->key_type, 1); - c = c->prev; - } - } -} diff --git a/src/dict/generics.c b/src/dict/generics.c deleted file mode 100644 index 41ab6b0..0000000 --- a/src/dict/generics.c +++ /dev/null @@ -1,445 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - -int libcdsb_dict_find_by_pointer(dict_t* x, const void* k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_cstring(dict_t* x, const char* k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_string (dict_t* x, const str_t* k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, k, vtypeof( k), _, cb, cut); } -int libcdsb_dict_find_by_array (dict_t* x, const arr_t* k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, k, vtypeof( k), _, cb, cut); } -int libcdsb_dict_find_by_list (dict_t* x, const list_t* k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, k, vtypeof( k), _, cb, cut); } -int libcdsb_dict_find_by_map (dict_t* x, const map_t* k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, k, vtypeof( k), _, cb, cut); } -int libcdsb_dict_find_by_vset (dict_t* x, const set_t* k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, k, vtypeof( k), _, cb, cut); } -int libcdsb_dict_find_by_dict (dict_t* x, const dict_t* k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, k, vtypeof( k), _, cb, cut); } -int libcdsb_dict_find_by_boolean(dict_t* x, bool k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_int8 (dict_t* x, s8_t k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_int16 (dict_t* x, s16_t k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_int32 (dict_t* x, s32_t k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_int64 (dict_t* x, s64_t k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_uint8 (dict_t* x, u8_t k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_uint16 (dict_t* x, u16_t k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_uint32 (dict_t* x, u32_t k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_uint64 (dict_t* x, u64_t k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_float (dict_t* x, fl_t k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_double (dict_t* x, dbl_t k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } -int libcdsb_dict_find_by_ldouble(dict_t* x, ldbl_t k, void* _, dict_access_callback cb, bool cut) { return libcdsb_dict_find(x, &k, vtypeof(&k), _, cb, cut); } - -bool libcdsb_dict_update_pointer_pointer(dict_t* x, const void* k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_cstring(dict_t* x, const void* k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_string (dict_t* x, const void* k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_pointer_array (dict_t* x, const void* k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_pointer_list (dict_t* x, const void* k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_pointer_map (dict_t* x, const void* k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_pointer_vset (dict_t* x, const void* k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_pointer_dict (dict_t* x, const void* k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_pointer_boolean(dict_t* x, const void* k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_int8 (dict_t* x, const void* k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_int16 (dict_t* x, const void* k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_int32 (dict_t* x, const void* k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_int64 (dict_t* x, const void* k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_uint8 (dict_t* x, const void* k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_uint16 (dict_t* x, const void* k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_uint32 (dict_t* x, const void* k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_uint64 (dict_t* x, const void* k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_float (dict_t* x, const void* k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_double (dict_t* x, const void* k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_pointer_ldouble(dict_t* x, const void* k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_cstring_pointer(dict_t* x, const char* k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_cstring(dict_t* x, const char* k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_string (dict_t* x, const char* k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_cstring_array (dict_t* x, const char* k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_cstring_list (dict_t* x, const char* k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_cstring_map (dict_t* x, const char* k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_cstring_vset (dict_t* x, const char* k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_cstring_dict (dict_t* x, const char* k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_cstring_boolean(dict_t* x, const char* k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_int8 (dict_t* x, const char* k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_int16 (dict_t* x, const char* k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_int32 (dict_t* x, const char* k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_int64 (dict_t* x, const char* k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_uint8 (dict_t* x, const char* k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_uint16 (dict_t* x, const char* k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_uint32 (dict_t* x, const char* k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_uint64 (dict_t* x, const char* k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_float (dict_t* x, const char* k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_double (dict_t* x, const char* k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_cstring_ldouble(dict_t* x, const char* k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_string_pointer(dict_t* x, const str_t* k, const void* v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_cstring(dict_t* x, const str_t* k, const char* v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_string (dict_t* x, const str_t* k, const str_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_string_array (dict_t* x, const str_t* k, const arr_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_string_list (dict_t* x, const str_t* k, const list_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_string_map (dict_t* x, const str_t* k, const map_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_string_vset (dict_t* x, const str_t* k, const set_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_string_dict (dict_t* x, const str_t* k, const dict_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_string_boolean(dict_t* x, const str_t* k, bool v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_int8 (dict_t* x, const str_t* k, s8_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_int16 (dict_t* x, const str_t* k, s16_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_int32 (dict_t* x, const str_t* k, s32_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_int64 (dict_t* x, const str_t* k, s64_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_uint8 (dict_t* x, const str_t* k, u8_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_uint16 (dict_t* x, const str_t* k, u16_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_uint32 (dict_t* x, const str_t* k, u32_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_uint64 (dict_t* x, const str_t* k, u64_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_float (dict_t* x, const str_t* k, fl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_double (dict_t* x, const str_t* k, dbl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_string_ldouble(dict_t* x, const str_t* k, ldbl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_array_pointer(dict_t* x, const arr_t* k, const void* v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_cstring(dict_t* x, const arr_t* k, const char* v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_string (dict_t* x, const arr_t* k, const str_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_array_array (dict_t* x, const arr_t* k, const arr_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_array_list (dict_t* x, const arr_t* k, const list_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_array_map (dict_t* x, const arr_t* k, const map_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_array_vset (dict_t* x, const arr_t* k, const set_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_array_dict (dict_t* x, const arr_t* k, const dict_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_array_boolean(dict_t* x, const arr_t* k, bool v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_int8 (dict_t* x, const arr_t* k, s8_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_int16 (dict_t* x, const arr_t* k, s16_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_int32 (dict_t* x, const arr_t* k, s32_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_int64 (dict_t* x, const arr_t* k, s64_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_uint8 (dict_t* x, const arr_t* k, u8_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_uint16 (dict_t* x, const arr_t* k, u16_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_uint32 (dict_t* x, const arr_t* k, u32_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_uint64 (dict_t* x, const arr_t* k, u64_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_float (dict_t* x, const arr_t* k, fl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_double (dict_t* x, const arr_t* k, dbl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_array_ldouble(dict_t* x, const arr_t* k, ldbl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_list_pointer(dict_t* x, const list_t* k, const void* v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_cstring(dict_t* x, const list_t* k, const char* v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_string (dict_t* x, const list_t* k, const str_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_list_array (dict_t* x, const list_t* k, const arr_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_list_list (dict_t* x, const list_t* k, const list_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_list_map (dict_t* x, const list_t* k, const map_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_list_vset (dict_t* x, const list_t* k, const set_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_list_dict (dict_t* x, const list_t* k, const dict_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_list_boolean(dict_t* x, const list_t* k, bool v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_int8 (dict_t* x, const list_t* k, s8_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_int16 (dict_t* x, const list_t* k, s16_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_int32 (dict_t* x, const list_t* k, s32_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_int64 (dict_t* x, const list_t* k, s64_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_uint8 (dict_t* x, const list_t* k, u8_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_uint16 (dict_t* x, const list_t* k, u16_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_uint32 (dict_t* x, const list_t* k, u32_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_uint64 (dict_t* x, const list_t* k, u64_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_float (dict_t* x, const list_t* k, fl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_double (dict_t* x, const list_t* k, dbl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_list_ldouble(dict_t* x, const list_t* k, ldbl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_map_pointer(dict_t* x, const map_t* k, const void* v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_cstring(dict_t* x, const map_t* k, const char* v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_string (dict_t* x, const map_t* k, const str_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_map_array (dict_t* x, const map_t* k, const arr_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_map_list (dict_t* x, const map_t* k, const list_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_map_map (dict_t* x, const map_t* k, const map_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_map_vset (dict_t* x, const map_t* k, const set_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_map_dict (dict_t* x, const map_t* k, const dict_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_map_boolean(dict_t* x, const map_t* k, bool v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_int8 (dict_t* x, const map_t* k, s8_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_int16 (dict_t* x, const map_t* k, s16_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_int32 (dict_t* x, const map_t* k, s32_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_int64 (dict_t* x, const map_t* k, s64_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_uint8 (dict_t* x, const map_t* k, u8_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_uint16 (dict_t* x, const map_t* k, u16_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_uint32 (dict_t* x, const map_t* k, u32_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_uint64 (dict_t* x, const map_t* k, u64_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_float (dict_t* x, const map_t* k, fl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_double (dict_t* x, const map_t* k, dbl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_map_ldouble(dict_t* x, const map_t* k, ldbl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_vset_pointer(dict_t* x, const set_t* k, const void* v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_cstring(dict_t* x, const set_t* k, const char* v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_string (dict_t* x, const set_t* k, const str_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_vset_array (dict_t* x, const set_t* k, const arr_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_vset_list (dict_t* x, const set_t* k, const list_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_vset_map (dict_t* x, const set_t* k, const map_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_vset_vset (dict_t* x, const set_t* k, const set_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_vset_dict (dict_t* x, const set_t* k, const dict_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_vset_boolean(dict_t* x, const set_t* k, bool v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_int8 (dict_t* x, const set_t* k, s8_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_int16 (dict_t* x, const set_t* k, s16_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_int32 (dict_t* x, const set_t* k, s32_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_int64 (dict_t* x, const set_t* k, s64_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_uint8 (dict_t* x, const set_t* k, u8_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_uint16 (dict_t* x, const set_t* k, u16_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_uint32 (dict_t* x, const set_t* k, u32_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_uint64 (dict_t* x, const set_t* k, u64_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_float (dict_t* x, const set_t* k, fl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_double (dict_t* x, const set_t* k, dbl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_vset_ldouble(dict_t* x, const set_t* k, ldbl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_dict_pointer(dict_t* x, const dict_t* k, const void* v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_cstring(dict_t* x, const dict_t* k, const char* v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_string (dict_t* x, const dict_t* k, const str_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_dict_array (dict_t* x, const dict_t* k, const arr_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_dict_list (dict_t* x, const dict_t* k, const list_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_dict_map (dict_t* x, const dict_t* k, const map_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_dict_vset (dict_t* x, const dict_t* k, const set_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_dict_dict (dict_t* x, const dict_t* k, const dict_t* v) { return libcdsb_dict_update(x, k, vtypeof(k), v, vtypeof( v)); } -bool libcdsb_dict_update_dict_boolean(dict_t* x, const dict_t* k, bool v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_int8 (dict_t* x, const dict_t* k, s8_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_int16 (dict_t* x, const dict_t* k, s16_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_int32 (dict_t* x, const dict_t* k, s32_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_int64 (dict_t* x, const dict_t* k, s64_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_uint8 (dict_t* x, const dict_t* k, u8_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_uint16 (dict_t* x, const dict_t* k, u16_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_uint32 (dict_t* x, const dict_t* k, u32_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_uint64 (dict_t* x, const dict_t* k, u64_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_float (dict_t* x, const dict_t* k, fl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_double (dict_t* x, const dict_t* k, dbl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_dict_ldouble(dict_t* x, const dict_t* k, ldbl_t v) { return libcdsb_dict_update(x, k, vtypeof(k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_boolean_pointer(dict_t* x, bool k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_cstring(dict_t* x, bool k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_string (dict_t* x, bool k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_boolean_array (dict_t* x, bool k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_boolean_list (dict_t* x, bool k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_boolean_map (dict_t* x, bool k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_boolean_vset (dict_t* x, bool k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_boolean_dict (dict_t* x, bool k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_boolean_boolean(dict_t* x, bool k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_int8 (dict_t* x, bool k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_int16 (dict_t* x, bool k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_int32 (dict_t* x, bool k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_int64 (dict_t* x, bool k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_uint8 (dict_t* x, bool k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_uint16 (dict_t* x, bool k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_uint32 (dict_t* x, bool k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_uint64 (dict_t* x, bool k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_float (dict_t* x, bool k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_double (dict_t* x, bool k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_boolean_ldouble(dict_t* x, bool k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_uint8_pointer(dict_t* x, u8_t k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_cstring(dict_t* x, u8_t k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_string (dict_t* x, u8_t k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint8_array (dict_t* x, u8_t k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint8_list (dict_t* x, u8_t k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint8_map (dict_t* x, u8_t k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint8_vset (dict_t* x, u8_t k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint8_dict (dict_t* x, u8_t k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint8_boolean(dict_t* x, u8_t k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_int8 (dict_t* x, u8_t k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_int16 (dict_t* x, u8_t k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_int32 (dict_t* x, u8_t k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_int64 (dict_t* x, u8_t k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_uint8 (dict_t* x, u8_t k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_uint16 (dict_t* x, u8_t k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_uint32 (dict_t* x, u8_t k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_uint64 (dict_t* x, u8_t k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_float (dict_t* x, u8_t k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_double (dict_t* x, u8_t k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint8_ldouble(dict_t* x, u8_t k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_uint16_pointer(dict_t* x, u16_t k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_cstring(dict_t* x, u16_t k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_string (dict_t* x, u16_t k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint16_array (dict_t* x, u16_t k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint16_list (dict_t* x, u16_t k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint16_map (dict_t* x, u16_t k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint16_vset (dict_t* x, u16_t k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint16_dict (dict_t* x, u16_t k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint16_boolean(dict_t* x, u16_t k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_int8 (dict_t* x, u16_t k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_int16 (dict_t* x, u16_t k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_int32 (dict_t* x, u16_t k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_int64 (dict_t* x, u16_t k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_uint8 (dict_t* x, u16_t k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_uint16 (dict_t* x, u16_t k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_uint32 (dict_t* x, u16_t k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_uint64 (dict_t* x, u16_t k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_float (dict_t* x, u16_t k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_double (dict_t* x, u16_t k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint16_ldouble(dict_t* x, u16_t k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_uint32_pointer(dict_t* x, u32_t k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_cstring(dict_t* x, u32_t k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_string (dict_t* x, u32_t k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint32_array (dict_t* x, u32_t k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint32_list (dict_t* x, u32_t k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint32_map (dict_t* x, u32_t k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint32_vset (dict_t* x, u32_t k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint32_dict (dict_t* x, u32_t k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint32_boolean(dict_t* x, u32_t k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_int8 (dict_t* x, u32_t k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_int16 (dict_t* x, u32_t k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_int32 (dict_t* x, u32_t k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_int64 (dict_t* x, u32_t k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_uint8 (dict_t* x, u32_t k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_uint16 (dict_t* x, u32_t k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_uint32 (dict_t* x, u32_t k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_uint64 (dict_t* x, u32_t k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_float (dict_t* x, u32_t k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_double (dict_t* x, u32_t k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint32_ldouble(dict_t* x, u32_t k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_uint64_pointer(dict_t* x, u64_t k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_cstring(dict_t* x, u64_t k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_string (dict_t* x, u64_t k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint64_array (dict_t* x, u64_t k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint64_list (dict_t* x, u64_t k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint64_map (dict_t* x, u64_t k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint64_vset (dict_t* x, u64_t k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint64_dict (dict_t* x, u64_t k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_uint64_boolean(dict_t* x, u64_t k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_int8 (dict_t* x, u64_t k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_int16 (dict_t* x, u64_t k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_int32 (dict_t* x, u64_t k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_int64 (dict_t* x, u64_t k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_uint8 (dict_t* x, u64_t k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_uint16 (dict_t* x, u64_t k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_uint32 (dict_t* x, u64_t k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_uint64 (dict_t* x, u64_t k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_float (dict_t* x, u64_t k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_double (dict_t* x, u64_t k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_uint64_ldouble(dict_t* x, u64_t k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_int8_pointer(dict_t* x, s8_t k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_cstring(dict_t* x, s8_t k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_string (dict_t* x, s8_t k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int8_array (dict_t* x, s8_t k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int8_list (dict_t* x, s8_t k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int8_map (dict_t* x, s8_t k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int8_vset (dict_t* x, s8_t k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int8_dict (dict_t* x, s8_t k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int8_boolean(dict_t* x, s8_t k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_int8 (dict_t* x, s8_t k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_int16 (dict_t* x, s8_t k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_int32 (dict_t* x, s8_t k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_int64 (dict_t* x, s8_t k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_uint8 (dict_t* x, s8_t k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_uint16 (dict_t* x, s8_t k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_uint32 (dict_t* x, s8_t k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_uint64 (dict_t* x, s8_t k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_float (dict_t* x, s8_t k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_double (dict_t* x, s8_t k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int8_ldouble(dict_t* x, s8_t k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_int16_pointer(dict_t* x, s16_t k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_cstring(dict_t* x, s16_t k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_string (dict_t* x, s16_t k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int16_array (dict_t* x, s16_t k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int16_list (dict_t* x, s16_t k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int16_map (dict_t* x, s16_t k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int16_vset (dict_t* x, s16_t k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int16_dict (dict_t* x, s16_t k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int16_boolean(dict_t* x, s16_t k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_int8 (dict_t* x, s16_t k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_int16 (dict_t* x, s16_t k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_int32 (dict_t* x, s16_t k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_int64 (dict_t* x, s16_t k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_uint8 (dict_t* x, s16_t k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_uint16 (dict_t* x, s16_t k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_uint32 (dict_t* x, s16_t k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_uint64 (dict_t* x, s16_t k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_float (dict_t* x, s16_t k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_double (dict_t* x, s16_t k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int16_ldouble(dict_t* x, s16_t k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_int32_pointer(dict_t* x, s32_t k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_cstring(dict_t* x, s32_t k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_string (dict_t* x, s32_t k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int32_array (dict_t* x, s32_t k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int32_list (dict_t* x, s32_t k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int32_map (dict_t* x, s32_t k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int32_vset (dict_t* x, s32_t k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int32_dict (dict_t* x, s32_t k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int32_boolean(dict_t* x, s32_t k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_int8 (dict_t* x, s32_t k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_int16 (dict_t* x, s32_t k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_int32 (dict_t* x, s32_t k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_int64 (dict_t* x, s32_t k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_uint8 (dict_t* x, s32_t k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_uint16 (dict_t* x, s32_t k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_uint32 (dict_t* x, s32_t k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_uint64 (dict_t* x, s32_t k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_float (dict_t* x, s32_t k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_double (dict_t* x, s32_t k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int32_ldouble(dict_t* x, s32_t k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_int64_pointer(dict_t* x, s64_t k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_cstring(dict_t* x, s64_t k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_string (dict_t* x, s64_t k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int64_array (dict_t* x, s64_t k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int64_list (dict_t* x, s64_t k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int64_map (dict_t* x, s64_t k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int64_vset (dict_t* x, s64_t k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int64_dict (dict_t* x, s64_t k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_int64_boolean(dict_t* x, s64_t k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_int8 (dict_t* x, s64_t k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_int16 (dict_t* x, s64_t k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_int32 (dict_t* x, s64_t k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_int64 (dict_t* x, s64_t k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_uint8 (dict_t* x, s64_t k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_uint16 (dict_t* x, s64_t k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_uint32 (dict_t* x, s64_t k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_uint64 (dict_t* x, s64_t k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_float (dict_t* x, s64_t k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_double (dict_t* x, s64_t k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_int64_ldouble(dict_t* x, s64_t k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_float_pointer(dict_t* x, fl_t k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_cstring(dict_t* x, fl_t k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_string (dict_t* x, fl_t k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_float_array (dict_t* x, fl_t k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_float_list (dict_t* x, fl_t k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_float_map (dict_t* x, fl_t k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_float_vset (dict_t* x, fl_t k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_float_dict (dict_t* x, fl_t k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_float_boolean(dict_t* x, fl_t k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_int8 (dict_t* x, fl_t k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_int16 (dict_t* x, fl_t k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_int32 (dict_t* x, fl_t k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_int64 (dict_t* x, fl_t k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_uint8 (dict_t* x, fl_t k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_uint16 (dict_t* x, fl_t k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_uint32 (dict_t* x, fl_t k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_uint64 (dict_t* x, fl_t k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_float (dict_t* x, fl_t k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_double (dict_t* x, fl_t k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_float_ldouble(dict_t* x, fl_t k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_double_pointer(dict_t* x, dbl_t k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_cstring(dict_t* x, dbl_t k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_string (dict_t* x, dbl_t k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_double_array (dict_t* x, dbl_t k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_double_list (dict_t* x, dbl_t k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_double_map (dict_t* x, dbl_t k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_double_vset (dict_t* x, dbl_t k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_double_dict (dict_t* x, dbl_t k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_double_boolean(dict_t* x, dbl_t k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_int8 (dict_t* x, dbl_t k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_int16 (dict_t* x, dbl_t k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_int32 (dict_t* x, dbl_t k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_int64 (dict_t* x, dbl_t k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_uint8 (dict_t* x, dbl_t k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_uint16 (dict_t* x, dbl_t k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_uint32 (dict_t* x, dbl_t k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_uint64 (dict_t* x, dbl_t k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_float (dict_t* x, dbl_t k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_double (dict_t* x, dbl_t k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_double_ldouble(dict_t* x, dbl_t k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } - -bool libcdsb_dict_update_ldouble_pointer(dict_t* x, ldbl_t k, const void* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_cstring(dict_t* x, ldbl_t k, const char* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_string (dict_t* x, ldbl_t k, const str_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_ldouble_array (dict_t* x, ldbl_t k, const arr_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_ldouble_list (dict_t* x, ldbl_t k, const list_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_ldouble_map (dict_t* x, ldbl_t k, const map_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_ldouble_vset (dict_t* x, ldbl_t k, const set_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_ldouble_dict (dict_t* x, ldbl_t k, const dict_t* v) { return libcdsb_dict_update(x, &k, vtypeof(&k), v, vtypeof( v)); } -bool libcdsb_dict_update_ldouble_boolean(dict_t* x, ldbl_t k, bool v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_int8 (dict_t* x, ldbl_t k, s8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_int16 (dict_t* x, ldbl_t k, s16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_int32 (dict_t* x, ldbl_t k, s32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_int64 (dict_t* x, ldbl_t k, s64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_uint8 (dict_t* x, ldbl_t k, u8_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_uint16 (dict_t* x, ldbl_t k, u16_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_uint32 (dict_t* x, ldbl_t k, u32_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_uint64 (dict_t* x, ldbl_t k, u64_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_float (dict_t* x, ldbl_t k, fl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_double (dict_t* x, ldbl_t k, dbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } -bool libcdsb_dict_update_ldouble_ldouble(dict_t* x, ldbl_t k, ldbl_t v) { return libcdsb_dict_update(x, &k, vtypeof(&k), &v, vtypeof(&v)); } diff --git a/src/dict/include.h b/src/dict/include.h index dc726d1..d0cfd6a 100644 --- a/src/dict/include.h +++ b/src/dict/include.h @@ -1,7 +1,7 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "../../include/extra/dict.h" +#include "../../include/dict.h" #include "../__internal/assert.h" #include "../__internal/rbtree.h" diff --git a/src/dict/memory.c b/src/dict/memory.c new file mode 100644 index 0000000..4b2a5b2 --- /dev/null +++ b/src/dict/memory.c @@ -0,0 +1,23 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +void dict_init(dict_t* x) { + memset(x, 0, sizeof(*x)); +} + +void dict_free(dict_t* x) { + + while (x->capacity--) { + while (!is_null(x->nodes[x->capacity])) { + vnode_free(&x->nodes[x->capacity]->key, x->nodes[x->capacity]->key_type); + vnode_free(&x->nodes[x->capacity]->value, x->nodes[x->capacity]->value_type); + + x->nodes[x->capacity] = x->nodes[x->capacity]->prev; + } + } + + free(x->nodes); + memset(x, 0, sizeof(*x)); +} diff --git a/src/dict/modify.c b/src/dict/modify.c new file mode 100644 index 0000000..33f6a84 --- /dev/null +++ b/src/dict/modify.c @@ -0,0 +1,189 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "../../include/list.h" +#include "include.h" + +static void dict_rehash(dict_t* s, size_t capacity) { + dnode_t **nodes, *c, *n, **p; + size_t i; + + i = s->capacity; + nodes = calloc(sizeof(*nodes), capacity); + + while (i--) { + c = s->nodes[i]; + + while (!is_null(c)) { + p = nodes + (vnode_hash(&c->key, c->key_type) % capacity); + n = c->prev; + c->prev = *p; + + *p = c; + c = n; + } + } + + free(s->nodes); + s->nodes = nodes; + s->capacity = capacity; +} + +/*#####################################################################################################################*/ + +bool libcdsb_dict_shrink_to_fit(dict_t* s) { + + size_t capacity; + + capacity = (s->size / CAPACITY_BLOCK) + 1; + capacity *= CAPACITY_BLOCK; + + while (((double)s->size / capacity) > 0.65) + capacity += CAPACITY_BLOCK; + + if (capacity >= s->capacity) + return false; + + dict_rehash(s, capacity); + + return true; +} + + +bool libcdsb_dict_update(dict_t* x, const void* k, vtype kt, const void* v, vtype vt) { + dnode_t *c, **p; + + if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX) + dict_rehash(x, x->capacity + CAPACITY_BLOCK); + + c = *(p = x->nodes + (vtype_hash(k, kt) % x->capacity)); + + while (!is_null(c)) { + if (vtype_compare(k, kt, vnode_peek(&c->key, c->key_type), c->key_type) == 0) { + vnode_free(&c->value, c->value_type); + + c->value = vnode_create(v, vt); + c->value_type = vt; + + return true; + } else c = c->prev; + } + + c = malloc(sizeof(*c)); + + c->prev = *p; + c->key = vnode_create(k, kt); + c->value = vnode_create(v, vt); + c->key_type = kt; + c->value_type = vt; + + *p = c; + ++x->size; + + return false; +} + + +bool libcdsb_dict_inject(dict_t* x, const void* k, vtype kt, const void* v, vtype vt) { + dnode_t *c, **p; + + if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX) + dict_rehash(x, x->capacity + CAPACITY_BLOCK); + + c = *(p = x->nodes + (vtype_hash(k, kt) % x->capacity)); + + while (!is_null(c)) { + if (vtype_compare(k, kt, vnode_peek(&c->key, c->key_type), c->key_type) == 0) { + vnode_free(&c->value, c->value_type); + + c->value = vnode_create(v, vt); + c->value_type = vt; + + return true; + } else c = c->prev; + } + + c = malloc(sizeof(*c)); + + c->prev = *p; + c->key_type = kt; + c->value_type = vt; + + vnode_attach(&c->key, k, kt); + vnode_attach(&c->value, v, vt); + + *p = c; + ++x->size; + + return false; +} + + +bool libcdsb_dict_inject_key(dict_t* x, const void* k, vtype kt, const void* v, vtype vt) { + dnode_t *c, **p; + + if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX) + dict_rehash(x, x->capacity + CAPACITY_BLOCK); + + c = *(p = x->nodes + (vtype_hash(k, kt) % x->capacity)); + + while (!is_null(c)) { + if (vtype_compare(k, kt, vnode_peek(&c->key, c->key_type), c->key_type) == 0) { + vnode_free(&c->value, c->value_type); + + c->value = vnode_create(v, vt); + c->value_type = vt; + + return true; + } else c = c->prev; + } + + c = malloc(sizeof(*c)); + + c->prev = *p; + c->value = vnode_create(v, vt); + c->key_type = kt; + c->value_type = vt; + + vnode_attach(&c->key, k, kt); + + *p = c; + ++x->size; + + return false; +} + + +bool libcdsb_dict_inject_value(dict_t* x, const void* k, vtype kt, const void* v, vtype vt) { + dnode_t *c, **p; + + if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX) + dict_rehash(x, x->capacity + CAPACITY_BLOCK); + + c = *(p = x->nodes + (vtype_hash(k, kt) % x->capacity)); + + while (!is_null(c)) { + if (vtype_compare(k, kt, vnode_peek(&c->key, c->key_type), c->key_type) == 0) { + vnode_free(&c->value, c->value_type); + + c->value = vnode_create(v, vt); + c->value_type = vt; + + return true; + } else c = c->prev; + } + + c = malloc(sizeof(*c)); + + c->prev = *p; + c->key = vnode_create(k, kt); + c->key_type = kt; + c->value_type = vt; + + vnode_attach(&c->value, v, vt); + + *p = c; + ++x->size; + + return false; +} diff --git a/tests/src/dict/plug.h b/tests/src/dict/plug.h index e6b73db..e3ffb5f 100644 --- a/tests/src/dict/plug.h +++ b/tests/src/dict/plug.h @@ -1,7 +1,7 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "../../../include/extra/dict.h" +#include "../../../include/dict.h" #include "../../include/random.h" #include "../../include/test.h" diff --git a/tests/src/global/plug.h b/tests/src/global/plug.h index f9409d8..b2dce62 100644 --- a/tests/src/global/plug.h +++ b/tests/src/global/plug.h @@ -6,7 +6,7 @@ #include "../../../include/list.h" #include "../../../include/set.h" #include "../../../include/map.h" -#include "../../../include/extra/dict.h" +#include "../../../include/dict.h" #include "../../include/random.h" #include "../../include/test.h" From 08aebcc15b0d425b44cff4e4c3d689abd9847486 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Fri, 19 Aug 2022 20:00:10 +0300 Subject: [PATCH 06/18] Minor fixes & modifications --- include/array.h | 4 ++- include/dict.h | 4 ++- include/list.h | 4 ++- include/vtype.h | 29 +++++++++++----- src/array/compute.c | 6 ++-- src/array/memory.c | 6 ---- src/array/modify.c | 13 +++---- src/dict/memory.c | 4 --- src/list/memory.c | 5 --- src/list/modify.c | 11 +----- src/set/modify.c | 84 +++++++++++++++++++-------------------------- 11 files changed, 72 insertions(+), 98 deletions(-) diff --git a/include/array.h b/include/array.h index 0e54ed0..8f79146 100644 --- a/include/array.h +++ b/include/array.h @@ -11,13 +11,15 @@ typedef int (*array_access_callback)(void* value, ssize_t index, vtype type, voi /*#####################################################################################################################*/ -extern void array_init (vtype_array* x, vtype type) Nonnull__(1); +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_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0, 1) diff --git a/include/dict.h b/include/dict.h index c5a827b..7e3b6f8 100644 --- a/include/dict.h +++ b/include/dict.h @@ -11,7 +11,9 @@ typedef int (*dict_access_callback)(const void* key, vtype key_type, void* value /*#####################################################################################################################*/ -extern void dict_init(vtype_dict* x) Nonnull__(1); +inline void dict_init(vtype_dict* x) Always_inline__ Nonnull__(1); + +inline void dict_init(vtype_dict* x) { x->nodes = (void*)(x->capacity = x->size = 0); } /*#####################################################################################################################*/ diff --git a/include/list.h b/include/list.h index 31b545a..e1aa9d0 100644 --- a/include/list.h +++ b/include/list.h @@ -11,12 +11,14 @@ typedef int (*list_access_callback)(void* value, ssize_t index, vtype type, void /*#####################################################################################################################*/ -extern void list_init (vtype_list* x) Nonnull__(1); +inline void list_init (vtype_list* x) Always_inline__ Nonnull__(1); extern void list_extend (vtype_list* x, const vtype_list* s) Nonnull__(1,2); extern size_t list_slice (vtype_list* x, vtype_list* src, ssize_t index, size_t count, bool cut) Nonnull__(1,2); extern void list_sort (vtype_list* x) Nonnull__(1); extern void list_reverse(vtype_list* x) Nonnull__(1); +inline void list_init (vtype_list* x) { x->first = x->last = 0; } + /*#####################################################################################################################*/ #define list_pop(x, value, data, callback) libcdsb_list_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0, 1) diff --git a/include/vtype.h b/include/vtype.h index e3328f8..999078f 100644 --- a/include/vtype.h +++ b/include/vtype.h @@ -33,6 +33,7 @@ typedef enum libcdsb_value_types { VTYPE_DICT = 18, } vtype; +/*#####################################################################################################################*/ struct libcdsb_string { char* buffer; }; struct libcdsb_array { void* mem; size_t size; vtype type; }; @@ -43,6 +44,8 @@ struct libcdsb_set { struct libcdsb_rbtree_node* root; vtype type; }; struct libcdsb_list { struct libcdsb_list_node* last; struct libcdsb_list_node* first; }; struct libcdsb_dict { struct libcdsb_dict_node** nodes; size_t capacity; size_t size; }; +/*#####################################################################################################################*/ + typedef void* vtype_pointer; typedef bool vtype_bool; @@ -69,15 +72,17 @@ typedef struct libcdsb_list vtype_list; typedef struct libcdsb_dict vtype_dict; typedef struct libcdsb_string vtype_string; -extern size_t string_size(const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1); -extern size_t string_nmemb(const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1); -extern size_t array_size(const vtype_array* x) Pure__ Warn_unused_result__ Nonnull__(1); -extern size_t array_nmemb(const vtype_array* x) Pure__ Warn_unused_result__ Nonnull__(1); -extern size_t list_size(const vtype_list* x) Pure__ Warn_unused_result__ Nonnull__(1); -extern size_t map_size(const vtype_map* x) Pure__ Warn_unused_result__ Nonnull__(1); -extern size_t vset_size(const vtype_set* x) Pure__ Warn_unused_result__ Nonnull__(1); -extern size_t dict_size(const vtype_dict* x) Pure__ Warn_unused_result__ Nonnull__(1); -extern size_t dict_capacity(const vtype_dict* x) Pure__ Warn_unused_result__ Nonnull__(1); +/*#####################################################################################################################*/ + +extern size_t string_size (const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1); +extern size_t string_nmemb (const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1); +extern size_t array_nmemb (const vtype_array* x) Pure__ Warn_unused_result__ Nonnull__(1); +extern size_t list_size (const vtype_list* x) Pure__ Warn_unused_result__ Nonnull__(1); +extern size_t map_size (const vtype_map* x) Pure__ Warn_unused_result__ Nonnull__(1); +extern size_t vset_size (const vtype_set* x) Pure__ Warn_unused_result__ Nonnull__(1); +inline size_t array_size (const vtype_array* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); +inline size_t dict_size (const vtype_dict* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); +inline size_t dict_capacity(const vtype_dict* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); extern int string_compare(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); extern int array_compare (const vtype_array* s0, const vtype_array* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); @@ -127,4 +132,10 @@ extern vtype_hash map_hash (const vtype_map* s) Pure__ Warn_unused_result__ extern vtype_hash vset_hash (const vtype_set* s) Pure__ Warn_unused_result__ Nonnull__(1); extern vtype_hash dict_hash (const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); +/*#####################################################################################################################*/ + +inline size_t array_size (const vtype_array* x) { return x->size; } +inline size_t dict_size (const vtype_dict* x) { return x->size; } +inline size_t dict_capacity(const vtype_dict* x) { return x->capacity; } + #endif /* LIBCDSB_VTYPE_H */ diff --git a/src/array/compute.c b/src/array/compute.c index eee0bdd..637fb37 100644 --- a/src/array/compute.c +++ b/src/array/compute.c @@ -4,14 +4,11 @@ #include "include.h" #include "../__internal/assert.h" -size_t array_size (const arr_t* x) { - return x->size; -} - size_t array_nmemb(const arr_t* x) { return x->size*vtype_size(x->type); } + hash_t array_hash(const arr_t* s) { hash_t hash = 0; @@ -26,6 +23,7 @@ hash_t array_hash(const arr_t* s) { return hash + VTYPE_ARRAY; } + size_t libcdsb_array_count(const arr_t* s, const void* v, vtype t) { void *p; void *e; diff --git a/src/array/memory.c b/src/array/memory.c index 5a84119..06c0caa 100644 --- a/src/array/memory.c +++ b/src/array/memory.c @@ -23,12 +23,6 @@ static inline type_free get_type_free(vtype type) { /*#####################################################################################################################*/ -void array_init(arr_t* x, vtype t) { - x->type = t; - x->size = 0; - x->mem = nullptr; -} - void array_free(arr_t* x) { if (x->size && x->type >= VTYPE_STRING) { void* p = x->mem; diff --git a/src/array/modify.c b/src/array/modify.c index 0fe9e05..7565815 100644 --- a/src/array/modify.c +++ b/src/array/modify.c @@ -20,16 +20,15 @@ ssize_t libcdsb_array_insert(arr_t* x, const void* v, vtype t) { if (vtype_size(x->type) > sizeof(vnode_t)) vnode_free(&n, x->type); - } else if (x->type == t) { + } else { + type_assert(x->type, t); get_type_initializer(t)(array_internal_at(x, i), v); } - #ifndef NDEBUG - else abort(); - #endif return i; } + ssize_t libcdsb_array_attach(arr_t* x, const void* v, vtype t) { ssize_t i; vnode_t n; @@ -44,12 +43,10 @@ ssize_t libcdsb_array_attach(arr_t* x, const void* v, vtype t) { if (vtype_size(x->type) > sizeof(vnode_t)) vnode_free(&n, x->type); - } else if (x->type == t) { + } else { + type_assert(x->type, t); memcpy(array_internal_at(x, i), v, vtype_size(t)); } - #ifndef NDEBUG - else abort(); - #endif return i; } diff --git a/src/dict/memory.c b/src/dict/memory.c index 4b2a5b2..59234ea 100644 --- a/src/dict/memory.c +++ b/src/dict/memory.c @@ -3,10 +3,6 @@ #include "include.h" -void dict_init(dict_t* x) { - memset(x, 0, sizeof(*x)); -} - void dict_free(dict_t* x) { while (x->capacity--) { diff --git a/src/list/memory.c b/src/list/memory.c index d3a1c53..b215538 100644 --- a/src/list/memory.c +++ b/src/list/memory.c @@ -3,11 +3,6 @@ #include "include.h" -void list_init(list_t* x) { - memset(x, 0, sizeof(*x)); -} - - void list_free(list_t* x) { lnode_t* c; lnode_t* next; diff --git a/src/list/modify.c b/src/list/modify.c index 3dd9593..5e1a604 100644 --- a/src/list/modify.c +++ b/src/list/modify.c @@ -92,16 +92,7 @@ bool libcdsb_list_attach(list_t* x, ssize_t i, const void* v, vtype t, int ins) } else vnode_free(&c->node, c->type); - if (t < VTYPE_STRING) { - c->node = vnode_create(v, t); - } else if (sizeof(str_t) == sizeof(void*) && t == VTYPE_STRING) { - c->node = *(char**)v; - } else { - c->node = malloc(vtype_size(t)); - memcpy(c->node, v, vtype_size(t)); - } - - c->type = t; + vnode_attach(&c->node, v, c->type = t); return true; } diff --git a/src/set/modify.c b/src/set/modify.c index dd5e4c2..42066da 100644 --- a/src/set/modify.c +++ b/src/set/modify.c @@ -9,12 +9,43 @@ bool libcdsb_vset_insert(set_t* x, const void* v, vtype t) { int cmp; rbnode_t* n; rbnode_t* p; + + if (!rbnode_is_empty(n = x->root)) { + do { + p = n; + cmp = vtype_compare(v, t, vnode_peek(&n->value, t), t); + + if (cmp == 0) return false; + + n = (cmp < 0) ? n->left : n->right; + } while (!rbnode_is_empty(n)); + + n = rbnode_create(nullptr, p, 1); + + if (cmp < 0) p->left = n; + else p->right = n; + + if (!rbnode_is_root(p)) + rbnode_fixup(&x->root, n); + + } else n = x->root = rbnode_create(nullptr, rbnode_empty, 0); + + n->value = vnode_tcreate(x->type, v, t); + + return true; +} + + +bool libcdsb_vset_attach(set_t* x, const void* v, vtype t) { + int cmp; + rbnode_t* n; + rbnode_t* p; vnode_t vn; - n = x->root; - vn = vnode_tcreate(x->type, v, t); - t = x->type; - v = vnode_peek(&vn, t); + vnode_tattach(&vn, x->type, v, t); + n = x->root; + t = x->type; + v = vnode_peek(&vn, t); if (!rbnode_is_empty(n)) { do { @@ -41,48 +72,3 @@ bool libcdsb_vset_insert(set_t* x, const void* v, vtype t) { return true; } - - -bool libcdsb_vset_attach(set_t* x, const void* v, vtype t) { - int cmp; - rbnode_t* n; - rbnode_t* p; - - n = x->root; - t = x->type; - - if (!rbnode_is_empty(n)) { - do { - p = n; - cmp = vtype_compare(v, t, vnode_peek(&n->value, t), t); - - if (cmp == 0) return false; - - n = (cmp < 0) ? n->left : n->right; - } while (!rbnode_is_empty(n)); - - n = rbnode_create(nullptr, p, 1); - - if (cmp < 0) p->left = n; - else p->right = n; - - if (!rbnode_is_root(p)) - rbnode_fixup(&x->root, n); - - } else n = x->root = rbnode_create(nullptr, rbnode_empty, 0); - - if (t < VTYPE_STRING) { - n->value = vnode_tcreate(x->type, v, t); - } else { - type_assert(x->type, t); - - if (sizeof(str_t) == sizeof(void*) && t == VTYPE_STRING) { - n->value = *(char**)v; - } else { - n->value = malloc(vtype_size(t)); - memcpy(n->value, v, vtype_size(t)); - } - } - - return true; -} From 2118404bfe3f2fafe74525f3d8a19e514aff959b Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Mon, 22 Aug 2022 11:56:16 +0300 Subject: [PATCH 07/18] Refactor headers --- include/__generics.h | 126 ------------------------------ include/array.h | 1 - include/{ => bits}/__attributes.h | 6 +- include/bits/__generics.h | 51 ++++++++++++ include/{extra => bits}/cstring.h | 17 ++-- include/{extra => bits}/memory.h | 20 +---- include/dict.h | 1 - include/extra/string.h | 84 -------------------- include/extra/vtype.h | 12 --- include/list.h | 1 - include/map.h | 1 - include/set.h | 1 - include/vtype.h | 89 +++++++++++++-------- src/__internal/__attributes.h | 2 +- src/__internal/include.h | 36 ++++++--- 15 files changed, 145 insertions(+), 303 deletions(-) delete mode 100644 include/__generics.h rename include/{ => bits}/__attributes.h (78%) create mode 100644 include/bits/__generics.h rename include/{extra => bits}/cstring.h (67%) rename include/{extra => bits}/memory.h (65%) delete mode 100644 include/extra/string.h delete mode 100644 include/extra/vtype.h diff --git a/include/__generics.h b/include/__generics.h deleted file mode 100644 index 2bda8e2..0000000 --- a/include/__generics.h +++ /dev/null @@ -1,126 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#ifndef LIBCDSB_CORE_GENERICS_H -#define LIBCDSB_CORE_GENERICS_H - -#define vtypeof(x) (vtype)(_Generic((x),\ - const void*: VTYPE_POINTER, void*: VTYPE_POINTER,\ - const char**: VTYPE_STRING, char**: VTYPE_STRING,\ - const vtype_string*: VTYPE_STRING, vtype_string*: VTYPE_STRING,\ - const vtype_array*: VTYPE_ARRAY, vtype_array*: VTYPE_ARRAY,\ - const vtype_list*: VTYPE_LIST, vtype_list*: VTYPE_LIST,\ - const vtype_map*: VTYPE_MAP, vtype_map*: VTYPE_MAP,\ - const vtype_set*: VTYPE_SET, vtype_set*: VTYPE_SET,\ - const vtype_dict*: VTYPE_DICT, vtype_dict*: VTYPE_DICT,\ - vtype_bool: VTYPE_BOOLEAN,\ - vtype_uint8: VTYPE_UINT8,\ - vtype_uint16: VTYPE_UINT16,\ - vtype_uint32: VTYPE_UINT32,\ - vtype_uint64: VTYPE_UINT64,\ - vtype_int8: VTYPE_INT8,\ - vtype_int16: VTYPE_INT16,\ - vtype_int32: VTYPE_INT32,\ - vtype_int64: VTYPE_INT64,\ - vtype_float: VTYPE_FLOAT,\ - vtype_double: VTYPE_DOUBLE,\ - vtype_ldouble: VTYPE_LDOUBLE)) - -#define _LIBCDSB_vtypeof(x) vtypeof(_Generic((x), default: (x), const char*: &(x), char*: &(x))) -#define _LIBCDSB_value_pointer(x) _Generic((x), default: &(x),\ - vtype_string*: (x), const vtype_string*: (x),\ - vtype_array*: (x), const vtype_array*: (x),\ - vtype_list*: (x), const vtype_list*: (x),\ - vtype_map*: (x), const vtype_map*: (x),\ - vtype_set*: (x), const vtype_set*: (x),\ - vtype_dict*: (x), const vtype_dict*: (x)) - - -#define _LIBCDSB_Generic(T, f, v) _Generic((v),\ - void*: T ## _ ## f ## _pointer, const void*: T ## _ ## f ## _pointer,\ - char*: T ## _ ## f ## _cstring, const char*: T ## _ ## f ## _cstring,\ - vtype_string*: T ## _ ## f ## _string, const vtype_string*: T ## _ ## f ## _string,\ - vtype_array*: T ## _ ## f ## _array, const vtype_array*: T ## _ ## f ## _array,\ - vtype_list*: T ## _ ## f ## _list, const vtype_list*: T ## _ ## f ## _list,\ - vtype_map*: T ## _ ## f ## _map, const vtype_map*: T ## _ ## f ## _map,\ - vtype_set*: T ## _ ## f ## _vset, const vtype_set*: T ## _ ## f ## _vset,\ - vtype_dict*: T ## _ ## f ## _dict, const vtype_dict*: T ## _ ## f ## _dict,\ - vtype_bool: T ## _ ## f ## _boolean,\ - vtype_uint8: T ## _ ## f ## _uint8,\ - vtype_uint16: T ## _ ## f ## _uint16,\ - vtype_uint32: T ## _ ## f ## _uint32,\ - vtype_uint64: T ## _ ## f ## _uint64,\ - vtype_int8: T ## _ ## f ## _int8,\ - vtype_int16: T ## _ ## f ## _int16,\ - vtype_int32: T ## _ ## f ## _int32,\ - vtype_int64: T ## _ ## f ## _int64,\ - vtype_float: T ## _ ## f ## _float,\ - vtype_double: T ## _ ## f ## _double,\ - vtype_ldouble: T ## _ ## f ## _ldouble\ -) - -#define _LIBCDSB_Generic2(T, f, k, v) _Generic((k),\ - void*: _LIBCDSB_Generic(T, f ## _pointer, v), const void*: _LIBCDSB_Generic(T, f ## _pointer, v),\ - char*: _LIBCDSB_Generic(T, f ## _cstring, v), const char*: _LIBCDSB_Generic(T, f ## _cstring, v),\ - vtype_string*: _LIBCDSB_Generic(T, f ## _string, v), const vtype_string*: _LIBCDSB_Generic(T, f ## _string, v),\ - vtype_array*: _LIBCDSB_Generic(T, f ## _array, v), const vtype_array*: _LIBCDSB_Generic(T, f ## _array, v),\ - vtype_list*: _LIBCDSB_Generic(T, f ## _list, v), const vtype_list*: _LIBCDSB_Generic(T, f ## _list, v),\ - vtype_map*: _LIBCDSB_Generic(T, f ## _map, v), const vtype_map*: _LIBCDSB_Generic(T, f ## _map, v),\ - vtype_set*: _LIBCDSB_Generic(T, f ## _vset, v), const vtype_set*: _LIBCDSB_Generic(T, f ## _vset, v),\ - vtype_dict*: _LIBCDSB_Generic(T, f ## _dict, v), const vtype_dict*: _LIBCDSB_Generic(T, f ## _dict, v),\ - vtype_bool: _LIBCDSB_Generic(T, f ## _boolean, v),\ - vtype_uint8: _LIBCDSB_Generic(T, f ## _uint8, v),\ - vtype_uint16: _LIBCDSB_Generic(T, f ## _uint16, v),\ - vtype_uint32: _LIBCDSB_Generic(T, f ## _uint32, v),\ - vtype_uint64: _LIBCDSB_Generic(T, f ## _uint64, v),\ - vtype_int8: _LIBCDSB_Generic(T, f ## _int8, v),\ - vtype_int16: _LIBCDSB_Generic(T, f ## _int16, v),\ - vtype_int32: _LIBCDSB_Generic(T, f ## _int32, v),\ - vtype_int64: _LIBCDSB_Generic(T, f ## _int64, v),\ - vtype_float: _LIBCDSB_Generic(T, f ## _float, v),\ - vtype_double: _LIBCDSB_Generic(T, f ## _double, v),\ - vtype_ldouble: _LIBCDSB_Generic(T, f ## _ldouble, v)\ -) - -#define _LIBCDSB_Generic_attach(T, ins_f, att_f, v) _Generic((v),\ - void*: T ## _ ## ins_f ## _pointer, const void*: T ## _ ## ins_f ## _pointer,\ - char*: T ## _ ## ins_f ## _cstring, const char*: T ## _ ## ins_f ## _cstring,\ - vtype_string*: T ## _ ## att_f ## _string, const vtype_string*: T ## _ ## att_f ## _string,\ - vtype_array*: T ## _ ## att_f ## _array, const vtype_array*: T ## _ ## att_f ## _array,\ - vtype_list*: T ## _ ## att_f ## _list, const vtype_list*: T ## _ ## att_f ## _list,\ - vtype_map*: T ## _ ## att_f ## _map, const vtype_map*: T ## _ ## att_f ## _map,\ - vtype_set*: T ## _ ## att_f ## _vset, const vtype_set*: T ## _ ## att_f ## _vset,\ - vtype_dict*: T ## _ ## att_f ## _dict, const vtype_dict*: T ## _ ## att_f ## _dict,\ - vtype_bool: T ## _ ## ins_f ## _boolean,\ - vtype_uint8: T ## _ ## ins_f ## _uint8,\ - vtype_uint16: T ## _ ## ins_f ## _uint16,\ - vtype_uint32: T ## _ ## ins_f ## _uint32,\ - vtype_uint64: T ## _ ## ins_f ## _uint64,\ - vtype_int8: T ## _ ## ins_f ## _int8,\ - vtype_int16: T ## _ ## ins_f ## _int16,\ - vtype_int32: T ## _ ## ins_f ## _int32,\ - vtype_int64: T ## _ ## ins_f ## _int64,\ - vtype_float: T ## _ ## ins_f ## _float,\ - vtype_double: T ## _ ## ins_f ## _double,\ - vtype_ldouble: T ## _ ## ins_f ## _ldouble\ -) - -#define _LIBCDSB_GenericS(T, f, v) _Generic((v),\ - void*: T ## _ ## f ## _cstring, const void*: T ## _ ## f ## _cstring,\ - char*: T ## _ ## f ## _cstring, const char*: T ## _ ## f ## _cstring,\ - vtype_string*: T ## _ ## f ## _string, const vtype_string*: T ## _ ## f ## _string,\ - int: T ## _ ## f ## _char, unsigned int: T ## _ ## f ## _char,\ - char: T ## _ ## f ## _char, unsigned char: T ## _ ## f ## _char,\ - short: T ## _ ## f ## _char, unsigned short: T ## _ ## f ## _char\ -) - -#define _LIBCDSB_GenericS2(T, f, s, d) _Generic((s),\ - void*: _LIBCDSB_GenericS(T, f ## _cstring, d), const void*: _LIBCDSB_GenericS(T, f ## _cstring, d),\ - char*: _LIBCDSB_GenericS(T, f ## _cstring, d), const char*: _LIBCDSB_GenericS(T, f ## _cstring, d),\ - vtype_string*: _LIBCDSB_GenericS(T, f ## _string, d), const vtype_string*: _LIBCDSB_GenericS(T, f ## _string, d),\ - int: _LIBCDSB_GenericS(T, f ## _char, d), unsigned int: _LIBCDSB_GenericS(T, f ## _char, d),\ - char: _LIBCDSB_GenericS(T, f ## _char, d), unsigned char: _LIBCDSB_GenericS(T, f ## _char, d),\ - short: _LIBCDSB_GenericS(T, f ## _char, d), unsigned short: _LIBCDSB_GenericS(T, f ## _char, d)\ -) - -#endif /* LIBCDSB_CORE_GENERICS_H */ diff --git a/include/array.h b/include/array.h index 8f79146..35bfd1f 100644 --- a/include/array.h +++ b/include/array.h @@ -1,7 +1,6 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "__generics.h" #include "vtype.h" #ifndef LIBCDSB_ARRAY_H diff --git a/include/__attributes.h b/include/bits/__attributes.h similarity index 78% rename from include/__attributes.h rename to include/bits/__attributes.h index b1b5171..014fc17 100644 --- a/include/__attributes.h +++ b/include/bits/__attributes.h @@ -1,12 +1,12 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#ifndef LIBCDSB_CORE_ATTRIBUTES_H -#define LIBCDSB_CORE_ATTRIBUTES_H +#ifndef LIBCDSB_BITS_ATTRIBUTES_H +#define LIBCDSB_BITS_ATTRIBUTES_H #define Pure__ __attribute__ ((pure)) #define Always_inline__ __attribute__ ((always_inline)) #define Warn_unused_result__ __attribute__ ((warn_unused_result)) #define Nonnull__(...) __attribute__ ((nonnull (__VA_ARGS__))) -#endif /* LIBCDSB_CORE_ATTRIBUTES_H */ +#endif /* LIBCDSB_BITS_ATTRIBUTES_H */ diff --git a/include/bits/__generics.h b/include/bits/__generics.h new file mode 100644 index 0000000..c88ca32 --- /dev/null +++ b/include/bits/__generics.h @@ -0,0 +1,51 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#ifndef LIBCDSB_BITS_GENERICS_H +#define LIBCDSB_BITS_GENERICS_H + +#define vtypeof(x) (vtype)(_Generic((x),\ + const void*: VTYPE_POINTER, void*: VTYPE_POINTER,\ + const char**: VTYPE_STRING, char**: VTYPE_STRING,\ + const vtype_string*: VTYPE_STRING, vtype_string*: VTYPE_STRING,\ + const vtype_array*: VTYPE_ARRAY, vtype_array*: VTYPE_ARRAY,\ + const vtype_list*: VTYPE_LIST, vtype_list*: VTYPE_LIST,\ + const vtype_map*: VTYPE_MAP, vtype_map*: VTYPE_MAP,\ + const vtype_set*: VTYPE_SET, vtype_set*: VTYPE_SET,\ + const vtype_dict*: VTYPE_DICT, vtype_dict*: VTYPE_DICT,\ + vtype_bool: VTYPE_BOOLEAN,\ + vtype_uint8: VTYPE_UINT8,\ + vtype_uint16: VTYPE_UINT16,\ + vtype_uint32: VTYPE_UINT32,\ + vtype_uint64: VTYPE_UINT64,\ + vtype_int8: VTYPE_INT8,\ + vtype_int16: VTYPE_INT16,\ + vtype_int32: VTYPE_INT32,\ + vtype_int64: VTYPE_INT64,\ + vtype_float: VTYPE_FLOAT,\ + vtype_double: VTYPE_DOUBLE,\ + vtype_ldouble: VTYPE_LDOUBLE)) + +#define _LIBCDSB_vtypeof(x) vtypeof(_Generic((x), default: (x), const char*: &(x), char*: &(x))) +#define _LIBCDSB_value_pointer(x) _Generic((x), default: &(x),\ + vtype_string*: (x), const vtype_string*: (x),\ + vtype_array*: (x), const vtype_array*: (x),\ + vtype_list*: (x), const vtype_list*: (x),\ + vtype_map*: (x), const vtype_map*: (x),\ + vtype_set*: (x), const vtype_set*: (x),\ + vtype_dict*: (x), const vtype_dict*: (x)) + +#define _LIBCDSB_to_cstring(x) _Generic((x), default: _LIBCDSB_nothing,\ + vtype_string*: _LIBCDSB_deref1, const vtype_string*: _LIBCDSB_deref1,\ + int: libcdsb_char_to_cstring, unsigned int: libcdsb_char_to_cstring,\ + char: libcdsb_char_to_cstring, unsigned char: libcdsb_char_to_cstring,\ + short: libcdsb_char_to_cstring, unsigned short: libcdsb_char_to_cstring\ +)(x) + +inline const void* _LIBCDSB_nothing(const void* x) __attribute__((always_inline)); +inline const void* _LIBCDSB_deref1 (const void* x) __attribute__((always_inline)); + +inline const void* _LIBCDSB_nothing(const void* x) { return x; } +inline const void* _LIBCDSB_deref1 (const void* x) { return *(void**)x; } + +#endif /* LIBCDSB_BITS_GENERICS_H */ diff --git a/include/extra/cstring.h b/include/bits/cstring.h similarity index 67% rename from include/extra/cstring.h rename to include/bits/cstring.h index 9a4e9cb..5641249 100644 --- a/include/extra/cstring.h +++ b/include/bits/cstring.h @@ -2,10 +2,12 @@ /* Copyright © 2022 Gregory Lirent */ #include -#include "../__attributes.h" +#include "__attributes.h" -#ifndef LIBCDSB_EXTRA_CSTRING_H -#define LIBCDSB_EXTRA_CSTRING_H +#ifndef LIBCDSB_BITS_CSTRING_H +#define LIBCDSB_BITS_CSTRING_H + +extern const char* libcdsb_char_to_cstring(int c) Warn_unused_result__; extern size_t libcdsb_strlen (const char* s) Pure__ Warn_unused_result__ Nonnull__(1); extern size_t libcdsb_strasciilen(const char* s) Pure__ Warn_unused_result__ Nonnull__(1); @@ -14,11 +16,4 @@ extern char* libcdsb_strdup (const char* s) Warn_unused_result__ Nonnu extern char* libcdsb_strndup(const char* s, size_t n) Warn_unused_result__ Nonnull__(1); extern void* libcdsb_memndup(const void* m, size_t n) Warn_unused_result__ Nonnull__(1); -#define strlen libcdsb_strlen -#define strasciilen libcdsb_strasciilen - -#define strdup libcdsb_strdup -#define strndup libcdsb_strndup -#define memndup libcdsb_memndup - -#endif /* LIBCDSB_EXTRA_CSTRING_H */ +#endif /* LIBCDSB_BITS_CSTRING_H */ diff --git a/include/extra/memory.h b/include/bits/memory.h similarity index 65% rename from include/extra/memory.h rename to include/bits/memory.h index e5a595e..5750557 100644 --- a/include/extra/memory.h +++ b/include/bits/memory.h @@ -2,10 +2,10 @@ /* Copyright © 2022 Gregory Lirent */ #include -#include "../__attributes.h" +#include "__attributes.h" -#ifndef LIBCDSB_EXTRA_MEMORY_H -#define LIBCDSB_EXTRA_MEMORY_H +#ifndef LIBCDSB_BITS_MEMORY_H +#define LIBCDSB_BITS_MEMORY_H typedef struct libcdsb_stack_node { struct libcdsb_stack_node* prev; @@ -25,16 +25,4 @@ extern void* libcdsb_realloc(void *p, size_t n) Warn_unused_result__; extern void libcdsb_free(void* s); -#define aligned_alloc libcdsb_aalloc -#define malloc libcdsb_malloc -#define calloc libcdsb_calloc -#define realloc libcdsb_realloc -#define free libcdsb_free - -#define stack_init libcdsb_stack_init -#define stack_push libcdsb_stack_push -#define stack_push_many libcdsb_stack_push_many -#define stack_pop libcdsb_stack_pop -#define stack_flush libcdsb_stack_flush - -#endif /* LIBCDSB_EXTRA_MEMORY_H */ +#endif /* LIBCDSB_BITS_MEMORY_H */ diff --git a/include/dict.h b/include/dict.h index 7e3b6f8..23966e7 100644 --- a/include/dict.h +++ b/include/dict.h @@ -1,7 +1,6 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "__generics.h" #include "vtype.h" #ifndef LIBCDSB_DICT_H diff --git a/include/extra/string.h b/include/extra/string.h deleted file mode 100644 index 283df4b..0000000 --- a/include/extra/string.h +++ /dev/null @@ -1,84 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "../string.h" - -#ifndef LIBCDSB_EXTRA_STRING_H -#define LIBCDSB_EXTRA_STRING_H - -/*#####################################################################################################################*/ - -#define string_split(s, sep, maxn) _LIBCDSB_GenericS(libcdsb_string, split, sep)(s, sep, maxn) -#define string_case_compare string_compare_case_insensitive - -#define string_replace_r(x, src, dest, maxn) _LIBCDSB_GenericS2(libcdsb_string, replace_r, src, dest)(x, src, dest, maxn) - -#define string_trim(x, arg) _LIBCDSB_GenericS(libcdsb_string, trim, arg)(x, arg, 0) -#define string_ltrim(x, arg) _LIBCDSB_GenericS(libcdsb_string, trim, arg)(x, arg, -1) -#define string_rtrim(x, arg) _LIBCDSB_GenericS(libcdsb_string, trim, arg)(x, arg, 1) - -extern size_t string_to_lower (vtype_string* x) Nonnull__(1); -extern size_t string_to_upper (vtype_string* x) Nonnull__(1); -extern size_t string_capitalize(vtype_string* x) Nonnull__(1); - -extern size_t string_reverse (vtype_string* x) Nonnull__(1); - -extern size_t string_align_center(vtype_string* x, size_t padsize, int padchr) Nonnull__(1); -extern size_t string_align_right (vtype_string* x, size_t padsize, int padchr) Nonnull__(1); -extern size_t string_align_left (vtype_string* x, size_t padsize, int padchr) Nonnull__(1); - -extern void libcdsb_string_replace(vtype_string* x, char* dest, size_t dest_nmemb, const char* src, size_t nmemb) Nonnull__(1,2); - -/*#####################################################################################################################*/ - -extern int string_compare_case_insensitive(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); - -inline vtype_array libcdsb_string_split_string (const vtype_string* s, const vtype_string* sep, size_t maxn) Nonnull__(1) Always_inline__; -extern vtype_array libcdsb_string_split_cstring(const vtype_string* s, const char* sep, size_t maxn) Nonnull__(1); -extern vtype_array libcdsb_string_split_char (const vtype_string* s, int chr, size_t maxn) Nonnull__(1); - -inline void libcdsb_string_trim_string (vtype_string* x, const vtype_string* s, int direction) Nonnull__(1) Always_inline__; -extern void libcdsb_string_trim_cstring(vtype_string* x, const char* s, int direction) Nonnull__(1); -extern void libcdsb_string_trim_char (vtype_string* x, int sc, int direction) Nonnull__(1); - -inline size_t libcdsb_string_replace_r_string_string (vtype_string*restrict x, const vtype_string*restrict src, const vtype_string*restrict dest, size_t maxn) Nonnull__(1) Always_inline__; -inline size_t libcdsb_string_replace_r_string_cstring (vtype_string*restrict x, const vtype_string*restrict src, const char*restrict dest, size_t maxn) Nonnull__(1) Always_inline__; -inline size_t libcdsb_string_replace_r_string_char (vtype_string*restrict x, const vtype_string*restrict src, int dest, size_t maxn) Nonnull__(1) Always_inline__; -inline size_t libcdsb_string_replace_r_cstring_string (vtype_string*restrict x, const char*restrict src, const vtype_string*restrict dest, size_t maxn) Nonnull__(1) Always_inline__; -extern size_t libcdsb_string_replace_r_cstring_cstring(vtype_string*restrict x, const char*restrict src, const char*restrict dest, size_t maxn) Nonnull__(1); -extern size_t libcdsb_string_replace_r_cstring_char (vtype_string*restrict x, const char*restrict src, int dest, size_t maxn) Nonnull__(1); -inline size_t libcdsb_string_replace_r_char_string (vtype_string*restrict x, int src, const vtype_string*restrict dest, size_t maxn) Nonnull__(1) Always_inline__; -extern size_t libcdsb_string_replace_r_char_cstring (vtype_string*restrict x, int src, const char*restrict dest, size_t maxn) Nonnull__(1); -#define libcdsb_string_replace_r_char_char libcdsb_string_replace_char_char - -/*#####################################################################################################################*/ - -inline vtype_array libcdsb_string_split_string(const vtype_string* x, const vtype_string* sep, size_t maxn) { - return string_split(x, sep->buffer, maxn); -} - -inline void libcdsb_string_trim_string(vtype_string* x, const vtype_string* s, int direction) { - return libcdsb_string_trim_cstring (x, s->buffer, direction); -} - -inline size_t libcdsb_string_replace_r_string_string (vtype_string*restrict x, const vtype_string*restrict src, const vtype_string*restrict dest, size_t maxn) { - return string_replace_r(x, src->buffer, dest->buffer, maxn); -} - -inline size_t libcdsb_string_replace_r_string_cstring(vtype_string*restrict x, const vtype_string*restrict src, const char*restrict dest, size_t maxn) { - return string_replace_r(x, src->buffer, dest, maxn); -} - -inline size_t libcdsb_string_replace_r_cstring_string(vtype_string*restrict x, const char*restrict src, const vtype_string*restrict dest, size_t maxn) { - return string_replace_r(x, src, dest->buffer, maxn); -} - -inline size_t libcdsb_string_replace_r_string_char (vtype_string*restrict x, const vtype_string*restrict src, int dest, size_t maxn) { - return string_replace_r(x, src->buffer, dest, maxn); -} - -inline size_t libcdsb_string_replace_r_char_string (vtype_string*restrict x, int src, const vtype_string*restrict dest, size_t maxn) { - return string_replace_r(x, src, dest->buffer, maxn); -} - -#endif /* LIBCDSB_EXTRA_STRING_H */ diff --git a/include/extra/vtype.h b/include/extra/vtype.h deleted file mode 100644 index af4307d..0000000 --- a/include/extra/vtype.h +++ /dev/null @@ -1,12 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "../vtype.h" - -#ifndef LIBCDSB_EXTRA_VTYPE_H -#define LIBCDSB_EXTRA_VTYPE_H - -extern const char* libcdsb_vtype_name(vtype t) Warn_unused_result__; -extern const char* libcdsb_vtype_stringify(const void* value, vtype t) Warn_unused_result__; - -#endif /* LIBCDSB_EXTRA_VTYPE_H */ diff --git a/include/list.h b/include/list.h index e1aa9d0..e617d48 100644 --- a/include/list.h +++ b/include/list.h @@ -1,7 +1,6 @@ /* 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 diff --git a/include/map.h b/include/map.h index 4c499c9..f04ef43 100644 --- a/include/map.h +++ b/include/map.h @@ -1,7 +1,6 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "__generics.h" #include "vtype.h" #ifndef LIBCDSB_MAP_H diff --git a/include/set.h b/include/set.h index f71d88b..67857fa 100644 --- a/include/set.h +++ b/include/set.h @@ -1,7 +1,6 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "__generics.h" #include "vtype.h" #ifndef LIBCDSB_SET_H diff --git a/include/vtype.h b/include/vtype.h index 999078f..e47855c 100644 --- a/include/vtype.h +++ b/include/vtype.h @@ -5,7 +5,8 @@ #include #include -#include "__attributes.h" +#include "bits/cstring.h" +#include "bits/memory.h" #ifndef LIBCDSB_VTYPE_H #define LIBCDSB_VTYPE_H @@ -72,53 +73,58 @@ typedef struct libcdsb_list vtype_list; typedef struct libcdsb_dict vtype_dict; typedef struct libcdsb_string vtype_string; + +extern const char* libcdsb_vtype_name (vtype t) Warn_unused_result__; +extern const char* libcdsb_vtype_stringify(const void* value, vtype t) Warn_unused_result__; + /*#####################################################################################################################*/ extern size_t string_size (const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1); -extern size_t string_nmemb (const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1); extern size_t array_nmemb (const vtype_array* x) Pure__ Warn_unused_result__ Nonnull__(1); extern size_t list_size (const vtype_list* x) Pure__ Warn_unused_result__ Nonnull__(1); extern size_t map_size (const vtype_map* x) Pure__ Warn_unused_result__ Nonnull__(1); extern size_t vset_size (const vtype_set* x) Pure__ Warn_unused_result__ Nonnull__(1); +inline size_t string_nmemb (const vtype_string* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); inline size_t array_size (const vtype_array* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); inline size_t dict_size (const vtype_dict* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); inline size_t dict_capacity(const vtype_dict* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); -extern int string_compare(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -extern int array_compare (const vtype_array* s0, const vtype_array* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -extern int list_compare (const vtype_list* s0, const vtype_list* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -extern int map_compare (const vtype_map* s0, const vtype_map* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -extern int vset_compare (const vtype_set* s0, const vtype_set* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -extern int dict_compare (const vtype_dict* s0, const vtype_dict* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); +extern int string_case_compare(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); +extern int string_compare (const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); +extern int array_compare (const vtype_array* s0, const vtype_array* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); +extern int list_compare (const vtype_list* s0, const vtype_list* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); +extern int map_compare (const vtype_map* s0, const vtype_map* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); +extern int vset_compare (const vtype_set* s0, const vtype_set* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); +extern int dict_compare (const vtype_dict* s0, const vtype_dict* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); -extern vtype_string string_copy (const vtype_string* s) Pure__ Warn_unused_result__ Nonnull__(1); -extern vtype_array array_copy (const vtype_array* s) Pure__ Warn_unused_result__ Nonnull__(1); -extern vtype_list list_copy (const vtype_list* s) Pure__ Warn_unused_result__ Nonnull__(1); -extern vtype_map map_copy (const vtype_map* s) Pure__ Warn_unused_result__ Nonnull__(1); -extern vtype_set vset_copy (const vtype_set* s) Pure__ Warn_unused_result__ Nonnull__(1); -extern vtype_dict dict_copy (const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); -extern vtype_list dict_copy_keys(const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); +inline vtype_string string_copy (const vtype_string* s) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_array array_copy (const vtype_array* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_list list_copy (const vtype_list* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_map map_copy (const vtype_map* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_set vset_copy (const vtype_set* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_dict dict_copy (const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_list dict_copy_keys(const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); #define map_copy_keys(s) vset_copy((vtype_set*)s) -extern vtype_string* string_duplicate (const vtype_string* s) Warn_unused_result__ Nonnull__(1); -extern vtype_array* array_duplicate (const vtype_array* s) Warn_unused_result__ Nonnull__(1); -extern vtype_list* list_duplicate (const vtype_list* s) Warn_unused_result__ Nonnull__(1); -extern vtype_map* map_duplicate (const vtype_map* s) Warn_unused_result__ Nonnull__(1); -extern vtype_set* vset_duplicate (const vtype_set* s) Warn_unused_result__ Nonnull__(1); -extern vtype_dict* dict_duplicate (const vtype_dict* s) Warn_unused_result__ Nonnull__(1); -extern vtype_list* dict_duplicate_keys(const vtype_dict* s) Warn_unused_result__ Nonnull__(1); +inline vtype_string* string_duplicate (const vtype_string* s) Always_inline__ Warn_unused_result__ Nonnull__(1); +extern vtype_array* array_duplicate (const vtype_array* s) Warn_unused_result__ Nonnull__(1); +extern vtype_list* list_duplicate (const vtype_list* s) Warn_unused_result__ Nonnull__(1); +extern vtype_map* map_duplicate (const vtype_map* s) Warn_unused_result__ Nonnull__(1); +extern vtype_set* vset_duplicate (const vtype_set* s) Warn_unused_result__ Nonnull__(1); +extern vtype_dict* dict_duplicate (const vtype_dict* s) Warn_unused_result__ Nonnull__(1); +extern vtype_list* dict_duplicate_keys(const vtype_dict* s) Warn_unused_result__ Nonnull__(1); #define map_duplicate_keys(s) vset_duplicate((vtype_set*)s) -extern void string_copy_init (vtype_string* x, const vtype_string* s) Nonnull__(1,2); -extern void array_copy_init (vtype_array* x, const vtype_array* s) Nonnull__(1,2); -extern void list_copy_init (vtype_list* x, const vtype_list* s) Nonnull__(1,2); -extern void map_copy_init (vtype_map* x, const vtype_map* s) Nonnull__(1,2); -extern void vset_copy_init (vtype_set* x, const vtype_set* s) Nonnull__(1,2); -extern void dict_copy_init (vtype_dict* x, const vtype_dict* s) Nonnull__(1,2); -extern void dict_init_keys (vtype_list* x, const vtype_dict* s) Nonnull__(1,2); +inline void string_copy_init (vtype_string* x, const vtype_string* s) Always_inline__ Nonnull__(1,2); +extern void array_copy_init (vtype_array* x, const vtype_array* s) Nonnull__(1,2); +extern void list_copy_init (vtype_list* x, const vtype_list* s) Nonnull__(1,2); +extern void map_copy_init (vtype_map* x, const vtype_map* s) Nonnull__(1,2); +extern void vset_copy_init (vtype_set* x, const vtype_set* s) Nonnull__(1,2); +extern void dict_copy_init (vtype_dict* x, const vtype_dict* s) Nonnull__(1,2); +extern void dict_init_keys (vtype_list* x, const vtype_dict* s) Nonnull__(1,2); #define map_copy_init_keys(x, s) vset_duplicate(x, (vtype_set*)s) -extern void string_free(vtype_string* x); +inline void string_free(vtype_string* x) Always_inline__; extern void array_free (vtype_array* x); extern void list_free (vtype_list* x); extern void map_free (vtype_map* x); @@ -134,8 +140,25 @@ extern vtype_hash dict_hash (const vtype_dict* s) Pure__ Warn_unused_result__ /*#####################################################################################################################*/ -inline size_t array_size (const vtype_array* x) { return x->size; } -inline size_t dict_size (const vtype_dict* x) { return x->size; } -inline size_t dict_capacity(const vtype_dict* x) { return x->capacity; } +inline size_t array_size (const vtype_array* x) { return x->size; } +inline size_t dict_size (const vtype_dict* x) { return x->size; } +inline size_t dict_capacity(const vtype_dict* x) { return x->capacity; } +inline size_t string_nmemb (const vtype_string* x) { return (x->buffer) ? libcdsb_strlen(x->buffer) : 0; } +inline void string_free ( vtype_string* x) { libcdsb_free(x->buffer); x->buffer = 0; } + +inline vtype_string string_copy(const vtype_string* s) { + vtype_string x = { .buffer = libcdsb_strdup(s->buffer) }; + return x; +} + +inline vtype_string* string_duplicate(const vtype_string* s) { + void** x = libcdsb_malloc(sizeof(*x)); + *x = libcdsb_strdup(s->buffer); + return (void*)x; +} + +inline void string_copy_init(vtype_string* x, const vtype_string* s) { + x->buffer = libcdsb_strdup(s->buffer); +} #endif /* LIBCDSB_VTYPE_H */ diff --git a/src/__internal/__attributes.h b/src/__internal/__attributes.h index 85d74b0..1fe638c 100644 --- a/src/__internal/__attributes.h +++ b/src/__internal/__attributes.h @@ -1,7 +1,7 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "../../include/__attributes.h" +#include "../../include/bits/__attributes.h" #define pure__ Pure__ #define const__ __attribute__((const)) diff --git a/src/__internal/include.h b/src/__internal/include.h index dbefa85..fb5a610 100644 --- a/src/__internal/include.h +++ b/src/__internal/include.h @@ -7,15 +7,11 @@ #include #include "../../include/vtype.h" -#include "../../include/extra/memory.h" -#include "../../include/extra/cstring.h" -#include "../../include/extra/vtype.h" +#include "__attributes.h" #ifndef LIBCDSB_SRC_INTERNAL_INCLUDE #define LIBCDSB_SRC_INTERNAL_INCLUDE -extern const size_t LIBCDSB_VTYPE_SIZES[19]; - #define is_x64 (sizeof(void*) == sizeof(vtype_uint64)) #define is_big_endian (*((unsigned int*)"\0\0\0\1") < (unsigned int)0xffff) #define is_little_endian (!is_big_endian) @@ -38,7 +34,6 @@ extern const size_t LIBCDSB_VTYPE_SIZES[19]; #define abs(v) _Generic((v), ldbl_t: fabsl, dbl_t: fabs, fl_t: fabsf)(v) -#include "__attributes.h" typedef vtype_uint8 u8_t; typedef vtype_uint16 u16_t; @@ -64,20 +59,37 @@ typedef vtype_dict dict_t; typedef vtype_hash hash_t; +extern const size_t LIBCDSB_VTYPE_SIZES[19]; + extern int libcdsb_vtype_compare_values (const void* s0, vtype t0, const void* s1, vtype t1) pure__ wur__; extern int libcdsb_vtype_compare_values_eq(const void* s0, const void* s1, vtype t) pure__ wur__; extern hash_t libcdsb_vtype_hash (const void* value, vtype type) pure__ wur__; -#define vtype_stringify libcdsb_vtype_stringify -#define vtype_name libcdsb_vtype_name -#define vtype_compare libcdsb_vtype_compare_values -#define vtype_compare_eq libcdsb_vtype_compare_values_eq - -#define vtype_hash libcdsb_vtype_hash +#define aligned_alloc libcdsb_aalloc +#define malloc libcdsb_malloc +#define calloc libcdsb_calloc +#define realloc libcdsb_realloc +#define free libcdsb_free +#define stack_init libcdsb_stack_init +#define stack_push libcdsb_stack_push +#define stack_push_many libcdsb_stack_push_many +#define stack_pop libcdsb_stack_pop +#define stack_flush libcdsb_stack_flush +#define strlen libcdsb_strlen +#define strasciilen libcdsb_strasciilen +#define strdup libcdsb_strdup +#define strndup libcdsb_strndup +#define memndup libcdsb_memndup +#define vtype_stringify libcdsb_vtype_stringify +#define vtype_name libcdsb_vtype_name +#define vtype_compare libcdsb_vtype_compare_values +#define vtype_compare_eq libcdsb_vtype_compare_values_eq +#define vtype_hash libcdsb_vtype_hash #define vtype_size(type) (LIBCDSB_VTYPE_SIZES[type]) + #define vtypeof(x) (vtype)(_Generic((x),\ const void**: VTYPE_POINTER, void**: VTYPE_POINTER, const void*: VTYPE_POINTER, void*: VTYPE_POINTER,\ const char**: VTYPE_STRING, char**: VTYPE_STRING, const char*: VTYPE_STRING, char*: VTYPE_STRING,\ From e92ff17be47efb4055364cf9a70fa2ece08185f5 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Mon, 22 Aug 2022 11:59:09 +0300 Subject: [PATCH 08/18] Fix calls of the inline methods --- src/array/copy.c | 16 ++++------------ src/array/include.h | 18 ++++++++---------- src/array/memory.c | 35 ++++++++++++----------------------- src/array/modify.c | 2 +- 4 files changed, 25 insertions(+), 46 deletions(-) diff --git a/src/array/copy.c b/src/array/copy.c index 7f2194e..639060b 100644 --- a/src/array/copy.c +++ b/src/array/copy.c @@ -13,15 +13,13 @@ arr_t array_copy(const arr_t* s) { if (s->type >= VTYPE_STRING) { void *p, *v, *e; - type_initializer init; x.mem = p = malloc(x.size*vtype_size(x.type)); v = s->mem; e = array_end(&x); - init = get_type_initializer(s->type); do { - init(p, v); + copy_init(p, v, s->type); p += vtype_size(x.type); v += vtype_size(x.type); } while (p < e); @@ -42,15 +40,13 @@ arr_t* array_duplicate(const arr_t* s) { if (s->type >= VTYPE_STRING) { void *p, *v, *e; - type_initializer init; x->mem = p = malloc(x->size*vtype_size(x->type)); v = s->mem; e = array_end(x); - init = get_type_initializer(s->type); do { - init(p, v); + copy_init(p, v, s->type); p += vtype_size(x->type); v += vtype_size(x->type); } while (p < e); @@ -69,15 +65,13 @@ void array_copy_init(arr_t* x, const arr_t* s) { if (s->type >= VTYPE_STRING) { void *p, *v, *e; - type_initializer init; x->mem = p = malloc(x->size*vtype_size(x->type)); v = s->mem; e = array_end(x); - init = get_type_initializer(s->type); do { - init(p, v); + copy_init(p, v, s->type); p += vtype_size(x->type); v += vtype_size(x->type); } while (p < e); @@ -103,15 +97,13 @@ size_t array_slice(arr_t* x, arr_t* s, ssize_t i, size_t n, _Bool cut) { if (!cut && s->type >= VTYPE_STRING) { void *p, *v, *e; - type_initializer init; p = x->mem; v = array_internal_at(s, i); e = array_internal_at(x, n); - init = get_type_initializer(s->type); do { - init(p, v); + copy_init(p, v, s->type); p += vtype_size(x->type); v += vtype_size(x->type); } while (p < e); diff --git a/src/array/include.h b/src/array/include.h index 38db83c..aebc892 100644 --- a/src/array/include.h +++ b/src/array/include.h @@ -7,20 +7,18 @@ #ifndef LIBCDSB_SRC_ARRAY_INCLUDE_H #define LIBCDSB_SRC_ARRAY_INCLUDE_H -typedef void (*type_initializer)(void*, const void*); - -ainline(type_initializer get_type_initializer(vtype type)) { - switch (type) { +ainline(void copy_init(void* x, const void* s, vtype t)) { + switch (t) { default: #ifndef NDEBUG abort(); #endif - case VTYPE_STRING: return (void*)string_copy_init; - case VTYPE_ARRAY: return (void*) array_copy_init; - case VTYPE_LIST: return (void*) list_copy_init; - case VTYPE_MAP: return (void*) map_copy_init; - case VTYPE_SET: return (void*) vset_copy_init; - case VTYPE_DICT: return (void*) dict_copy_init; + case VTYPE_STRING: string_copy_init(x, s); break; + case VTYPE_ARRAY: array_copy_init(x, s); break; + case VTYPE_LIST: list_copy_init(x, s); break; + case VTYPE_MAP: map_copy_init(x, s); break; + case VTYPE_SET: vset_copy_init(x, s); break; + case VTYPE_DICT: dict_copy_init(x, s); break; } } diff --git a/src/array/memory.c b/src/array/memory.c index 06c0caa..503bc98 100644 --- a/src/array/memory.c +++ b/src/array/memory.c @@ -4,36 +4,25 @@ #include "include.h" #include "../__internal/assert.h" -typedef void (*type_free)(void*); - -static inline type_free get_type_free(vtype type) { - switch (type) { - default: - #ifndef NDEBUG - abort(); - #endif - case VTYPE_STRING: return (void*)string_free; - case VTYPE_ARRAY: return (void*) array_free; - case VTYPE_LIST: return (void*) list_free; - case VTYPE_MAP: return (void*) map_free; - case VTYPE_SET: return (void*) vset_free; - case VTYPE_DICT: return (void*) dict_free; - } -} - -/*#####################################################################################################################*/ - void array_free(arr_t* x) { if (x->size && x->type >= VTYPE_STRING) { void* p = x->mem; - type_free free_; assert(!is_null(p)); - free_ = get_type_free(x->type); - do { - free_(p); + switch (x->type) { + default: + #ifndef NDEBUG + abort(); + #endif + case VTYPE_STRING: string_free(p); break; + case VTYPE_ARRAY: array_free(p); break; + case VTYPE_LIST: list_free(p); break; + case VTYPE_MAP: map_free(p); break; + case VTYPE_SET: vset_free(p); break; + case VTYPE_DICT: dict_free(p); break; + } p += vtype_size(x->type); } while (--x->size); } diff --git a/src/array/modify.c b/src/array/modify.c index 7565815..849b013 100644 --- a/src/array/modify.c +++ b/src/array/modify.c @@ -22,7 +22,7 @@ ssize_t libcdsb_array_insert(arr_t* x, const void* v, vtype t) { } else { type_assert(x->type, t); - get_type_initializer(t)(array_internal_at(x, i), v); + copy_init(array_internal_at(x, i), v, t); } return i; From 205c8337c280ed0c48dc8c081401a70f5f6ccbe7 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Mon, 22 Aug 2022 12:03:02 +0300 Subject: [PATCH 09/18] Update the include/bits implementation --- src/extra-memory.c | 2 +- src/extra.c | 20 +++++++++++++++++++- src/vtype-extra.c | 34 +++++++++++++++++++--------------- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/extra-memory.c b/src/extra-memory.c index afeeb49..84bb2da 100644 --- a/src/extra-memory.c +++ b/src/extra-memory.c @@ -2,8 +2,8 @@ /* Copyright © 2022 Gregory Lirent */ #include -#include "../include/extra/cstring.h" #include "__internal/include.h" + #undef aligned_alloc #undef malloc #undef realloc diff --git a/src/extra.c b/src/extra.c index 175d14f..313b1b6 100644 --- a/src/extra.c +++ b/src/extra.c @@ -1,9 +1,27 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "../include/extra/cstring.h" +#include "../modules/libunic/include.h" #include "__internal/include.h" +static _Thread_local int CHAR_BUFFER_POS = 0; +static _Thread_local char CHAR_BUFFER[16][5]; + +const char* libcdsb_char_to_cstring(int c) { + + char* p; + + if (CHAR_BUFFER_POS > 15) + CHAR_BUFFER_POS = 0; + + if (is_null(p = tochar_unicode(CHAR_BUFFER[CHAR_BUFFER_POS], c))) { + CHAR_BUFFER[CHAR_BUFFER_POS][0] = 0; + } else *p = 0; + + return CHAR_BUFFER[CHAR_BUFFER_POS++]; +} + + size_t libcdsb_strlen(const char* s) { static const size_t m = (sizeof(size_t) == 8) ? 0x8080808080808080UL : 0x80808080UL; static const size_t d = (sizeof(size_t) == 8) ? 0x0101010101010101UL : 0x01010101UL; diff --git a/src/vtype-extra.c b/src/vtype-extra.c index 80f1bfc..8776b10 100644 --- a/src/vtype-extra.c +++ b/src/vtype-extra.c @@ -19,13 +19,13 @@ double: "%."s__(DBL_DIG)"lg",\ long double: "%."s__(LDBL_DIG)"Lg") -#define stringify(v) sprintf(STRINGIFY_BUFFER, fstring(v), (v)) +#define stringify(v) sprintf(STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS], fstring(v), (v)) -static _Thread_local char STRINGIFY_BUFFER[64]; +static _Thread_local int STRINGIFY_BUFFER_POS = 0; +static _Thread_local char STRINGIFY_BUFFER[16][64]; /*#####################################################################################################################*/ - const size_t LIBCDSB_VTYPE_SIZES[19] = { sizeof(void*), sizeof(bool), sizeof(u8_t), sizeof(u16_t), sizeof(u32_t), sizeof(u64_t), @@ -35,12 +35,13 @@ const size_t LIBCDSB_VTYPE_SIZES[19] = { sizeof(list_t), sizeof(set_t), sizeof(dict_t) }; - /*#####################################################################################################################*/ - const char* libcdsb_vtype_name(vtype t) { - switch (t) { default: abort(); + switch (t) { + #ifndef NDEBUG + default: abort(); + #endif case VTYPE_POINTER: return "VTYPE_POINTER"; case VTYPE_BOOLEAN: return "VTYPE_BOOLEAN"; case VTYPE_UINT8: return "VTYPE_UINT8"; @@ -69,6 +70,9 @@ const char* libcdsb_vtype_stringify(const void* v, vtype t) { if (t == VTYPE_BOOLEAN) return (*(vtype_bool*)v) ? "true" : "false"; if (t == VTYPE_STRING) return *(char**)v; + if (STRINGIFY_BUFFER_POS > 15) + STRINGIFY_BUFFER_POS = 0; + switch (t) { case VTYPE_INT8: stringify(*( s8_t*)v); break; case VTYPE_INT16: stringify(*( s16_t*)v); break; @@ -79,25 +83,25 @@ const char* libcdsb_vtype_stringify(const void* v, vtype t) { case VTYPE_UINT32: stringify(*( u32_t*)v); break; case VTYPE_UINT64: stringify(*( u64_t*)v); break; case VTYPE_FLOAT: if (abs(*(fl_t*)v) <= FLT_EPSILON) { - STRINGIFY_BUFFER[0] = 0x30; - STRINGIFY_BUFFER[1] = 0x00; + STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS][0] = 0x30; + STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS][1] = 0x00; } else stringify(*(fl_t*)v); break; case VTYPE_DOUBLE: if (abs(*(dbl_t*)v) <= DBL_EPSILON) { - STRINGIFY_BUFFER[0] = 0x30; - STRINGIFY_BUFFER[1] = 0x00; + STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS][0] = 0x30; + STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS][1] = 0x00; } else stringify(*(dbl_t*)v); break; case VTYPE_LDOUBLE: if (abs(*(ldbl_t*)v) <= LDBL_EPSILON) { - STRINGIFY_BUFFER[0] = 0x30; - STRINGIFY_BUFFER[1] = 0x00; + STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS][0] = 0x30; + STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS][1] = 0x00; } else stringify(*(ldbl_t*)v); break; - case VTYPE_POINTER: sprintf(STRINGIFY_BUFFER, (sizeof(void*) == 8) ? "0x%016lx" : "0x%08x", (uintptr_t)*(void**)v); break; + case VTYPE_POINTER: sprintf(STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS], (sizeof(void*) == 8) ? "0x%016lx" : "0x%08x", (uintptr_t)*(void**)v); break; - default: sprintf(STRINGIFY_BUFFER, "<%s>", libcdsb_vtype_name(t)); + default: sprintf(STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS], "<%s>", libcdsb_vtype_name(t)); break; } - return STRINGIFY_BUFFER; + return STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS++]; } From ca8251973e6aa62086da55aba1b5efd2cdd83d8d Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Mon, 22 Aug 2022 12:13:20 +0300 Subject: [PATCH 10/18] Refactor string --- examples/string.c | 10 +- include/string.h | 98 +++------- src/string/access.c | 61 ++++++ src/string/base.c | 142 -------------- src/string/comparison.c | 66 +++++++ src/string/compute.c | 60 ++++++ src/string/copy.c | 78 ++++++++ src/string/extra-align.c | 142 -------------- src/string/extra-split.c | 89 --------- src/string/get.c | 174 ------------------ src/string/include.h | 2 +- src/string/modify.c | 275 ++++++++++++++++++++++++++++ src/string/replace.c | 223 ---------------------- src/string/{extra.c => transform.c} | 142 +++++--------- src/string/trim.c | 160 ---------------- tests/include/test.h | 2 +- tests/src/string/main.c | 10 +- tests/src/string/plug.h | 2 +- tests/src/string/src/random.c | 2 +- 19 files changed, 627 insertions(+), 1111 deletions(-) create mode 100644 src/string/access.c delete mode 100644 src/string/base.c create mode 100644 src/string/comparison.c create mode 100644 src/string/compute.c create mode 100644 src/string/copy.c delete mode 100644 src/string/extra-align.c delete mode 100644 src/string/extra-split.c delete mode 100644 src/string/get.c create mode 100644 src/string/modify.c delete mode 100644 src/string/replace.c rename src/string/{extra.c => transform.c} (65%) delete mode 100644 src/string/trim.c diff --git a/examples/string.c b/examples/string.c index 4072af5..9494a79 100644 --- a/examples/string.c +++ b/examples/string.c @@ -2,8 +2,8 @@ /* Copyright © 2022 Gregory Lirent */ #include -#include "../include/extra/string.h" -#include "../include/extra/array.h" +#include "../include/array.h" +#include "../include/string.h" typedef vtype_string str_t; typedef vtype_array arr_t; @@ -25,14 +25,14 @@ int main(int argc, char** argv) { printf("%s\n", str.buffer); - arr_t parts = string_split(&str, ',', -1); + arr_t parts = string_split(&str, ','); printf("%lu\n", array_size(&parts)); for (size_t i = 0; i < array_size(&parts); ++i) { - str_t* value = array_at(&parts, i); + str_t* value = at_array(&parts, i); - string_trim_spaces(value); + string_trim(value, 0); printf("%s (%lu)\n", value->buffer, string_nmemb(value)); } diff --git a/include/string.h b/include/string.h index b8e8474..8b9c516 100644 --- a/include/string.h +++ b/include/string.h @@ -1,88 +1,48 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "__generics.h" +#include "bits/__generics.h" #include "vtype.h" -#include #ifndef LIBCDSB_STRING_H #define LIBCDSB_STRING_H /*#####################################################################################################################*/ -extern void string_init(vtype_string* x, const char* value) Nonnull__(1); +extern size_t string_slice (vtype_string* x, vtype_string* s, ssize_t index, size_t nchars, bool cut) Nonnull__(1,2); +extern size_t string_reverse (vtype_string* x) Nonnull__(1); +extern size_t string_to_lower (vtype_string* x) Nonnull__(1); +extern size_t string_to_upper (vtype_string* x) Nonnull__(1); +extern size_t string_capitalize(vtype_string* x) Nonnull__(1); -extern char* string_at(const vtype_string* s, ssize_t index) Nonnull__(1); -extern size_t string_slice(vtype_string* x, vtype_string* s, ssize_t index, size_t nchars, bool cut) Nonnull__(1,2); - -#define string_indexof(s, arg) _LIBCDSB_GenericS(libcdsb_string, indexof, arg)(s, arg) -#define string_count(s, arg) _LIBCDSB_GenericS(libcdsb_string, count, arg)(s, arg) -#define string_concat(x, value) _LIBCDSB_GenericS(libcdsb_string, concat, value)(x, value) - -#define string_trim_spaces(x) libcdsb_string_trim_spaces(x, 0) -#define string_ltrim_spaces(x) libcdsb_string_trim_spaces(x, -1) -#define string_rtrim_spaces(x) libcdsb_string_trim_spaces(x, 1) - -#define string_replace(x, src, dest, maxn) _LIBCDSB_GenericS2(libcdsb_string, replace, src, dest)(x, src, dest, maxn) +extern char* at_string (const vtype_string* s, ssize_t index) Nonnull__(1); /*#####################################################################################################################*/ -inline ssize_t libcdsb_string_indexof_string (const vtype_string* s, const vtype_string* arg) Pure__ Warn_unused_result__ Nonnull__(1) Always_inline__; -extern ssize_t libcdsb_string_indexof_cstring(const vtype_string* s, const char* arg) Pure__ Warn_unused_result__ Nonnull__(1); -extern ssize_t libcdsb_string_indexof_char (const vtype_string* s, int arg) Pure__ Warn_unused_result__ Nonnull__(1); - -inline size_t libcdsb_string_count_string (const vtype_string* s, const vtype_string* arg) Pure__ Warn_unused_result__ Nonnull__(1) Always_inline__; -extern size_t libcdsb_string_count_cstring(const vtype_string* s, const char* arg) Pure__ Warn_unused_result__ Nonnull__(1); -extern size_t libcdsb_string_count_char (const vtype_string* s, int arg) Pure__ Warn_unused_result__ Nonnull__(1); - -inline bool libcdsb_string_concat_string (vtype_string* x, const vtype_string* value) Nonnull__(1) Always_inline__; -extern bool libcdsb_string_concat_cstring(vtype_string* x, const char* value) Nonnull__(1); -extern bool libcdsb_string_concat_char (vtype_string* x, int value) Nonnull__(1); - -extern void libcdsb_string_trim_spaces(vtype_string* x, int direction) Nonnull__(1); - -inline size_t libcdsb_string_replace_string_string (vtype_string* x, const vtype_string* src, const vtype_string* dest, size_t maxn) Nonnull__(1) Always_inline__; -inline size_t libcdsb_string_replace_string_cstring (vtype_string* x, const vtype_string* src, const char* dest, size_t maxn) Nonnull__(1) Always_inline__; -inline size_t libcdsb_string_replace_string_char (vtype_string* x, const vtype_string* src, int dest, size_t maxn) Nonnull__(1) Always_inline__; -inline size_t libcdsb_string_replace_cstring_string (vtype_string* x, const char* src, const vtype_string* dest, size_t maxn) Nonnull__(1) Always_inline__; -extern size_t libcdsb_string_replace_cstring_cstring(vtype_string* x, const char* src, const char* dest, size_t maxn) Nonnull__(1); -extern size_t libcdsb_string_replace_cstring_char (vtype_string* x, const char* src, int dest, size_t maxn) Nonnull__(1); -inline size_t libcdsb_string_replace_char_string (vtype_string* x, int src, const vtype_string* dest, size_t maxn) Nonnull__(1) Always_inline__; -extern size_t libcdsb_string_replace_char_cstring (vtype_string* x, int src, const char* dest, size_t maxn) Nonnull__(1); -extern size_t libcdsb_string_replace_char_char (vtype_string* x, int src, int dest, size_t maxn) Nonnull__(1); +#define string_init(x, s) libcdsb_string_init (x, _LIBCDSB_to_cstring(s), 0) +#define string_indexof(x, s) libcdsb_string_indexof(x, _LIBCDSB_to_cstring(s)) +#define string_count(x, s) libcdsb_string_count (x, _LIBCDSB_to_cstring(s), 0) +#define string_concat(x, s) libcdsb_string_concat (x, _LIBCDSB_to_cstring(s), 0) +#define string_align(x, n, c) libcdsb_string_align (x, n, c, 0) +#define string_lalign(x, n, c) libcdsb_string_align (x, n, c, -1) +#define string_ralign(x, n, c) libcdsb_string_align (x, n, c, 1) +#define string_split(x, s) libcdsb_string_split (x, _LIBCDSB_to_cstring(s), 0, -1) +#define string_trim(x, s) libcdsb_string_trim (x, _LIBCDSB_to_cstring(s), 0) +#define string_ltrim(x, s) libcdsb_string_trim (x, _LIBCDSB_to_cstring(s), -1) +#define string_rtrim(x, s) libcdsb_string_trim (x, _LIBCDSB_to_cstring(s), 1) +#define string_replace(x, s, d) libcdsb_string_replace(x, _LIBCDSB_to_cstring(s), 0, _LIBCDSB_to_cstring(d), 0, -1) /*#####################################################################################################################*/ -inline ssize_t libcdsb_string_indexof_string(const vtype_string* s, const vtype_string* arg) { - return string_indexof(s, arg->buffer); -} +inline void libcdsb_string_init (vtype_string* x, const char* s, size_t nmemb) Always_inline__ Nonnull__(1); +extern bool libcdsb_string_concat (vtype_string* x, const char* s, size_t nmemb) Nonnull__(1); +extern void libcdsb_string_trim (vtype_string* x, const char* s, int direction) Nonnull__(1); +extern size_t libcdsb_string_align (vtype_string* x, size_t padsize, int padchr, int direction) Nonnull__(1); +extern ssize_t libcdsb_string_indexof(const vtype_string* x, const char* s) Pure__ Warn_unused_result__ Nonnull__(1); +extern size_t libcdsb_string_count (const vtype_string* x, const char* s, size_t nmemb) Pure__ Warn_unused_result__ Nonnull__(1); +extern vtype_array libcdsb_string_split (const vtype_string* x, const char* s, size_t nmemb, size_t maxn) Nonnull__(1); +extern size_t libcdsb_string_replace(vtype_string* x, const char* s, size_t snmemb, const char* d, size_t dnmemb, size_t maxn) Nonnull__(1,2); -inline size_t libcdsb_string_count_string(const vtype_string* s, const vtype_string* arg) { - return string_count(s, arg->buffer); -} +inline void libcdsb_string_init (vtype_string* x, const char* s, size_t nmemb) { x->buffer = ((nmemb) ? libcdsb_strndup(s, nmemb) : libcdsb_strdup(s)); } -inline bool libcdsb_string_concat_string(vtype_string* x, const vtype_string* s) { - return string_concat(x, s->buffer); -} - -inline size_t libcdsb_string_replace_string_string (vtype_string* x, const vtype_string* src, const vtype_string* dest, size_t maxn) { - return string_replace(x, src->buffer, dest->buffer, maxn); -} - -inline size_t libcdsb_string_replace_string_cstring(vtype_string* x, const vtype_string* src, const char* dest, size_t maxn) { - return string_replace(x, src->buffer, dest, maxn); -} - -inline size_t libcdsb_string_replace_cstring_string(vtype_string* x, const char* src, const vtype_string* dest, size_t maxn) { - return string_replace(x, src, dest->buffer, maxn); -} - -inline size_t libcdsb_string_replace_string_char (vtype_string* x, const vtype_string* src, int dest, size_t maxn) { - return string_replace(x, src->buffer, dest, maxn); -} - -inline size_t libcdsb_string_replace_char_string (vtype_string* x, int src, const vtype_string* dest, size_t maxn) { - return string_replace(x, src, dest->buffer, maxn); -} - -#endif /* LIBCDSB_BASE_STRING_H */ +#endif /* LIBCDSB_STRING_H */ diff --git a/src/string/access.c b/src/string/access.c new file mode 100644 index 0000000..c846732 --- /dev/null +++ b/src/string/access.c @@ -0,0 +1,61 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +char* at_string(const str_t* s, ssize_t i) { + char *e, *p; + size_t n, l; + + if (is_null(s->buffer) || !*s->buffer) + return nullptr; + + n = strasciilen(s->buffer); + e = s->buffer + n; + + if (i > n) { + p = s->buffer + n; + e = p + strlen(p); + + do { p = next_char(p); } while (--i && p < e); + return (!i) ? p : nullptr; + + } else if (i < 0 && n < (l = strlen(s->buffer))) { + p = s->buffer + l; + + do { p = prev_char(p); } while (++i && p >= s->buffer); + return (!i) ? p : nullptr; + + } else if (i < 0 && (i += l) < 0) i = 0; + + return s->buffer + i; +} + + +ssize_t libcdsb_string_indexof(const str_t* x, const char* s) { + char *e, *p; + size_t n; + + if (is_null(x->buffer) || is_null(s) || !*x->buffer || !*s) { + return 0; + } + + if (!is_null(p = strstr(x->buffer, s))) { + n = strasciilen(x->buffer); + e = x->buffer + n; + + if (e >= p) return p - x->buffer; + + do { + e = next_char(e); + ++n; + } while (e < p); + + if (e != p) { + /* Trying to find index of inconsistent string part + * It is not make a sense on that abstract level */ + } else return n; + } + + return -1; +} diff --git a/src/string/base.c b/src/string/base.c deleted file mode 100644 index 805140d..0000000 --- a/src/string/base.c +++ /dev/null @@ -1,142 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - -hash_t string_hash(const str_t* s) { - hash_t hash = 0; - size_t nmemb = string_nmemb(s); - - if (nmemb > 0) - hash = s->buffer[0]; - - if (nmemb > 1) - hash += s->buffer[nmemb-1]; - - hash ^= nmemb; - - return hash + VTYPE_STRING; -} - - -size_t string_nmemb(const str_t* s) { - return (!is_null(s->buffer)) ? strlen(s->buffer) : 0; -} - - -size_t string_size(const str_t* s) { - size_t n; - char* p; - - if (is_null(s->buffer) || !*s->buffer) - return 0; - - n = strasciilen(s->buffer); - p = s->buffer + n; - - while (*p) { - p = next_char(p); - ++n; - } - - return n; -} - - -void string_init(str_t* x, const char* s) { - size_t n = (!is_null(s)) ? strlen(s) : 0; - - if (n) x->buffer = strndup(s, n); - else memset(x, 0, sizeof(*x)); -} - - -void string_free(str_t* x) { - free(x->buffer); - memset(x, 0, sizeof(*x)); -} - - -int string_compare(const str_t* s0, const str_t* s1) { - ssize_t n0, n1; - - if (s0 == s1) return 0; - - n0 = (!is_null(s0->buffer)) ? strlen(s0->buffer) : 0; - n1 = (!is_null(s1->buffer)) ? strlen(s1->buffer) : 0; - - n0 -= n1; - - if (n0 || !n1) return n0; - - return memcmp(s0->buffer, s1->buffer, n1); -} - - -/*#####################################################################################################################*/ - - -bool libcdsb_string_concat_cstring(str_t* x, const char* s) { - size_t n; - size_t xn; - - if ((n = (!is_null(s)) ? strlen(s) : 0)) { - xn = (!is_null(x->buffer)) ? strlen(x->buffer) : 0; - - x->buffer = realloc(x->buffer, xn + ++n); - memcpy(x->buffer + xn, s, n); - - return true; - } - - return false; -} - - -bool libcdsb_string_concat_char(str_t* x, int chr) { - size_t xn; - size_t n; - char *e; - char s[5] = {0}; - - if (!is_null(e = tochar_unicode(s, chr))) { - xn = (!is_null(x->buffer)) ? strlen(x->buffer) : 0; - n = e - s; - - x->buffer = realloc(x->buffer, xn + ++n); - memcpy(x->buffer + xn, s, n); - - return true; - } - - return false; -} - - -/*#####################################################################################################################*/ - - -str_t string_copy(const str_t* s) { - str_t x = { .buffer = 0 }; - size_t n = (!is_null(s->buffer)) ? strlen(s->buffer) : 0; - - if (n) x.buffer = strndup(s->buffer, n); - return x; -} - - -str_t* string_duplicate(const str_t* s) { - str_t* x = calloc(sizeof(*x), 1); - size_t n = (!is_null(s->buffer)) ? strlen(s->buffer) : 0; - - if (n) x->buffer = strndup(s->buffer, n); - return x; -} - - -void string_copy_init(str_t* x, const str_t* s) { - size_t n = (!is_null(s->buffer)) ? strlen(s->buffer) : 0; - - if (n) x->buffer = strndup(s->buffer, n); - else memset(x, 0, sizeof(*x)); -} diff --git a/src/string/comparison.c b/src/string/comparison.c new file mode 100644 index 0000000..5d07cfc --- /dev/null +++ b/src/string/comparison.c @@ -0,0 +1,66 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include +#include "include.h" + +int string_compare(const str_t* s0, const str_t* s1) { + ssize_t n0, n1; + + if (s0 == s1) return 0; + + n0 = (!is_null(s0->buffer)) ? strlen(s0->buffer) : 0; + n1 = (!is_null(s1->buffer)) ? strlen(s1->buffer) : 0; + + n0 -= n1; + + if (n0 || !n1) return n0; + + return memcmp(s0->buffer, s1->buffer, n1); +} + + +int string_case_compare(const str_t* s0, const str_t* s1) { + const char *p0, *p1, *t0, *t1; + ssize_t n0, n1; + u32_t uc0, uc1; + + if (s0 == s1) return 0; + + p0 = s0->buffer; + p1 = s1->buffer; + n0 = (!is_null(p0)) ? strasciilen(p0) : 0; + n1 = (!is_null(p1)) ? strasciilen(p1) : 0; + + n0 -= n1; + + if (!n0 && n1) { + do { + n0 = toupper(*(p0++)); + n0 -= toupper(*(p1++)); + if (n0) return n0; + } while(--n1); + + } else return memcmp(s0->buffer, s1->buffer, n1); + + while (*p0 && *p1) { + t0 = fromchar_unicode(&uc0, p0); + t1 = fromchar_unicode(&uc1, p1); + + if (is_null(t0) || is_null(t1)) { + n0 = (ssize_t)*(unsigned char*)(p0++) - *(unsigned char*)(p1++); + if (n0) return n0; + } else { + n0 = toupper_unicode(uc0); + if ((n0 -= toupper_unicode(uc1))) + return n0; + + p0 = t0; + p1 = t1; + } + } + + n0 = *(unsigned char*)p0 - *(unsigned char*)p1; + + return n0; +} diff --git a/src/string/compute.c b/src/string/compute.c new file mode 100644 index 0000000..ef8e2ce --- /dev/null +++ b/src/string/compute.c @@ -0,0 +1,60 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +size_t string_size(const str_t* s) { + size_t n; + char* p; + + if (is_null(s->buffer) || !*s->buffer) + return 0; + + n = strasciilen(s->buffer); + p = s->buffer + n; + + while (*p) { + p = next_char(p); + ++n; + } + + return n; +} + + +hash_t string_hash(const str_t* s) { + hash_t hash = 0; + size_t nmemb = string_nmemb(s); + + if (nmemb > 0) + hash = s->buffer[0]; + + if (nmemb > 1) + hash += s->buffer[nmemb-1]; + + hash ^= nmemb; + + return hash + VTYPE_STRING; +} + + +size_t libcdsb_string_count(const str_t* x, const char* s, size_t sn) { + char* p; + size_t c; + + if (is_null(x->buffer) || is_null(s) || !*x->buffer || !*s) { + return 0; + } + + if (!sn) sn = strlen(s); + + p = x->buffer; + c = 0; + + while (!is_null(p = strstr(p, s))) { + p += sn; + ++c; + } + + return c; +} diff --git a/src/string/copy.c b/src/string/copy.c new file mode 100644 index 0000000..498e68a --- /dev/null +++ b/src/string/copy.c @@ -0,0 +1,78 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +size_t string_slice(str_t* x, str_t* s, ssize_t i, size_t c, bool cut) { + char *e, *p, *v; + size_t n = 0; + + memset(x, 0, sizeof(*x)); + + if (!c) return n; + + p = at_string(s, i); + + if (is_null(p)) + return n; + + e = p + strlen(p); + v = p; + + while (c-- && v < e) { + v = next_char(v); + ++n; + } + + x->buffer = strndup(p, v - p); + + if (cut) { + memmove(p, v, strlen(v) + 1); + } + + return n; +} + + +arr_t libcdsb_string_split(const str_t* x, const char* s, size_t sn, size_t maxn) { + arr_t ret; + char *p, *e; + str_t* v; + + ret.mem = 0; + ret.size = 0; + ret.type = VTYPE_STRING; + + if (is_null(x->buffer)) + return ret; + + if (is_null(s) || !*s) { + v = ret.mem = malloc(sizeof(str_t)); + v->buffer = strdup(x->buffer); + + return ret; + } + + if (!sn) sn = strlen(s); + p = x->buffer; + e = p; + + while (maxn-- && !is_null(p = strstr(p, s))) { + p += sn; + v = ret.mem = realloc(ret.mem, ++ret.size * sizeof(str_t)); + + v[ret.size-1].buffer = strndup(e, p - e); + + p += sn; + e = p; + } + + if (*e) { + sn = strlen(e); + v = ret.mem = realloc(ret.mem, ++ret.size*sizeof(str_t)); + + v[ret.size-1].buffer = strndup(e, sn); + } + + return ret; +} diff --git a/src/string/extra-align.c b/src/string/extra-align.c deleted file mode 100644 index ebfb8d1..0000000 --- a/src/string/extra-align.c +++ /dev/null @@ -1,142 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - - -/*#####################################################################################################################*/ - - -static char* string_info(const vtype_string* s, size_t* size, size_t* nmemb) { - - char* p; - char* v; - - if (is_null(s->buffer) || !*s->buffer) { - *size = *nmemb = 0; - return s->buffer; - } - - *size = *nmemb = strasciilen(s->buffer); - p = s->buffer + *nmemb; - - if (!*p) return p; - - while (*(v = next_char(p))) { - ++*size; - *nmemb += v - p; - p = v; - } - ++*size; - *nmemb += v - p; - - return p; -} - - -static int fetch_pad(char buffer[4], int chr) { - - char* p; - - if (chr) { - p = tochar_unicode(buffer, chr); - chr = !is_null(p) ? p - buffer : 0; - } - - if (!chr) { - *buffer = ' '; - chr = 1; - } - - return chr; -} - - -/*#####################################################################################################################*/ - - -size_t string_align_center(vtype_string* x, size_t n, int pc) { - - char s[4]; - size_t l; - size_t ls; - size_t rs; - char* p; - - string_info(x, &ls, &l); - - if (ls < n) { - pc = fetch_pad(s, pc); - ls = n - ls; - rs = ls / 2; - } else return ls; - - x->buffer = p = realloc(x->buffer, l + ls*pc + 1); - memmove(x->buffer + (ls -= rs)*pc, x->buffer, l); - - for (size_t i = 0; i < ls; ++i) { - p = memcpy(p, s, pc) + pc; - } - - p += l; - - for (size_t i = 0; i < rs; ++i) { - p = memcpy(p, s, pc) + pc; - } - - *p = 0; - - return n; -} - - -size_t string_align_right(vtype_string* x, size_t n, int pc) { - - char s[4]; - size_t l; - size_t ls; - char* p; - - string_info(x, &ls, &l); - - if (ls < n) { - pc = fetch_pad(s, pc); - ls = n - ls; - } else return ls; - - x->buffer = p = realloc(x->buffer, ++l + ls*pc); - memmove(x->buffer + ls*pc, x->buffer, l); - - for (size_t i = 0; i < ls; ++i) { - p = memcpy(p, s, pc) + pc; - } - - return n; -} - - -size_t string_align_left(vtype_string* x, size_t n, int pc) { - - char s[4]; - size_t l; - size_t rs; - char* p; - - string_info(x, &rs, &l); - - if (rs < n) { - pc = fetch_pad(s, pc); - rs = n - rs; - } else return rs; - - x->buffer = realloc(x->buffer, l + rs*pc + 1); - p = x->buffer + l; - - for (size_t i = 0; i < rs; ++i) { - p = memcpy(p, s, pc) + pc; - } - - *p = 0; - - return n; -} diff --git a/src/string/extra-split.c b/src/string/extra-split.c deleted file mode 100644 index 7879fc3..0000000 --- a/src/string/extra-split.c +++ /dev/null @@ -1,89 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - -arr_t libcdsb_string_split_cstring(const str_t* s, const char* a, size_t maxn) { - arr_t x = { .mem = 0, .size = 0, .type = VTYPE_STRING }; - - size_t n; - char* p; - char* e; - str_t* v; - - if (is_null(s->buffer)) { - return x; - } - - if (is_null(a) || !*a) { - v = x.mem = malloc(sizeof(str_t)); - v->buffer = strdup(s->buffer); - return x; - } - - n = strlen(a); - p = s->buffer; - e = p; - - while (maxn-- && !is_null(p = strstr(p, a))) { - p += n; - v = x.mem = realloc(x.mem, ++x.size*sizeof(str_t)); - - v[x.size-1].buffer = strndup(e, p - e); - - p += n; - e = p; - } - - if (*e) { - n = strlen(e); - v = x.mem = realloc(x.mem, ++x.size*sizeof(str_t)); - - v[x.size-1].buffer = strndup(e, n); - } - - return x; -} - - -arr_t libcdsb_string_split_char(const str_t* s, int ac, size_t maxn) { - arr_t x = { .mem = 0, .size = 0, .type = VTYPE_STRING }; - char a[5] = { 0 }; - - size_t n; - char* p; - char* e; - str_t* v; - - if (is_null(s->buffer)) { - return x; - } - - if (is_null(p = tochar_unicode(a, ac)) || !(n = p - a)) { - v = x.mem = malloc(sizeof(str_t)); - v->buffer = strdup(s->buffer); - return x; - } - - p = s->buffer; - e = p; - - while (maxn-- && !is_null(p = strstr(p, a))) { - p += n; - v = x.mem = realloc(x.mem, ++x.size*sizeof(str_t)); - - v[x.size-1].buffer = strndup(e, p - e); - - p += n; - e = p; - } - - if (*e) { - n = strlen(e); - v = x.mem = realloc(x.mem, ++x.size*sizeof(str_t)); - - v[x.size-1].buffer = strndup(e, n); - } - - return x; -} diff --git a/src/string/get.c b/src/string/get.c deleted file mode 100644 index 4f2cac5..0000000 --- a/src/string/get.c +++ /dev/null @@ -1,174 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - -char* string_at(const str_t* s, ssize_t i) { - char *e, *p; - size_t n, l; - - if (is_null(s->buffer) || !*s->buffer) - return nullptr; - - n = strasciilen(s->buffer); - e = s->buffer + n; - - if (i > n) { - p = s->buffer + n; - e = p + strlen(p); - - do { p = next_char(p); } while (--i && p < e); - return (!i) ? p : nullptr; - - } else if (i < 0 && n < (l = strlen(s->buffer))) { - p = s->buffer + l; - - do { p = prev_char(p); } while (++i && p >= s->buffer); - return (!i) ? p : nullptr; - - } else if (i < 0 && (i += l) < 0) i = 0; - - return s->buffer + i; -} - - -size_t string_slice(str_t* x, str_t* s, ssize_t i, size_t c, bool cut) { - char *e, *p, *v; - size_t n = 0; - - memset(x, 0, sizeof(*x)); - - if (!c) return n; - - p = string_at(s, i); - - if (is_null(p)) - return n; - - e = p + strlen(p); - v = p; - - while (c-- && v < e) { - v = next_char(v); - ++n; - } - - x->buffer = strndup(p, v - p); - - if (cut) { - memmove(p, v, strlen(v) + 1); - } - - return n; -} - - -/*#####################################################################################################################*/ - - -ssize_t libcdsb_string_indexof_cstring(const str_t* s, const char* a) { - char *e, *p; - size_t n; - - if (is_null(s->buffer) || is_null(a) || !*s->buffer || !*a) { - return 0; - } - - if (!is_null(p = strstr(s->buffer, a))) { - n = strasciilen(s->buffer); - e = s->buffer + n; - - if (e >= p) return p - s->buffer; - - do { - e = next_char(e); - ++n; - } while (e < p); - - if (e != p) { - /* Trying to find index of inconsistent string part - * It is not make a sense on that abstract level */ - } else return n; - } - - return -1; -} - - -ssize_t libcdsb_string_indexof_char(const str_t* s, int ac) { - size_t n; - char* e; - - char a[5] = { 0 }; - char* p = tochar_unicode(a, ac); - - if (is_null(s->buffer) || !*s->buffer || is_null(p)) { - return 0; - } - - if (!is_null(p = strstr(s->buffer, a))) { - n = strasciilen(s->buffer); - e = s->buffer + n; - - if (e >= p) return p - s->buffer; - - do { - e = next_char(e); - ++n; - } while (e < p); - - if (e != p) { - /* Trying to find index of inconsistent string part - * It is not make a sense on that abstract level */ - } else return n; - } - - return -1; -} - - -/*#####################################################################################################################*/ - - -size_t libcdsb_string_count_cstring(const str_t* s, const char* a) { - char* p; - size_t n, c; - - if (is_null(s->buffer) || is_null(a) || !*s->buffer || !*a) { - return 0; - } - - n = strlen(a); - p = s->buffer; - c = 0; - - while (!is_null(p = strstr(p, a))) { - p += n; - ++c; - } - - return c; -} - - -size_t libcdsb_string_count_char(const str_t* s, int ac) { - size_t n, c; - - char a[5] = {0}; - char* p = tochar_unicode(a, ac); - - if (is_null(s->buffer) || !*s->buffer || is_null(p)) { - return 0; - } - - n = p - a; - p = s->buffer; - c = 0; - - while (!is_null(p = strstr(p, a))) { - p += n; - ++c; - } - - return c; -} diff --git a/src/string/include.h b/src/string/include.h index a0a4764..15b1960 100644 --- a/src/string/include.h +++ b/src/string/include.h @@ -2,7 +2,7 @@ /* Copyright © 2022 Gregory Lirent */ #include "../../modules/libunic/include.h" -#include "../../include/extra/string.h" +#include "../../include/string.h" #include "../__internal/include.h" #ifndef LIBCDSB_SRC_STRING_INCLUDE_H diff --git a/src/string/modify.c b/src/string/modify.c new file mode 100644 index 0000000..255bfb3 --- /dev/null +++ b/src/string/modify.c @@ -0,0 +1,275 @@ +/* This software is licensed by the MIT License, see LICENSE file */ +/* Copyright © 2022 Gregory Lirent */ + +#include "include.h" + +static void string_trim_spaces(str_t* x, int direction) { + static size_t m[32/(sizeof(size_t))] = {0}; + + u8_t* l; + u8_t* r; + + if (sizeof(size_t) == 8) { + m[0] = 0x0000000100002e00UL; + } else { + m[0] = 0x00002e00UL; + m[1] = 0x00000001UL; + } + + if (is_null(x->buffer)) + return; + + l = (void*)x->buffer; + r = (void*)x->buffer + strlen(x->buffer); + + if (direction <= 0) { + while (m[*l/(8*sizeof(size_t))]&((size_t)1<<(*l%(8*sizeof(size_t))))) { + ++l; + } + } + + if (direction >= 0) { + do { + --r; + } while (m[*r/(8*sizeof(size_t))]&((size_t)1<<(*r%(8*sizeof(size_t))))); + ++r; + } + + if (x->buffer != (char*)l) { + memmove(x->buffer, l, r-l); + r -= (char*)l - x->buffer; + } + + *r = 0; +} + + +static char* string_info(const str_t* s, size_t* size, size_t* nmemb) { + + char* p; + char* v; + + if (is_null(s->buffer) || !*s->buffer) { + *size = *nmemb = 0; + return s->buffer; + } + + *size = *nmemb = strasciilen(s->buffer); + p = s->buffer + *nmemb; + + if (!*p) return p; + + while (*(v = next_char(p))) { + ++*size; + *nmemb += v - p; + p = v; + } + ++*size; + *nmemb += v - p; + + return p; +} + + +static int fetch_pad(char buffer[4], int chr) { + + char* p; + + if (chr) { + p = tochar_unicode(buffer, chr); + chr = !is_null(p) ? p - buffer : 0; + } + + if (!chr) { + *buffer = ' '; + chr = 1; + } + + return chr; +} + +/*#####################################################################################################################*/ + +bool libcdsb_string_concat(str_t* x, const char* s, size_t n) { + size_t xn; + + if (n || (n = !is_null(s) ? strlen(s) : 0)) { + xn = (!is_null(x->buffer)) ? strlen(x->buffer) : 0; + + x->buffer = realloc(x->buffer, xn + ++n); + memcpy(x->buffer + xn, s, n); + + return true; + } + + return false; +} + + +void libcdsb_string_trim(str_t* x, const char* s, int direction) { + + u8_t* l; + u8_t* r; + size_t n; + bool f; + + struct { + const char* p; + size_t n; + }* m; + + if (is_null(s)) { + string_trim_spaces(x, direction); + return; + } + + if (is_null(x->buffer) || !*s) + return; + + if (x->buffer == s) { + *x->buffer = 0; + return; + } + + n = 0; + m = 0; + + while (*(l = (void*)next_char((void*)s))) { + m = realloc(m, ++n*sizeof(*m)); + m[n-1].n = (char*)l - s; + m[n-1].p = s; + s = (void*)l; + } + + m = realloc(m, ++n*sizeof(*m)); + m[n-1].n = (char*)l - s; + m[n-1].p = s; + + l = (void*)x->buffer; + r = (void*)x->buffer + strlen(x->buffer); + + if (direction <= 0) { + f = false; + do for (size_t i = 0; i < n; ++i) { + if (memcmp(l, m[i].p, m[i].n) == 0) { + f = true; + l += m[i].n; + break; + } + } while(f && !(f = false)); + } + + if (direction >= 0) { + f = false; + do for (size_t i = 0; i < n; ++i) { + if (memcmp(r - m[i].n, m[i].p, m[i].n) == 0) { + f = true; + r -= m[i].n; + break; + } + } while(f && !(f = false)); + } + + if (x->buffer != (char*)l) { + memmove(x->buffer, l, r-l); + r -= (char*)l - x->buffer; + } + + *r = 0; +} + + +size_t libcdsb_string_align(str_t* x, size_t n, int pc, int direction) { + char *p, s[4]; + size_t l, ls, rs; + + string_info(x, &ls, &l); + + if (ls < n) { + pc = fetch_pad(s, pc); + + if (direction == 0) { + ls = n - ls; + rs = ls / 2; + ls -= rs; + } else if (direction < 0) { + rs = n - ls; + ls = 0; + } else { + ls = n - ls; + rs = 0; + } + } else return ls; + + x->buffer = p = realloc(x->buffer, l + ((ls + rs) * pc) + 1); + + if (ls) { + memmove(x->buffer + ls * pc, x->buffer, l); + + do { + p = memcpy(p, s, pc) + pc; + } while (--ls); + + p += l; + } else p = x->buffer + l; + + while (rs--) p = memcpy(p, s, pc) + pc; + *p = 0; + + return n; +} + + +size_t libcdsb_string_replace(str_t* x, const char* s, size_t sn, const char* d, size_t dn, size_t m) { + + char *sc, *dc; + char *p; + size_t c, n, o; + + if (is_null(x->buffer) || is_null(s) || !*x->buffer || !*(char*)s) + return 0; + + if (s == d) return string_count(x, s); + + if (!sn) sn = strlen(s); + if (!dn) dn = !is_null(d) ? strlen(d) : dn; + + n = strlen(x->buffer); + p = x->buffer; + sc = dc = (void*)(c = 0); + + if (x->buffer == s) { + x->buffer = realloc(x->buffer, dn + 1); + memcpy(x->buffer, d, dn); + x->buffer[dn] = 0; + + return 1; + } + + if (x->buffer < (char*)s && (char*)s < x->buffer + n) s = sc = memndup(s, sn); + if (x->buffer <= (char*)d && (char*)d < x->buffer + n) d = dc = memndup(d, dn); + + while (m-- && !is_null(p = strstr(p, s))) { + + if (sn != dn) { + size_t l = n; + + if (sn < dn) { + n += dn - sn; + o = p - x->buffer; + x->buffer = realloc(x->buffer, n + 1); + p = x->buffer + o; + } else n -= sn - dn; + + memmove(p + dn, p + sn, l - (p + n - x->buffer) + 1); + } + + p += sn; + ++c; + } + + free(sc); + free(dc); + + return c; +} diff --git a/src/string/replace.c b/src/string/replace.c deleted file mode 100644 index ea08c43..0000000 --- a/src/string/replace.c +++ /dev/null @@ -1,223 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - -size_t libcdsb_string_replace_cstring_cstring(str_t* x, const char* a, const char* d, size_t maxn) { - char *p, *t, *r; - size_t c, n, an, dn; - - if (a == d) return string_count(x, a); - - if (is_null(x->buffer) || is_null(a) || !*x->buffer || !*a) { - return 0; - } - - an = strlen(a); - dn = (!is_null(d)) ? strlen(d) : 0; - n = strlen(x->buffer); - p = x->buffer; - c = 0; - t = 0; - r = 0; - - if (x->buffer == a) { - x->buffer = realloc(x->buffer, dn + 1); - memcpy(x->buffer, d, dn); - x->buffer[dn] = 0; - - return 1; - } - - if (x->buffer < a && a < x->buffer + n) { - a = r = memndup(a, an); - } - - if (x->buffer <= d && d < x->buffer + n) { - d = t = memndup(d, dn); - } - - while (maxn-- && !is_null(p = strstr(p, a))) { - libcdsb_string_replace(x, p, an, d, dn); - p += an; - ++c; - } - - free(r); - free(t); - return c; -} - - -size_t libcdsb_string_replace_cstring_char(str_t* x, const char* a, int dc, size_t maxn) { - char *p, *t; - char d[4]; - size_t c, n, an, dn; - - if (is_null(x->buffer) || is_null(a) || !*x->buffer || !*a) { - return 0; - } - - an = strlen(a); - p = tochar_unicode(d, dc); - dn = (!is_null(p)) ? p - d : 0; - n = strlen(x->buffer); - p = x->buffer; - c = 0; - t = 0; - - if (x->buffer == a) { - x->buffer = realloc(x->buffer, dn + 1); - memcpy(x->buffer, d, dn); - x->buffer[dn] = 0; - - return 1; - } else if (x->buffer < a && a < x->buffer + n) { - a = t = memndup(a, an); - } - - while (maxn-- && !is_null(p = strstr(p, a))) { - libcdsb_string_replace(x, p, an, d, dn); - p += an; - ++c; - } - - free(t); - return c; -} - - -size_t libcdsb_string_replace_char_cstring(str_t* x, int ac, const char* d, size_t maxn) { - char *p, *t; - char a[4]; - size_t c, n, an, dn; - - p = tochar_unicode(a, ac); - - if (is_null(x->buffer) || is_null(p) || !*x->buffer || !*p) { - return 0; - } - - an = p - a; - dn = (!is_null(d)) ? strlen(d) : 0; - n = strlen(x->buffer); - p = x->buffer; - c = 0; - t = 0; - - if (x->buffer <= d && d < x->buffer + n) { - d = t = memndup(d, dn); - } - - while (maxn-- && !is_null(p = strstr(p, a))) { - libcdsb_string_replace(x, p, an, d, dn); - p += an; - ++c; - } - - free(t); - return c; -} - - -size_t libcdsb_string_replace_char_char(str_t* x, int ac, int dc, size_t maxn) { - char* p; - char a[4]; - char d[4]; - size_t c, an, dn; - - p = tochar_unicode(a, ac); - - if (is_null(x->buffer) || is_null(p) || !*x->buffer || !*p) { - return 0; - } - - an = p - a; - p = tochar_unicode(d, dc); - dn = (!is_null(p)) ? p - d : 0; - p = x->buffer; - c = 0; - - while (maxn-- && !is_null(p = strstr(p, a))) { - libcdsb_string_replace(x, p, an, d, dn); - p += an; - ++c; - } - - return c; -} - - - -size_t libcdsb_string_replace_r_cstring_cstring(str_t* x, const char*restrict a, const char*restrict d, size_t maxn) { - char *restrict p; - size_t c, an, dn; - - if (is_null(x->buffer) || is_null(a) || !*x->buffer || !*a) { - return 0; - } - - an = strlen(a); - dn = (!is_null(d)) ? strlen(d) : 0; - p = x->buffer; - c = 0; - - while (maxn-- && !is_null(p = strstr(p, a))) { - libcdsb_string_replace(x, p, an, d, dn); - p += an; - ++c; - } - - return c; -} - - -size_t libcdsb_string_replace_r_cstring_char(str_t* x, const char*restrict a, int dc, size_t maxn) { - char *restrict p; - char d[4]; - size_t c, an, dn; - - if (is_null(x->buffer) || is_null(a) || !*x->buffer || !*a) { - return 0; - } - - an = strlen(a); - p = tochar_unicode(d, dc); - dn = (!is_null(p)) ? p - d : 0; - p = x->buffer; - c = 0; - - while (maxn-- && !is_null(p = strstr(p, a))) { - libcdsb_string_replace(x, p, an, d, dn); - p += an; - ++c; - } - - return c; -} - - -size_t libcdsb_string_replace_r_char_cstring(str_t* x, int ac, const char*restrict d, size_t maxn) { - char *restrict p; - char a[4]; - size_t c, an, dn; - - p = tochar_unicode(a, ac); - - if (is_null(x->buffer) || is_null(p) || !*x->buffer || !*p) { - return 0; - } - - an = p - a; - dn = (!is_null(d)) ? strlen(d) : 0; - p = x->buffer; - c = 0; - - while (maxn-- && !is_null(p = strstr(p, a))) { - libcdsb_string_replace(x, p, an, d, dn); - p += an; - ++c; - } - - return c; -} diff --git a/src/string/extra.c b/src/string/transform.c similarity index 65% rename from src/string/extra.c rename to src/string/transform.c index 6a8d0f0..9ea825d 100644 --- a/src/string/extra.c +++ b/src/string/transform.c @@ -1,60 +1,59 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include #include "include.h" -int string_compare_case_insensitive(const str_t* s0, const str_t* s1) { - const char *p0, *p1, *t0, *t1; - ssize_t n0, n1; - u32_t uc0, uc1; +static void string_replace_builtin(str_t* x, char* p, size_t n, const char* v, size_t vn) { + if (n != vn) { + size_t l = strlen(x->buffer); - if (s0 == s1) return 0; + if (n < vn) { + char* t = x->buffer; - p0 = s0->buffer; - p1 = s1->buffer; - n0 = (!is_null(p0)) ? strasciilen(p0) : 0; - n1 = (!is_null(p1)) ? strasciilen(p1) : 0; - - n0 -= n1; - - if (!n0 && n1) { - do { - n0 = toupper(*(p0++)); - n0 -= toupper(*(p1++)); - if (n0) return n0; - } while(--n1); - - } else return memcmp(s0->buffer, s1->buffer, n1); - - while (*p0 && *p1) { - t0 = fromchar_unicode(&uc0, p0); - t1 = fromchar_unicode(&uc1, p1); - - if (is_null(t0) || is_null(t1)) { - n0 = (ssize_t)*(unsigned char*)(p0++) - *(unsigned char*)(p1++); - if (n0) return n0; - } else { - n0 = toupper_unicode(uc0); - if ((n0 -= toupper_unicode(uc1))) - return n0; - - p0 = t0; - p1 = t1; + x->buffer = realloc(x->buffer, l + (vn - n) + 1); + p = x->buffer + (p - t); } + + memmove(p+vn, p+n, l - (p+n - x->buffer) + 1); } - n0 = *(unsigned char*)p0 - *(unsigned char*)p1; - - return n0; + memcpy(p, v, vn); } - /*#####################################################################################################################*/ +size_t string_reverse(str_t* x) { + char *t, *p, *v; + size_t n; + + if (is_null(x->buffer) || !*x->buffer) + return 0; + + n = strlen(x->buffer); + t = malloc(n + 1); + p = t + n; + v = x->buffer; + n = 0; + + while (p > t) { + int cs = charsize(v); + + if (cs > 1) { + p = memcpy(p - cs, v, cs); + v += cs; + } else *(--p) = *(v++); + + ++n; + } + + free(x->buffer); + x->buffer = t; + + return n; +} + size_t string_to_lower(str_t* x) { - char ps[4]; char *es, *p, *e; u32_t uc0, uc1; @@ -76,7 +75,7 @@ size_t string_to_lower(str_t* x) { es = tochar_unicode(ps, uc1); if (!is_null(es)) { - libcdsb_string_replace(x, p, e-p, ps, es-ps); + string_replace_builtin(x, p, e-p, ps, es-ps); ++n; } } @@ -112,7 +111,7 @@ size_t string_to_upper(str_t* x) { es = tochar_unicode(ps, uc1); if (!is_null(es)) { - libcdsb_string_replace(x, p, e-p, ps, es-ps); + string_replace_builtin(x, p, e-p, ps, es-ps); ++n; } } @@ -146,7 +145,7 @@ size_t string_capitalize(str_t* x) { es = tochar_unicode(ps, uc1); if (!is_null(es)) { - libcdsb_string_replace(x, p, e-p, ps, es-ps); + string_replace_builtin(x, p, e-p, ps, es-ps); ++n; } } @@ -164,7 +163,7 @@ size_t string_capitalize(str_t* x) { es = tochar_unicode(ps, uc1); if (!is_null(es)) { - libcdsb_string_replace(x, p, e-p, ps, es-ps); + string_replace_builtin(x, p, e-p, ps, es-ps); ++n; } } @@ -175,56 +174,3 @@ size_t string_capitalize(str_t* x) { return n; } - - -/*#####################################################################################################################*/ - - -size_t string_reverse(str_t* x) { - char *t, *p, *v; - size_t n; - - if (is_null(x->buffer) || !*x->buffer) - return 0; - - n = strlen(x->buffer); - t = malloc(n + 1); - p = t + n; - v = x->buffer; - n = 0; - - while (p > t) { - int cs = charsize(v); - - if (cs > 1) { - p = memcpy(p - cs, v, cs); - v += cs; - } else *(--p) = *(v++); - - ++n; - } - - free(x->buffer); - x->buffer = t; - - return n; -} - -/*#####################################################################################################################*/ - -void libcdsb_string_replace(str_t* x, char* p, size_t n, const char* v, size_t vn) { - if (n != vn) { - size_t l = strlen(x->buffer); - - if (n < vn) { - char* t = x->buffer; - - x->buffer = realloc(x->buffer, l + (vn - n) + 1); - p = x->buffer + (p - t); - } - - memmove(p+vn, p+n, l - (p+n - x->buffer) + 1); - } - - memcpy(p, v, vn); -} diff --git a/src/string/trim.c b/src/string/trim.c deleted file mode 100644 index abbdd34..0000000 --- a/src/string/trim.c +++ /dev/null @@ -1,160 +0,0 @@ -/* This software is licensed by the MIT License, see LICENSE file */ -/* Copyright © 2022 Gregory Lirent */ - -#include "include.h" - - -/*#####################################################################################################################*/ - - -void libcdsb_string_trim_spaces(str_t* x, int direction) { - static size_t m[32/(sizeof(size_t))] = {0}; - - u8_t* l; - u8_t* r; - - if (sizeof(size_t) == 8) { - m[0] = 0x0000000100002e00UL; - } else { - m[0] = 0x00002e00UL; - m[1] = 0x00000001UL; - } - - if (is_null(x->buffer)) - return; - - l = (void*)x->buffer; - r = (void*)x->buffer + strlen(x->buffer); - - if (direction <= 0) { - while (m[*l/(8*sizeof(size_t))]&((size_t)1<<(*l%(8*sizeof(size_t))))) { - ++l; - } - } - - if (direction >= 0) { - do { - --r; - } while (m[*r/(8*sizeof(size_t))]&((size_t)1<<(*r%(8*sizeof(size_t))))); - ++r; - } - - if (x->buffer != (char*)l) { - memmove(x->buffer, l, r-l); - r -= (char*)l - x->buffer; - } - - *r = 0; -} - - -/*#####################################################################################################################*/ - - -void libcdsb_string_trim_cstring(str_t* x, const char* s, int direction) { - - u8_t* l; - u8_t* r; - size_t n; - bool f; - - struct { - const char* p; - size_t n; - }* m; - - if (is_null(s)) - return libcdsb_string_trim_spaces(x, direction); - - if (is_null(x->buffer) || !*s) - return; - - if (x->buffer == s) { - *x->buffer = 0; - return; - } - - n = 0; - m = 0; - - while (*(l = (void*)next_char((void*)s))) { - m = realloc(m, ++n*sizeof(*m)); - m[n-1].n = (char*)l - s; - m[n-1].p = s; - s = (void*)l; - } - - m = realloc(m, ++n*sizeof(*m)); - m[n-1].n = (char*)l - s; - m[n-1].p = s; - - l = (void*)x->buffer; - r = (void*)x->buffer + strlen(x->buffer); - - if (direction <= 0) { - f = false; - do for (size_t i = 0; i < n; ++i) { - if (memcmp(l, m[i].p, m[i].n) == 0) { - f = true; - l += m[i].n; - break; - } - } while(f && !(f = false)); - } - - if (direction >= 0) { - f = false; - do for (size_t i = 0; i < n; ++i) { - if (memcmp(r - m[i].n, m[i].p, m[i].n) == 0) { - f = true; - r -= m[i].n; - break; - } - } while(f && !(f = false)); - } - - if (x->buffer != (char*)l) { - memmove(x->buffer, l, r-l); - r -= (char*)l - x->buffer; - } - - *r = 0; -} - - -void libcdsb_string_trim_char(str_t* x, int sc, int direction) { - - u8_t* l; - u8_t* r; - char p[4]; - size_t n; - - if (!sc) - return libcdsb_string_trim_spaces(x, direction); - if (is_null(x->buffer) || is_null(l = (void*)tochar_unicode(p, sc))) - return; - - n = (char*)l - p; - - l = (void*)x->buffer; - r = (void*)x->buffer + strlen(x->buffer); - - if (direction <= 0) { - while (memcmp(l, p, n) == 0) { - l += n; - } - } - - if (direction >= 0) { - while (memcmp(r-n, p, n) == 0) { - r -= n; - } - } - - if (x->buffer != (char*)l) { - memmove(x->buffer, l, r-l); - r -= (char*)l - x->buffer; - } - - *r = 0; -} diff --git a/tests/include/test.h b/tests/include/test.h index ac3d5e9..51b96cf 100644 --- a/tests/include/test.h +++ b/tests/include/test.h @@ -2,7 +2,7 @@ /* Copyright © 2022 Gregory Lirent */ #include -#include "../../include/extra/vtype.h" +#include "../../include/vtype.h" #ifndef LIBCDSB_TESTS_TEST_H #define LIBCDSB_TESTS_TEST_H diff --git a/tests/src/string/main.c b/tests/src/string/main.c index 522b3f8..73ddb30 100644 --- a/tests/src/string/main.c +++ b/tests/src/string/main.c @@ -18,10 +18,10 @@ int main(int argc, char** argv) { { char* repl = random_utf8_cstring(30); - void* hack = string_at(&x, 31); + void* hack = at_string(&x, 31); string_print((void*)&hack, "(part 2)"); string_print((void*)&repl, "(part 2 replaced)"); - string_replace(&x, hack, repl, -1); + string_replace(&x, hack, repl); free(repl); } @@ -54,16 +54,16 @@ int main(int argc, char** argv) { x = string_random(12); - string_align_center(&x, 30, 0); + string_align(&x, 30, 0); string_info(&x); string_print(&x, 0); - string_trim_spaces(&x); + string_trim(&x, 0); string_info(&x); string_print(&x, "trimmed"); put_separator(0); - string_align_center(&x, 30, c); + string_align(&x, 30, c); string_info(&x); string_print(&x, 0); diff --git a/tests/src/string/plug.h b/tests/src/string/plug.h index 241dc93..f58d418 100644 --- a/tests/src/string/plug.h +++ b/tests/src/string/plug.h @@ -3,7 +3,7 @@ #include #include "../../../modules/libunic/include.h" -#include "../../../include/extra/string.h" +#include "../../../include/string.h" #include "../../include/random.h" #include "../../include/test.h" diff --git a/tests/src/string/src/random.c b/tests/src/string/src/random.c index 36a587c..95e3481 100644 --- a/tests/src/string/src/random.c +++ b/tests/src/string/src/random.c @@ -45,7 +45,7 @@ void string_replace_random(str_t* x, unsigned int n) { v = random_utf8_cstring(n); } else v = random_ascii_cstring(n); - string_replace(x, x, v, -1); + string_replace(x, x, v); free(v); } From 48bddb6db83352fe3003f7a452d33283c05fbecc Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Mon, 22 Aug 2022 14:18:38 +0300 Subject: [PATCH 11/18] Refactor the internal symbols --- src/__internal/include.h | 41 ++++---------------- src/__internal/rbtree.h | 20 ++++++---- src/__internal/vnode.h | 30 ++++++++------- src/array/sort.c | 80 +++++++++++----------------------------- src/dict/copy.c | 8 ++-- src/dict/modify.c | 12 +++--- src/extra.c | 14 +++---- src/list/access.c | 6 +-- src/list/copy.c | 26 ++++++------- src/list/sort.c | 11 +++--- src/map/comparison.c | 12 +++--- src/map/compute.c | 6 +-- src/map/copy.c | 20 +++++----- src/map/include.h | 8 ++-- src/rbtree.c | 39 ++++++++++---------- src/set/comparison.c | 12 +++--- src/set/compute.c | 6 +-- src/string/include.h | 7 +++- src/string/transform.c | 10 ++--- src/vnode.c | 34 ++++++----------- src/vtype-extra.c | 33 ++++++++--------- src/vtype.c | 22 +++++------ 22 files changed, 195 insertions(+), 262 deletions(-) diff --git a/src/__internal/include.h b/src/__internal/include.h index fb5a610..1fcb493 100644 --- a/src/__internal/include.h +++ b/src/__internal/include.h @@ -34,7 +34,6 @@ #define abs(v) _Generic((v), ldbl_t: fabsl, dbl_t: fabs, fl_t: fabsf)(v) - typedef vtype_uint8 u8_t; typedef vtype_uint16 u16_t; typedef vtype_uint32 u32_t; @@ -59,12 +58,11 @@ typedef vtype_dict dict_t; typedef vtype_hash hash_t; -extern const size_t LIBCDSB_VTYPE_SIZES[19]; - -extern int libcdsb_vtype_compare_values (const void* s0, vtype t0, const void* s1, vtype t1) pure__ wur__; -extern int libcdsb_vtype_compare_values_eq(const void* s0, const void* s1, vtype t) pure__ wur__; -extern hash_t libcdsb_vtype_hash (const void* value, vtype type) pure__ wur__; +extern const size_t LIBCDSB_BUILTIN_VTYPE_SIZES[19]; +extern int libcdsb_builtin_vtype_compare_values (const void* s0, vtype t0, const void* s1, vtype t1) pure__ wur__; +extern int libcdsb_builtin_vtype_compare_values_eq(const void* s0, const void* s1, vtype t) pure__ wur__; +extern hash_t libcdsb_builtin_vtype_hash (const void* value, vtype type) pure__ wur__; #define aligned_alloc libcdsb_aalloc #define malloc libcdsb_malloc @@ -84,32 +82,9 @@ extern hash_t libcdsb_vtype_hash (const void* value, vtype type) #define vtype_stringify libcdsb_vtype_stringify #define vtype_name libcdsb_vtype_name -#define vtype_compare libcdsb_vtype_compare_values -#define vtype_compare_eq libcdsb_vtype_compare_values_eq -#define vtype_hash libcdsb_vtype_hash -#define vtype_size(type) (LIBCDSB_VTYPE_SIZES[type]) - - -#define vtypeof(x) (vtype)(_Generic((x),\ - const void**: VTYPE_POINTER, void**: VTYPE_POINTER, const void*: VTYPE_POINTER, void*: VTYPE_POINTER,\ - const char**: VTYPE_STRING, char**: VTYPE_STRING, const char*: VTYPE_STRING, char*: VTYPE_STRING,\ - const str_t*: VTYPE_STRING, str_t*: VTYPE_STRING, str_t: VTYPE_STRING,\ - const arr_t*: VTYPE_ARRAY, arr_t*: VTYPE_ARRAY, arr_t: VTYPE_ARRAY,\ - const list_t*: VTYPE_LIST, list_t*: VTYPE_LIST, list_t: VTYPE_LIST,\ - const map_t*: VTYPE_MAP, map_t*: VTYPE_MAP, map_t: VTYPE_MAP,\ - const set_t*: VTYPE_SET, set_t*: VTYPE_SET, set_t: VTYPE_SET,\ - const dict_t*: VTYPE_DICT, dict_t*: VTYPE_DICT, dict_t: VTYPE_DICT,\ - const vtype_bool*: VTYPE_BOOLEAN, vtype_bool*: VTYPE_BOOLEAN, vtype_bool: VTYPE_BOOLEAN,\ - const vtype_uint8*: VTYPE_UINT8, vtype_uint8*: VTYPE_UINT8, vtype_uint8: VTYPE_UINT8,\ - const vtype_uint16*: VTYPE_UINT16, vtype_uint16*: VTYPE_UINT16, vtype_uint16: VTYPE_UINT16,\ - const vtype_uint32*: VTYPE_UINT32, vtype_uint32*: VTYPE_UINT32, vtype_uint32: VTYPE_UINT32,\ - const vtype_uint64*: VTYPE_UINT64, vtype_uint64*: VTYPE_UINT64, vtype_uint64: VTYPE_UINT64,\ - const vtype_int8*: VTYPE_INT8, vtype_int8*: VTYPE_INT8, vtype_int8: VTYPE_INT8,\ - const vtype_int16*: VTYPE_INT16, vtype_int16*: VTYPE_INT16, vtype_int16: VTYPE_INT16,\ - const vtype_int32*: VTYPE_INT32, vtype_int32*: VTYPE_INT32, vtype_int32: VTYPE_INT32,\ - const vtype_int64*: VTYPE_INT64, vtype_int64*: VTYPE_INT64, vtype_int64: VTYPE_INT64,\ - const vtype_float*: VTYPE_FLOAT, vtype_float*: VTYPE_FLOAT, vtype_float: VTYPE_FLOAT,\ - const vtype_double*: VTYPE_DOUBLE, vtype_double*: VTYPE_DOUBLE, vtype_double: VTYPE_DOUBLE,\ - const vtype_ldouble*: VTYPE_LDOUBLE, vtype_ldouble*: VTYPE_LDOUBLE, vtype_ldouble: VTYPE_LDOUBLE)) +#define vtype_compare libcdsb_builtin_vtype_compare_values +#define vtype_compare_eq libcdsb_builtin_vtype_compare_values_eq +#define vtype_hash libcdsb_builtin_vtype_hash +#define vtype_size(type) (LIBCDSB_BUILTIN_VTYPE_SIZES[type]) #endif /* LIBCDSB_SRC_INTERNAL_INCLUDE */ diff --git a/src/__internal/rbtree.h b/src/__internal/rbtree.h index 93ecb97..a974485 100644 --- a/src/__internal/rbtree.h +++ b/src/__internal/rbtree.h @@ -15,16 +15,20 @@ typedef struct libcdsb_rbtree_node { short colored; } rbnode_t; -extern rbnode_t LIBCDSB_RBTREE_NODE_EMPTY[1]; +extern rbnode_t LIBCDSB_BUILTIN_RBTREE_NODE_EMPTY[1]; -extern void* libcdsb_rbtree_node_create(void* value, rbnode_t* parent, int colored, int size) Nonnull__( 2); -extern void libcdsb_rbtree_node_fixup (rbnode_t** root, rbnode_t* node) Nonnull__(1,2); -extern rbnode_t* libcdsb_rbtree_node_delete(rbnode_t** root, rbnode_t* node) Nonnull__(1,2); +extern void* libcdsb_builtin_rbtree_node_create(void* value, rbnode_t* parent, int colored, int size) Nonnull__( 2); +extern void libcdsb_builtin_rbtree_node_fixup (rbnode_t** root, rbnode_t* node) Nonnull__(1,2); +extern rbnode_t* libcdsb_builtin_rbtree_node_delete(rbnode_t** root, rbnode_t* node) Nonnull__(1,2); -#define rbnode_empty ((rbnode_t*)LIBCDSB_RBTREE_NODE_EMPTY) -#define rbnode_create(v, p, c) ((rbnode_t*)libcdsb_rbtree_node_create(v, p, c, sizeof(rbnode_t))) -#define rbnode_fixup libcdsb_rbtree_node_fixup -#define rbnode_delete libcdsb_rbtree_node_delete +extern rbnode_t* libcdsb_builtin_rbtree_next_inorder (rbnode_t** root, rbnode_t* prev, bool reverse); +extern rbnode_t* libcdsb_builtin_rbtree_next_preorder (rbnode_t** root, rbnode_t* prev, bool reverse); +extern rbnode_t* libcdsb_builtin_rbtree_next_postorder(rbnode_t** root, rbnode_t* prev, bool reverse); + +#define rbnode_empty ((rbnode_t*)LIBCDSB_BUILTIN_RBTREE_NODE_EMPTY) +#define rbnode_create(v, p, c) ((rbnode_t*)libcdsb_builtin_rbtree_node_create(v, p, c, sizeof(rbnode_t))) +#define rbnode_fixup libcdsb_builtin_rbtree_node_fixup +#define rbnode_delete libcdsb_builtin_rbtree_node_delete #define rbnode_is_empty(n) ((n) == rbnode_empty) #define rbnode_is_root(n) rbnode_is_empty((n)->parent) diff --git a/src/__internal/vnode.h b/src/__internal/vnode.h index 755730f..06f021d 100644 --- a/src/__internal/vnode.h +++ b/src/__internal/vnode.h @@ -19,15 +19,15 @@ typedef union { typedef void* vnode_t; -extern vnode_t libcdsb_vnode_create (const void* value, vtype type) wur__; -extern vnode_t libcdsb_vnode_create_target(vtype target_type, const void* value, vtype type) wur__; +extern vnode_t libcdsb_builtin_vnode_create (const void* value, vtype type) wur__; +extern vnode_t libcdsb_builtin_vnode_create_target(vtype target_type, const void* value, vtype type) wur__; -extern void libcdsb_vnode_free(vnode_t* x, vtype type) Nonnull__(1); -extern void* libcdsb_vnode_peek(const vnode_t* x, vtype type) pure__ wur__ Nonnull__(1); +extern void libcdsb_builtin_vnode_free(vnode_t* x, vtype type) Nonnull__(1); +extern void* libcdsb_builtin_vnode_peek(const vnode_t* x, vtype type) pure__ wur__ Nonnull__(1); -ainline(void vnode_attach(vnode_t* node, const void* value, vtype type)) { +ainline(void libcdsb_builtin_vnode_attach(vnode_t* node, const void* value, vtype type)) { if (type < VTYPE_STRING) { - *node = libcdsb_vnode_create(value, type); + *node = libcdsb_builtin_vnode_create(value, type); } else if (sizeof(str_t) == sizeof(void*) && type == VTYPE_STRING) { *node = *(char**)value; } else { @@ -36,9 +36,9 @@ ainline(void vnode_attach(vnode_t* node, const void* value, vtype type)) { } } -ainline(void vnode_tattach(vnode_t* node, vtype target_type, const void* value, vtype type)) { +ainline(void libcdsb_builtin_vnode_tattach(vnode_t* node, vtype target_type, const void* value, vtype type)) { if (type < VTYPE_STRING) { - *node = libcdsb_vnode_create_target(target_type, value, type); + *node = libcdsb_builtin_vnode_create_target(target_type, value, type); } else { type_assert(target_type, type); @@ -51,16 +51,18 @@ ainline(void vnode_tattach(vnode_t* node, vtype target_type, const void* value, } } -#define vnode_create libcdsb_vnode_create -#define vnode_tcreate libcdsb_vnode_create_target -#define vnode_peek libcdsb_vnode_peek -#define vnode_free libcdsb_vnode_free +#define vnode_create libcdsb_builtin_vnode_create +#define vnode_tcreate libcdsb_builtin_vnode_create_target +#define vnode_attach libcdsb_builtin_vnode_attach +#define vnode_tattach libcdsb_builtin_vnode_tattach +#define vnode_peek libcdsb_builtin_vnode_peek +#define vnode_free libcdsb_builtin_vnode_free #define vnode_hash(vnode, type) vtype_hash(vnode_peek(vnode, type), type) #define vnode_compare(s0, t0, s1, t1) vtype_compare(vnode_peek(s0, t0), t0, vnode_peek(s1, t1), t1) #define vnode_compare_eq(s0, s1, t) vtype_compare_eq(vnode_peek(s0, t), vnode_peek(s1, t), t) -#define vnode_duplicate(vnode, type) libcdsb_vnode_create(vnode_peek(vnode, type), type) -#define vnode_tduplicate(target_type, vnode, type) libcdsb_vnode_create_target(target_type, vnode_peek(vnode, type), type) +#define vnode_duplicate(vnode, type) vnode_create(vnode_peek(vnode, type), type) +#define vnode_tduplicate(target_type, vnode, type) vnode_tcreate(target_type, vnode_peek(vnode, type), type) #define vnode_stringify(n, t) vtype_stringify(vnode_peek(n, t), t) diff --git a/src/array/sort.c b/src/array/sort.c index 19622c2..64a01f1 100644 --- a/src/array/sort.c +++ b/src/array/sort.c @@ -4,78 +4,42 @@ #include "include.h" #include "../__internal/assert.h" -static_assert(( - VTYPE_UINT8 == 2 && - VTYPE_UINT16 == 3 && - VTYPE_UINT32 == 4 && - VTYPE_UINT64 == 5 && - VTYPE_INT8 == 6 && - VTYPE_INT16 == 7 && - VTYPE_INT32 == 8 && - VTYPE_INT64 == 9 && - VTYPE_FLOAT == 10 && - VTYPE_DOUBLE == 11 && - VTYPE_LDOUBLE == 12 && - VTYPE_STRING == 13 && - VTYPE_MAP == 14 && - VTYPE_ARRAY == 15 && - VTYPE_LIST == 16 && - VTYPE_SET == 17 -), "enum values assertion"); +typedef int (*compare_f)(const void*, const void*); -static int uint8_compare (const u8_t* s0, const u8_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } -static int uint16_compare (const u16_t* s0, const u16_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } -static int uint32_compare (const u32_t* s0, const u32_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } -static int uint64_compare (const u64_t* s0, const u64_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } -static int int8_compare (const s8_t* s0, const s8_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } -static int int16_compare (const s16_t* s0, const s16_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } -static int int32_compare (const s32_t* s0, const s32_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } -static int int64_compare (const s64_t* s0, const s64_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } -static int float_compare (const fl_t* s0, const fl_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } -static int double_compare (const dbl_t* s0, const dbl_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } -static int ldouble_compare(const ldbl_t* s0, const ldbl_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } +static int libcdsb_builtin_compare_uint8 (const u8_t* s0, const u8_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } +static int libcdsb_builtin_compare_uint16 (const u16_t* s0, const u16_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } +static int libcdsb_builtin_compare_uint32 (const u32_t* s0, const u32_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } +static int libcdsb_builtin_compare_uint64 (const u64_t* s0, const u64_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } +static int libcdsb_builtin_compare_int8 (const s8_t* s0, const s8_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } +static int libcdsb_builtin_compare_int16 (const s16_t* s0, const s16_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } +static int libcdsb_builtin_compare_int32 (const s32_t* s0, const s32_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } +static int libcdsb_builtin_compare_int64 (const s64_t* s0, const s64_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } +static int libcdsb_builtin_compare_float (const fl_t* s0, const fl_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } +static int libcdsb_builtin_compare_double (const dbl_t* s0, const dbl_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } +static int libcdsb_builtin_compare_ldouble(const ldbl_t* s0, const ldbl_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; } -static int (*COMPARE[16])(const void*, const void*) = { - (void*) uint8_compare, - (void*) uint16_compare, - (void*) uint32_compare, - (void*) uint64_compare, - (void*) int8_compare, - (void*) int16_compare, - (void*) int32_compare, - (void*) int64_compare, - (void*) float_compare, - (void*) double_compare, - (void*) ldouble_compare, - (void*) string_compare, - (void*) map_compare, - (void*) array_compare, - (void*) list_compare, - (void*) vset_compare -}; +static compare_f libcdsb_builtin_get_comparator(vtype t) { + static void* comparators[17] = { libcdsb_builtin_compare_uint8, libcdsb_builtin_compare_uint16, + libcdsb_builtin_compare_uint32, libcdsb_builtin_compare_uint64, + libcdsb_builtin_compare_int8, libcdsb_builtin_compare_int16, + libcdsb_builtin_compare_int32, libcdsb_builtin_compare_int64, + libcdsb_builtin_compare_float, libcdsb_builtin_compare_double, + libcdsb_builtin_compare_ldouble, string_compare, map_compare, + array_compare, list_compare, vset_compare, dict_compare }; - -/*#####################################################################################################################*/ - - -ainline(int get_compare_index(vtype t)) { if (t == VTYPE_POINTER) { if (is_x64) t = VTYPE_UINT64; else t = VTYPE_UINT32; } else if (t == VTYPE_BOOLEAN) t = VTYPE_UINT8; - return t - VTYPE_UINT8; + return comparators[t - VTYPE_UINT8]; } - /*#####################################################################################################################*/ - void array_sort(arr_t* x) { - int i = get_compare_index(x->type); - if (x->size > 1) - qsort(x->mem, x->size, vtype_size(x->type), COMPARE[i]); + qsort(x->mem, x->size, vtype_size(x->type), libcdsb_builtin_get_comparator(x->type)); } void array_reverse(arr_t* x) { diff --git a/src/dict/copy.c b/src/dict/copy.c index a9a6148..312d7c7 100644 --- a/src/dict/copy.c +++ b/src/dict/copy.c @@ -4,7 +4,7 @@ #include "../../include/list.h" #include "include.h" -static inline dnode_t* dnode_duplicate(const dnode_t* s, dnode_t* p) { +static inline dnode_t* libcdsb_builtin_duplicate(const dnode_t* s, dnode_t* p) { dnode_t* x = malloc(sizeof(*x)); x->prev = p; @@ -31,7 +31,7 @@ dict_t dict_copy(const dict_t* s) { n = s->nodes[i]; while (!is_null(n)) { - x.nodes[i] = dnode_duplicate(n, x.nodes[i]); + x.nodes[i] = libcdsb_builtin_duplicate(n, x.nodes[i]); n = n->prev; } } @@ -53,7 +53,7 @@ dict_t* dict_duplicate(const dict_t* s) { n = s->nodes[i]; while (!is_null(n)) { - x->nodes[i] = dnode_duplicate(n, x->nodes[i]); + x->nodes[i] = libcdsb_builtin_duplicate(n, x->nodes[i]); n = n->prev; } } @@ -74,7 +74,7 @@ void dict_copy_init(dict_t* x, const dict_t* s) { n = s->nodes[i]; while (!is_null(n)) { - x->nodes[i] = dnode_duplicate(n, x->nodes[i]); + x->nodes[i] = libcdsb_builtin_duplicate(n, x->nodes[i]); n = n->prev; } } diff --git a/src/dict/modify.c b/src/dict/modify.c index 33f6a84..7f34591 100644 --- a/src/dict/modify.c +++ b/src/dict/modify.c @@ -4,7 +4,7 @@ #include "../../include/list.h" #include "include.h" -static void dict_rehash(dict_t* s, size_t capacity) { +static void libcdsb_builtin_rehash(dict_t* s, size_t capacity) { dnode_t **nodes, *c, *n, **p; size_t i; @@ -44,7 +44,7 @@ bool libcdsb_dict_shrink_to_fit(dict_t* s) { if (capacity >= s->capacity) return false; - dict_rehash(s, capacity); + libcdsb_builtin_rehash(s, capacity); return true; } @@ -54,7 +54,7 @@ bool libcdsb_dict_update(dict_t* x, const void* k, vtype kt, const void* v, vtyp dnode_t *c, **p; if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX) - dict_rehash(x, x->capacity + CAPACITY_BLOCK); + libcdsb_builtin_rehash(x, x->capacity + CAPACITY_BLOCK); c = *(p = x->nodes + (vtype_hash(k, kt) % x->capacity)); @@ -88,7 +88,7 @@ bool libcdsb_dict_inject(dict_t* x, const void* k, vtype kt, const void* v, vtyp dnode_t *c, **p; if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX) - dict_rehash(x, x->capacity + CAPACITY_BLOCK); + libcdsb_builtin_rehash(x, x->capacity + CAPACITY_BLOCK); c = *(p = x->nodes + (vtype_hash(k, kt) % x->capacity)); @@ -123,7 +123,7 @@ bool libcdsb_dict_inject_key(dict_t* x, const void* k, vtype kt, const void* v, dnode_t *c, **p; if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX) - dict_rehash(x, x->capacity + CAPACITY_BLOCK); + libcdsb_builtin_rehash(x, x->capacity + CAPACITY_BLOCK); c = *(p = x->nodes + (vtype_hash(k, kt) % x->capacity)); @@ -158,7 +158,7 @@ bool libcdsb_dict_inject_value(dict_t* x, const void* k, vtype kt, const void* v dnode_t *c, **p; if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX) - dict_rehash(x, x->capacity + CAPACITY_BLOCK); + libcdsb_builtin_rehash(x, x->capacity + CAPACITY_BLOCK); c = *(p = x->nodes + (vtype_hash(k, kt) % x->capacity)); diff --git a/src/extra.c b/src/extra.c index 313b1b6..be7d703 100644 --- a/src/extra.c +++ b/src/extra.c @@ -4,21 +4,21 @@ #include "../modules/libunic/include.h" #include "__internal/include.h" -static _Thread_local int CHAR_BUFFER_POS = 0; -static _Thread_local char CHAR_BUFFER[16][5]; +static _Thread_local int LIBCDSB_BUILTIN_COUNTER = 0; +static _Thread_local char LIBCDSB_BUILTIN_BUFFER[16][5]; const char* libcdsb_char_to_cstring(int c) { char* p; - if (CHAR_BUFFER_POS > 15) - CHAR_BUFFER_POS = 0; + if (LIBCDSB_BUILTIN_COUNTER > 15) + LIBCDSB_BUILTIN_COUNTER = 0; - if (is_null(p = tochar_unicode(CHAR_BUFFER[CHAR_BUFFER_POS], c))) { - CHAR_BUFFER[CHAR_BUFFER_POS][0] = 0; + if (is_null(p = tochar_unicode(LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER], c))) { + LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER][0] = 0; } else *p = 0; - return CHAR_BUFFER[CHAR_BUFFER_POS++]; + return LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER++]; } diff --git a/src/list/access.c b/src/list/access.c index 4232de7..1d6834e 100644 --- a/src/list/access.c +++ b/src/list/access.c @@ -3,7 +3,7 @@ #include "include.h" -static void lnode_cut(list_t* s, lnode_t* cur) { +static void libcdsb_builtin_cut(list_t* s, lnode_t* cur) { vnode_free(&cur->node, cur->type); @@ -45,7 +45,7 @@ int libcdsb_list_get(vtype_list* x, ssize_t i, void* _, list_access_callback cal i = (callback) ? callback(vnode_peek(&c->node, c->type), i, c->type, _) : 0; - if (cut) lnode_cut(x, c); + if (cut) libcdsb_builtin_cut(x, c); return i; } @@ -67,7 +67,7 @@ int libcdsb_list_find(vtype_list* x, const void* v, vtype t, void* _, list_acces if (cmp == 0) { i = (callback) ? callback(vnode_peek(&c->node, c->type), (r)?~i:i, c->type, _) : 0; - if (cut) lnode_cut(x, c); + if (cut) libcdsb_builtin_cut(x, c); return i; } diff --git a/src/list/copy.c b/src/list/copy.c index 3e1fae4..34e5b77 100644 --- a/src/list/copy.c +++ b/src/list/copy.c @@ -3,7 +3,7 @@ #include "include.h" -static void init_first(list_t* x, vnode_t v, vtype t) { +static void libcdsb_builtin_init(list_t* x, vnode_t v, vtype t) { lnode_t* node = malloc(sizeof(*node)); node->next = nullptr; @@ -16,7 +16,7 @@ static void init_first(list_t* x, vnode_t v, vtype t) { } -static void push_next(list_t* x, vnode_t v, vtype t) { +static void libcdsb_builtin_push(list_t* x, vnode_t v, vtype t) { lnode_t* node = malloc(sizeof(*node)); node->next = nullptr; @@ -40,10 +40,10 @@ list_t list_copy(const list_t* s) { if (is_null(c)) return x; - init_first(&x, vnode_duplicate(&c->node, c->type), c->type); + libcdsb_builtin_init(&x, vnode_duplicate(&c->node, c->type), c->type); while (!is_null(c = c->next)) { - push_next(&x, vnode_duplicate(&c->node, c->type), c->type); + libcdsb_builtin_push(&x, vnode_duplicate(&c->node, c->type), c->type); } return x; @@ -60,10 +60,10 @@ list_t* list_duplicate(const list_t* s) { if (is_null(c)) return x; - init_first(x, vnode_duplicate(&c->node, c->type), c->type); + libcdsb_builtin_init(x, vnode_duplicate(&c->node, c->type), c->type); while (!is_null(c = c->next)) { - push_next(x, vnode_duplicate(&c->node, c->type), c->type); + libcdsb_builtin_push(x, vnode_duplicate(&c->node, c->type), c->type); } return x; @@ -79,10 +79,10 @@ void list_copy_init(list_t* x, const list_t* s) { if (is_null(c)) return; - init_first(x, vnode_duplicate(&c->node, c->type), c->type); + libcdsb_builtin_init(x, vnode_duplicate(&c->node, c->type), c->type); while (!is_null(c = c->next)) { - push_next(x, vnode_duplicate(&c->node, c->type), c->type); + libcdsb_builtin_push(x, vnode_duplicate(&c->node, c->type), c->type); } } @@ -96,7 +96,7 @@ void list_extend(list_t* x, const list_t* s) { return; if (is_null(x->first)) { - init_first(x, vnode_duplicate(&c->node, c->type), c->type); + libcdsb_builtin_init(x, vnode_duplicate(&c->node, c->type), c->type); c = c->next; if (is_null(c)) @@ -104,7 +104,7 @@ void list_extend(list_t* x, const list_t* s) { } do { - push_next(x, vnode_duplicate(&c->node, c->type), c->type); + libcdsb_builtin_push(x, vnode_duplicate(&c->node, c->type), c->type); } while (!is_null(c = c->next)); } @@ -157,13 +157,13 @@ size_t list_slice(list_t* x, list_t* s, ssize_t i, size_t n, _Bool cut) { else r -= n; if (!cut) { - init_first(x, vnode_duplicate(&c->node, c->type), c->type); + libcdsb_builtin_init(x, vnode_duplicate(&c->node, c->type), c->type); while ((c = c->next) != e) { - push_next(x, vnode_duplicate(&c->node, c->type), c->type); + libcdsb_builtin_push(x, vnode_duplicate(&c->node, c->type), c->type); } - push_next(x, vnode_duplicate(&e->node, e->type), e->type); + libcdsb_builtin_push(x, vnode_duplicate(&e->node, e->type), e->type); } else { if (c->prev) { c->prev->next = e->next; diff --git a/src/list/sort.c b/src/list/sort.c index 1542072..daeb337 100644 --- a/src/list/sort.c +++ b/src/list/sort.c @@ -3,9 +3,7 @@ #include "include.h" -/*#####################################################################################################################*/ - -static inline void lnode_swap(lnode_t* s0, lnode_t* s1) { +static inline void libcdsb_builtin_swap(lnode_t* s0, lnode_t* s1) { vnode_t v = s0->node; vtype t = s0->type; @@ -16,6 +14,7 @@ static inline void lnode_swap(lnode_t* s0, lnode_t* s1) { s1->type = t; } +/*#####################################################################################################################*/ void list_sort(list_t* x) { stack_t z; @@ -37,12 +36,12 @@ void list_sort(list_t* x) { for (lnode_t* c = l; c != r; c = c->next) { if (lnode_compare(c, r) <= 0) { p = (is_null(p)) ? l : p->next; - lnode_swap(p, c); + libcdsb_builtin_swap(p, c); } } p = (is_null(p)) ? l : p->next; - lnode_swap(p, r); + libcdsb_builtin_swap(p, r); stack_push(&z, r); stack_push(&z, p->next); @@ -58,7 +57,7 @@ void list_reverse(list_t* x) { lnode_t *r = x->last; while (l != r) { - lnode_swap(l, r); + libcdsb_builtin_swap(l, r); if ((r = r->prev) == l) break; l = l->next; diff --git a/src/map/comparison.c b/src/map/comparison.c index 9590767..a2b74a0 100644 --- a/src/map/comparison.c +++ b/src/map/comparison.c @@ -3,7 +3,7 @@ #include "include.h" -static inline int mnode_compare(const mnode_t* s0, const mnode_t* s1, vtype t) { +static inline int libcdsb_builtin_compare(const mnode_t* s0, const mnode_t* s1, vtype t) { int c = vnode_compare_eq(&s0->key, &s1->key, t); return !c ? vnode_compare(&s0->value, s0->type, &s1->value, s1->type) : c; @@ -35,13 +35,13 @@ int map_compare(const map_t* s0, const map_t* s1) { stack_flush(&z); return mnode_is_empty(c0) ? -1 : 1; } - } else if ((cmp = mnode_compare(c0, c1, s0->type))) { + } else if ((cmp = libcdsb_builtin_compare(c0, c1, s0->type))) { if (c0->left == c1->right) { // == mnode_empty - cmp = mnode_compare(c0->right, c1, s0->type); - if (!cmp) cmp = mnode_compare(c0, c1->left, s0->type); + cmp = libcdsb_builtin_compare(c0->right, c1, s0->type); + if (!cmp) cmp = libcdsb_builtin_compare(c0, c1->left, s0->type); } else if (c0->right == c1->left) { // == mnode_empty - cmp = mnode_compare(c0, c1->right, s0->type); - if (!cmp) cmp = mnode_compare(c0->left, c1, s0->type); + cmp = libcdsb_builtin_compare(c0, c1->right, s0->type); + if (!cmp) cmp = libcdsb_builtin_compare(c0->left, c1, s0->type); } if (cmp) { diff --git a/src/map/compute.c b/src/map/compute.c index 8c03385..75088de 100644 --- a/src/map/compute.c +++ b/src/map/compute.c @@ -3,7 +3,7 @@ #include "include.h" -static inline hash_t mnode_hash(const mnode_t* s, vtype t) { +static inline hash_t libcdsb_builtin_hash(const mnode_t* s, vtype t) { return vnode_hash(&s->key, t) + vnode_hash(&s->value, s->type) + t; } @@ -53,7 +53,7 @@ hash_t map_hash(const map_t* s) { } while (!is_null(c0 = stack_pop(&z))); } - v = mnode_hash(c1, s->type); + v = libcdsb_builtin_hash(c1, s->type); stack_push(&z, s->root->right); if (!mnode_is_empty(c0 = stack_pop(&z))) { @@ -64,7 +64,7 @@ hash_t map_hash(const map_t* s) { } while (!is_null(c0 = stack_pop(&z))); } - v += mnode_hash(c1, s->type); + v += libcdsb_builtin_hash(c1, s->type); return (hash ^ v) + VTYPE_MAP; } diff --git a/src/map/copy.c b/src/map/copy.c index 7fe7ecf..f4fb761 100644 --- a/src/map/copy.c +++ b/src/map/copy.c @@ -3,7 +3,7 @@ #include "include.h" -static inline mnode_t* mnode_duplicate(const mnode_t* s, mnode_t* p, const vtype t) { +static inline mnode_t* libcdsb_builtin_duplicate(const mnode_t* s, mnode_t* p, const vtype t) { mnode_t* x; x = mnode_create(vnode_duplicate(&s->key, t), p, s->colored); @@ -26,7 +26,7 @@ map_t map_copy(const map_t* s) { x.type = s->type; if (!mnode_is_empty(s->root)) { - x.root = mnode_duplicate(s->root, mnode_empty, s->type); + x.root = libcdsb_builtin_duplicate(s->root, mnode_empty, s->type); stack_push(&z, x.root); do { @@ -34,12 +34,12 @@ map_t map_copy(const map_t* s) { mnode_t *p1 = stack_pop(&z); if (!mnode_is_empty(p1->left)) { - p0->left = mnode_duplicate(p1->left, p0, s->type); + p0->left = libcdsb_builtin_duplicate(p1->left, p0, s->type); stack_push_many(&z, 2, p1->left, p0->left); } if (!mnode_is_empty(p1->right)) { - p0->right = mnode_duplicate(p1->right, p0, s->type); + p0->right = libcdsb_builtin_duplicate(p1->right, p0, s->type); stack_push_many(&z, 2, p1->right, p0->right); } @@ -63,7 +63,7 @@ map_t* map_duplicate(const map_t* s) { x->type = s->type; if (!mnode_is_empty(s->root)) { - x->root = mnode_duplicate(s->root, mnode_empty, s->type); + x->root = libcdsb_builtin_duplicate(s->root, mnode_empty, s->type); stack_push(&z, x->root); do { @@ -71,12 +71,12 @@ map_t* map_duplicate(const map_t* s) { mnode_t *p1 = stack_pop(&z); if (!mnode_is_empty(p1->left)) { - p0->left = mnode_duplicate(p1->left, p0, s->type); + p0->left = libcdsb_builtin_duplicate(p1->left, p0, s->type); stack_push_many(&z, 2, p1->left, p0->left); } if (!mnode_is_empty(p1->right)) { - p0->right = mnode_duplicate(p1->right, p0, s->type); + p0->right = libcdsb_builtin_duplicate(p1->right, p0, s->type); stack_push_many(&z, 2, p1->right, p0->right); } @@ -98,7 +98,7 @@ void map_copy_init(map_t* x, const map_t* s) { x->type = s->type; if (!mnode_is_empty(s->root)) { - x->root = mnode_duplicate(s->root, mnode_empty, s->type); + x->root = libcdsb_builtin_duplicate(s->root, mnode_empty, s->type); stack_push(&z, x->root); do { @@ -106,12 +106,12 @@ void map_copy_init(map_t* x, const map_t* s) { mnode_t *p1 = stack_pop(&z); if (!mnode_is_empty(p1->left)) { - p0->left = mnode_duplicate(p1->left, p0, s->type); + p0->left = libcdsb_builtin_duplicate(p1->left, p0, s->type); stack_push_many(&z, 2, p1->left, p0->left); } if (!mnode_is_empty(p1->right)) { - p0->right = mnode_duplicate(p1->right, p0, s->type); + p0->right = libcdsb_builtin_duplicate(p1->right, p0, s->type); stack_push_many(&z, 2, p1->right, p0->right); } diff --git a/src/map/include.h b/src/map/include.h index de5185e..2c12f93 100644 --- a/src/map/include.h +++ b/src/map/include.h @@ -27,10 +27,10 @@ static_assert(offsetof(struct libcdsb_rbtree_node, value) == offsetof(struct l static_assert(offsetof(struct libcdsb_set, root) == offsetof(struct libcdsb_map, root), "Implementation assert"); static_assert(offsetof(struct libcdsb_set, type) == offsetof(struct libcdsb_map, type), "Implementation assert"); -#define mnode_empty ((mnode_t*)LIBCDSB_RBTREE_NODE_EMPTY) -#define mnode_create(k, p, c) ((mnode_t*)libcdsb_rbtree_node_create(k, (rbnode_t*)p, c, sizeof(mnode_t))) -#define mnode_fixup(r, n) libcdsb_rbtree_node_fixup((rbnode_t**)(r), (rbnode_t*)(n)) -#define mnode_delete(r, n) (mnode_t*)libcdsb_rbtree_node_delete((rbnode_t**)(r), (rbnode_t*)(n)) +#define mnode_empty ((mnode_t*)rbnode_empty) +#define mnode_create(k, p, c) ((mnode_t*)libcdsb_builtin_rbtree_node_create(k, (rbnode_t*)p, c, sizeof(mnode_t))) +#define mnode_fixup(r, n) libcdsb_builtin_rbtree_node_fixup((rbnode_t**)(r), (rbnode_t*)(n)) +#define mnode_delete(r, n) (mnode_t*)libcdsb_builtin_rbtree_node_delete((rbnode_t**)(r), (rbnode_t*)(n)) #define mnode_is_empty(n) ((n) == mnode_empty) #define mnode_is_root(n) mnode_is_empty((n)->parent) diff --git a/src/rbtree.c b/src/rbtree.c index 9c7d328..4d9df47 100644 --- a/src/rbtree.c +++ b/src/rbtree.c @@ -11,19 +11,12 @@ typedef enum libcdsb_rbtree_node_direction { #define rbdir_dir(cur, d) (&((cur)->left))[(d)>>1] #define rbdir_inv(cur, d) (&((cur)->left))[(d)&1] -/*#####################################################################################################################*/ +#define rotate libcdsb_builtin_rotate +#define replace libcdsb_builtin_replace +#define fixup libcdsb_builtin_fixup -rbnode_t LIBCDSB_RBTREE_NODE_EMPTY[1] = {{ - .colored = 0, - .value = 0, - .parent = rbnode_empty, - .left = rbnode_empty, - .right = rbnode_empty -}}; -/*#####################################################################################################################*/ - -static inline void rotate(rbnode_t **x, rbnode_t *c, rbdir_t d) { +static void libcdsb_builtin_rotate(rbnode_t **x, rbnode_t *c, rbdir_t d) { rbnode_t* n = rbdir_inv(c, d); rbdir_inv(c, d) = rbdir_dir(n, d); @@ -41,7 +34,8 @@ static inline void rotate(rbnode_t **x, rbnode_t *c, rbdir_t d) { c->parent = n; } -static inline void replace(rbnode_t** x, rbnode_t* c, rbnode_t* n) { + +static void libcdsb_builtin_replace(rbnode_t** x, rbnode_t* c, rbnode_t* n) { if (!rbnode_is_root(c)) { if (c->parent->left == c) { c->parent->left = n; @@ -51,10 +45,7 @@ static inline void replace(rbnode_t** x, rbnode_t* c, rbnode_t* n) { } -/*#####################################################################################################################*/ - - -static void delete_fixup(rbnode_t** x, rbnode_t* n) { +static void libcdsb_builtin_fixup(rbnode_t** x, rbnode_t* n) { rbdir_t d; rbnode_t *s, *p; @@ -98,8 +89,16 @@ static void delete_fixup(rbnode_t** x, rbnode_t* n) { /*#####################################################################################################################*/ +rbnode_t LIBCDSB_BUILTIN_RBTREE_NODE_EMPTY[1] = {{ + .colored = 0, + .value = 0, + .parent = rbnode_empty, + .left = rbnode_empty, + .right = rbnode_empty +}}; -rbnode_t* libcdsb_rbtree_node_delete(rbnode_t** x, rbnode_t* c) { + +rbnode_t* libcdsb_builtin_rbtree_node_delete(rbnode_t** x, rbnode_t* c) { rbnode_t *n, *t; int s; @@ -135,14 +134,14 @@ rbnode_t* libcdsb_rbtree_node_delete(rbnode_t** x, rbnode_t* c) { t->left = c->left; } - if (!s) delete_fixup(x, n); + if (!s) fixup(x, n); return c; } -void libcdsb_rbtree_node_fixup(rbnode_t** x, rbnode_t* n) { +void libcdsb_builtin_rbtree_node_fixup(rbnode_t** x, rbnode_t* n) { rbdir_t d[2]; rbnode_t *u, *p, *gp; @@ -181,7 +180,7 @@ void libcdsb_rbtree_node_fixup(rbnode_t** x, rbnode_t* n) { } -void* libcdsb_rbtree_node_create(void* v, rbnode_t* p, int c, int n) { +void* libcdsb_builtin_rbtree_node_create(void* v, rbnode_t* p, int c, int n) { rbnode_t* x; x = malloc(n); diff --git a/src/set/comparison.c b/src/set/comparison.c index 4a3dabc..fbf2908 100644 --- a/src/set/comparison.c +++ b/src/set/comparison.c @@ -4,7 +4,7 @@ #include "../../include/set.h" #include "../__internal/rbtree.h" -static inline int rbnode_compare(const rbnode_t* s0, const rbnode_t* s1, vtype t) { +static inline int libcdsb_builtin_compare(const rbnode_t* s0, const rbnode_t* s1, vtype t) { return vnode_compare(s0->value, t, s1->value, t); } @@ -34,13 +34,13 @@ int vset_compare(const set_t* s0, const set_t* s1) { stack_flush(&z); return rbnode_is_empty(c0) ? -1 : 1; } - } else if ((cmp = rbnode_compare(c0, c1, s0->type))) { + } else if ((cmp = libcdsb_builtin_compare(c0, c1, s0->type))) { if (c0->left == c1->right) { // == rbnode_empty - cmp = rbnode_compare(c0->right, c1, s0->type); - if (!cmp) cmp = rbnode_compare(c0, c1->left, s0->type); + cmp = libcdsb_builtin_compare(c0->right, c1, s0->type); + if (!cmp) cmp = libcdsb_builtin_compare(c0, c1->left, s0->type); } else if (c0->right == c1->left) { // == rbnode_empty - cmp = rbnode_compare(c0, c1->right, s0->type); - if (!cmp) cmp = rbnode_compare(c0->left, c1, s0->type); + cmp = libcdsb_builtin_compare(c0, c1->right, s0->type); + if (!cmp) cmp = libcdsb_builtin_compare(c0->left, c1, s0->type); } if (cmp) { diff --git a/src/set/compute.c b/src/set/compute.c index 3f3bb78..8cf4b98 100644 --- a/src/set/compute.c +++ b/src/set/compute.c @@ -4,7 +4,7 @@ #include "../../include/set.h" #include "../__internal/rbtree.h" -static inline hash_t rbnode_hash(const rbnode_t* s, vtype t) { +static inline hash_t libcdsb_builtin_hash(const rbnode_t* s, vtype t) { return vnode_hash(&s->value, t); } @@ -54,7 +54,7 @@ hash_t vset_hash(const set_t* s) { } while (!is_null(c0 = stack_pop(&z))); } - v = rbnode_hash(c1, s->type); + v = libcdsb_builtin_hash(c1, s->type); stack_push(&z, s->root->right); if (!rbnode_is_empty(c0 = stack_pop(&z))) { @@ -65,7 +65,7 @@ hash_t vset_hash(const set_t* s) { } while (!is_null(c0 = stack_pop(&z))); } - v += rbnode_hash(c1, s->type); + v += libcdsb_builtin_hash(c1, s->type); return (hash ^ v) + VTYPE_SET; } diff --git a/src/string/include.h b/src/string/include.h index 15b1960..3a559e8 100644 --- a/src/string/include.h +++ b/src/string/include.h @@ -8,14 +8,14 @@ #ifndef LIBCDSB_SRC_STRING_INCLUDE_H #define LIBCDSB_SRC_STRING_INCLUDE_H -ainline(char* next_char(char* s)) { +ainline(char* libcdsb_builtin_next_char(char* s)) { int cs = charsize(s); if (cs) return s + cs; return ++s; } -ainline(char* prev_char(char* s)) { +ainline(char* libcdsb_builtin_prev_char(char* s)) { if (*(--s)&0x80) { char* p = s; @@ -29,4 +29,7 @@ ainline(char* prev_char(char* s)) { return s; } +#define next_char libcdsb_builtin_next_char +#define prev_char libcdsb_builtin_prev_char + #endif /* LIBCDSB_SRC_STRING_INCLUDE_H */ diff --git a/src/string/transform.c b/src/string/transform.c index 9ea825d..2fdecf6 100644 --- a/src/string/transform.c +++ b/src/string/transform.c @@ -3,7 +3,7 @@ #include "include.h" -static void string_replace_builtin(str_t* x, char* p, size_t n, const char* v, size_t vn) { +static void libcdsb_builtin_replace(str_t* x, char* p, size_t n, const char* v, size_t vn) { if (n != vn) { size_t l = strlen(x->buffer); @@ -75,7 +75,7 @@ size_t string_to_lower(str_t* x) { es = tochar_unicode(ps, uc1); if (!is_null(es)) { - string_replace_builtin(x, p, e-p, ps, es-ps); + libcdsb_builtin_replace(x, p, e-p, ps, es-ps); ++n; } } @@ -111,7 +111,7 @@ size_t string_to_upper(str_t* x) { es = tochar_unicode(ps, uc1); if (!is_null(es)) { - string_replace_builtin(x, p, e-p, ps, es-ps); + libcdsb_builtin_replace(x, p, e-p, ps, es-ps); ++n; } } @@ -145,7 +145,7 @@ size_t string_capitalize(str_t* x) { es = tochar_unicode(ps, uc1); if (!is_null(es)) { - string_replace_builtin(x, p, e-p, ps, es-ps); + libcdsb_builtin_replace(x, p, e-p, ps, es-ps); ++n; } } @@ -163,7 +163,7 @@ size_t string_capitalize(str_t* x) { es = tochar_unicode(ps, uc1); if (!is_null(es)) { - string_replace_builtin(x, p, e-p, ps, es-ps); + libcdsb_builtin_replace(x, p, e-p, ps, es-ps); ++n; } } diff --git a/src/vnode.c b/src/vnode.c index 5a30d6e..33babed 100644 --- a/src/vnode.c +++ b/src/vnode.c @@ -5,7 +5,7 @@ #include "__internal/vnode.h" #include "../include/string.h" -static vtype internal_round(u64_t* x, ldbl_t v) { +static vtype libcdsb_builtin_round(u64_t* x, ldbl_t v) { if (v > 0) { *x = (u64_t)(v + 0.5); return VTYPE_UINT64; @@ -15,18 +15,16 @@ static vtype internal_round(u64_t* x, ldbl_t v) { } } -/*#####################################################################################################################*/ - -static vnode_t create_value(vtype xt, const void* v, vtype t) { +static vnode_t libcdsb_builtin_create_value(vtype xt, const void* v, vtype t) { var_t _; if (t == VTYPE_FLOAT) { - t = internal_round(&_.u64, *(fl_t*)v); + t = libcdsb_builtin_round(&_.u64, *(fl_t*)v); } else if (t == VTYPE_DOUBLE) { - t = internal_round(&_.u64, *(dbl_t*)v); + t = libcdsb_builtin_round(&_.u64, *(dbl_t*)v); } else if (t == VTYPE_LDOUBLE) { - t = internal_round(&_.u64, *(ldbl_t*)v); + t = libcdsb_builtin_round(&_.u64, *(ldbl_t*)v); } if (sizeof(void*) == 8) { @@ -85,7 +83,7 @@ static vnode_t create_value(vtype xt, const void* v, vtype t) { } -static vnode_t create_float(vtype xt, const void* v, vtype t) { +static vnode_t libcdsb_builtin_create_float(vtype xt, const void* v, vtype t) { var_t _; if (t == VTYPE_UINT8 || t == VTYPE_BOOLEAN ) { @@ -131,11 +129,9 @@ static vnode_t create_float(vtype xt, const void* v, vtype t) { return _.ptr; } - /*#####################################################################################################################*/ - -vnode_t libcdsb_vnode_create(const void* v, vtype t) { +vnode_t libcdsb_builtin_vnode_create(const void* v, vtype t) { var_t _ = { .ptr = 0 }; switch (t) { default: abort(); @@ -198,10 +194,7 @@ vnode_t libcdsb_vnode_create(const void* v, vtype t) { } -/*#####################################################################################################################*/ - - -void* libcdsb_vnode_peek(const vnode_t* x, vtype t) { +void* libcdsb_builtin_vnode_peek(const vnode_t* x, vtype t) { switch (t) { default: abort(); case VTYPE_FLOAT: if (is_permissible(fl_t)) goto vt_; else goto pt_; @@ -232,7 +225,7 @@ void* libcdsb_vnode_peek(const vnode_t* x, vtype t) { } -void libcdsb_vnode_free(vnode_t* x, vtype t) { +void libcdsb_builtin_vnode_free(vnode_t* x, vtype t) { switch (t) { default: abort(); @@ -271,18 +264,15 @@ void libcdsb_vnode_free(vnode_t* x, vtype t) { } -/*#####################################################################################################################*/ - - -vnode_t libcdsb_vnode_create_target(vtype xt, const void* v, vtype t) { +vnode_t libcdsb_builtin_vnode_create_target(vtype xt, const void* v, vtype t) { var_t _ = { .ptr = 0 }; if (xt <= VTYPE_LDOUBLE) { if (t >= VTYPE_STRING) t = VTYPE_POINTER; if (xt <= VTYPE_INT64) - return create_value(xt, v, t); - return create_float(xt, v, t); + return libcdsb_builtin_create_value(xt, v, t); + return libcdsb_builtin_create_float(xt, v, t); } else if (t == VTYPE_POINTER && (t = xt) > VTYPE_STRING) { v = *(void**)v; } diff --git a/src/vtype-extra.c b/src/vtype-extra.c index 8776b10..054ea29 100644 --- a/src/vtype-extra.c +++ b/src/vtype-extra.c @@ -4,8 +4,6 @@ #include #include "__internal/include.h" -/*#####################################################################################################################*/ - #define sh__(a) #a #define s__(a) sh__(a) @@ -19,14 +17,14 @@ double: "%."s__(DBL_DIG)"lg",\ long double: "%."s__(LDBL_DIG)"Lg") -#define stringify(v) sprintf(STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS], fstring(v), (v)) +#define stringify(v) sprintf(LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER], fstring(v), (v)) -static _Thread_local int STRINGIFY_BUFFER_POS = 0; -static _Thread_local char STRINGIFY_BUFFER[16][64]; +static _Thread_local int LIBCDSB_BUILTIN_COUNTER = 0; +static _Thread_local char LIBCDSB_BUILTIN_BUFFER[16][64]; /*#####################################################################################################################*/ -const size_t LIBCDSB_VTYPE_SIZES[19] = { +const size_t LIBCDSB_BUILTIN_VTYPE_SIZES[19] = { sizeof(void*), sizeof(bool), sizeof(u8_t), sizeof(u16_t), sizeof(u32_t), sizeof(u64_t), sizeof(s8_t), sizeof(s16_t), sizeof(s32_t), sizeof(s64_t), @@ -35,7 +33,6 @@ const size_t LIBCDSB_VTYPE_SIZES[19] = { sizeof(list_t), sizeof(set_t), sizeof(dict_t) }; -/*#####################################################################################################################*/ const char* libcdsb_vtype_name(vtype t) { switch (t) { @@ -70,8 +67,8 @@ const char* libcdsb_vtype_stringify(const void* v, vtype t) { if (t == VTYPE_BOOLEAN) return (*(vtype_bool*)v) ? "true" : "false"; if (t == VTYPE_STRING) return *(char**)v; - if (STRINGIFY_BUFFER_POS > 15) - STRINGIFY_BUFFER_POS = 0; + if (LIBCDSB_BUILTIN_COUNTER > 15) + LIBCDSB_BUILTIN_COUNTER = 0; switch (t) { case VTYPE_INT8: stringify(*( s8_t*)v); break; @@ -83,25 +80,25 @@ const char* libcdsb_vtype_stringify(const void* v, vtype t) { case VTYPE_UINT32: stringify(*( u32_t*)v); break; case VTYPE_UINT64: stringify(*( u64_t*)v); break; case VTYPE_FLOAT: if (abs(*(fl_t*)v) <= FLT_EPSILON) { - STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS][0] = 0x30; - STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS][1] = 0x00; + LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER][0] = 0x30; + LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER][1] = 0x00; } else stringify(*(fl_t*)v); break; case VTYPE_DOUBLE: if (abs(*(dbl_t*)v) <= DBL_EPSILON) { - STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS][0] = 0x30; - STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS][1] = 0x00; + LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER][0] = 0x30; + LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER][1] = 0x00; } else stringify(*(dbl_t*)v); break; case VTYPE_LDOUBLE: if (abs(*(ldbl_t*)v) <= LDBL_EPSILON) { - STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS][0] = 0x30; - STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS][1] = 0x00; + LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER][0] = 0x30; + LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER][1] = 0x00; } else stringify(*(ldbl_t*)v); break; - case VTYPE_POINTER: sprintf(STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS], (sizeof(void*) == 8) ? "0x%016lx" : "0x%08x", (uintptr_t)*(void**)v); break; + case VTYPE_POINTER: sprintf(LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER], (sizeof(void*) == 8) ? "0x%016lx" : "0x%08x", (uintptr_t)*(void**)v); break; - default: sprintf(STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS], "<%s>", libcdsb_vtype_name(t)); + default: sprintf(LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER], "<%s>", libcdsb_vtype_name(t)); break; } - return STRINGIFY_BUFFER[STRINGIFY_BUFFER_POS++]; + return LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER++]; } diff --git a/src/vtype.c b/src/vtype.c index 45663d8..e8389e5 100644 --- a/src/vtype.c +++ b/src/vtype.c @@ -6,7 +6,7 @@ /*#####################################################################################################################*/ -static ldbl_t normalize_value(const void* v, vtype t) { +static ldbl_t libcdsb_builtin_normalize(const void* v, vtype t) { if (t == VTYPE_BOOLEAN || t == VTYPE_UINT8) { return *(u8_t*)v; } else if (t == VTYPE_UINT16) { @@ -30,7 +30,7 @@ static ldbl_t normalize_value(const void* v, vtype t) { } else return abs(*(ldbl_t*)v) <= LDBL_EPSILON ? 0 : *(ldbl_t*)v; } -static hash_t ldouble_hash(ldbl_t s) { +static hash_t libcdsb_builtin_hash_float(ldbl_t s) { hash_t hash; if (sizeof(hash_t) == sizeof(u64_t)) { @@ -61,14 +61,14 @@ static hash_t ldouble_hash(ldbl_t s) { /*#####################################################################################################################*/ -int libcdsb_vtype_compare_values(const void* s0, vtype t0, const void* s1, vtype t1) { - if (t0 == t1) return libcdsb_vtype_compare_values_eq(s0, s1, t0); +int libcdsb_builtin_vtype_compare_values(const void* s0, vtype t0, const void* s1, vtype t1) { + if (t0 == t1) return libcdsb_builtin_vtype_compare_values_eq(s0, s1, t0); if (t0 <= VTYPE_LDOUBLE && t1 <= VTYPE_LDOUBLE) { ldbl_t d0, d1; - d0 = normalize_value(s0, t0); - d1 = normalize_value(s1, t1); + d0 = libcdsb_builtin_normalize(s0, t0); + d1 = libcdsb_builtin_normalize(s1, t1); return (abs(d0 - d1) <= LDBL_EPSILON) ? 0 : (d0 < d1 ? -1 : 1); } @@ -77,7 +77,7 @@ int libcdsb_vtype_compare_values(const void* s0, vtype t0, const void* s1, vtype } -int libcdsb_vtype_compare_values_eq(const void* s0, const void* s1, vtype t) { +int libcdsb_builtin_vtype_compare_values_eq(const void* s0, const void* s1, vtype t) { #define compare(T, s0, s1) *(T*)s0 == *(T*)s1 ? 0 : (*(T*)s0 < *(T*)s1 ? -1 : 1) @@ -117,7 +117,7 @@ int libcdsb_vtype_compare_values_eq(const void* s0, const void* s1, vtype t) { /*#####################################################################################################################*/ -hash_t libcdsb_vtype_hash(const void* v, vtype t) { +hash_t libcdsb_builtin_vtype_hash(const void* v, vtype t) { switch (t) { default: abort(); @@ -147,8 +147,8 @@ hash_t libcdsb_vtype_hash(const void* v, vtype t) { case VTYPE_SET: return vset_hash(v); case VTYPE_DICT: return dict_hash(v); - case VTYPE_FLOAT: return ldouble_hash(*(fl_t*)v); - case VTYPE_DOUBLE: return ldouble_hash(*(dbl_t*)v); - case VTYPE_LDOUBLE: return ldouble_hash(*(ldbl_t*)v); + case VTYPE_FLOAT: return libcdsb_builtin_hash_float(*(fl_t*)v); + case VTYPE_DOUBLE: return libcdsb_builtin_hash_float(*(dbl_t*)v); + case VTYPE_LDOUBLE: return libcdsb_builtin_hash_float(*(ldbl_t*)v); } } From d7bd9be567d6167335502d80d0c983f203505867 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Wed, 24 Aug 2022 11:43:27 +0300 Subject: [PATCH 12/18] Update headers --- include/array.h | 1 + include/bits/__rbtree.h | 20 ++++++++++++++++++++ include/dict.h | 1 + include/list.h | 1 + include/map.h | 6 ++++-- include/set.h | 6 ++++-- 6 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 include/bits/__rbtree.h 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 */ From 8858e02afb31b6bbf97c985aea76181f9ba967cc Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Wed, 24 Aug 2022 12:26:17 +0300 Subject: [PATCH 13/18] Add implementation of the stack reversion --- include/bits/memory.h | 1 + src/extra-stack.c | 48 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/include/bits/memory.h b/include/bits/memory.h index 5750557..5cc4635 100644 --- a/include/bits/memory.h +++ b/include/bits/memory.h @@ -16,6 +16,7 @@ extern void libcdsb_stack_init (stack_t* stack) Nonnull__(1) extern void libcdsb_stack_push (stack_t* stack, void* value) Nonnull__(1); extern void libcdsb_stack_push_many(stack_t* stack, size_t n, ...) Nonnull__(1); extern void* libcdsb_stack_pop (stack_t* stack) Nonnull__(1); +extern void libcdsb_stack_reverse (stack_t* stack) Nonnull__(1); extern void libcdsb_stack_flush (stack_t* stack) Nonnull__(1); extern void* libcdsb_aalloc (size_t a, size_t n) Warn_unused_result__; diff --git a/src/extra-stack.c b/src/extra-stack.c index 563a177..bdaca67 100644 --- a/src/extra-stack.c +++ b/src/extra-stack.c @@ -27,6 +27,7 @@ void libcdsb_stack_push(stack_t* x, void* value) { x->value = value; } + void libcdsb_stack_push_many(stack_t* x, size_t c, ...) { va_list args; @@ -52,6 +53,7 @@ void libcdsb_stack_push_many(stack_t* x, size_t c, ...) { va_end(args); } + void* libcdsb_stack_pop(stack_t* x) { stack_t* n; @@ -70,14 +72,50 @@ void* libcdsb_stack_pop(stack_t* x) { } -void libcdsb_stack_flush(stack_t* stack) { +void libcdsb_stack_reverse(stack_t* x) { + + stack_t z, *iter, *n, copy; + + + if (x->prev) { + z.prev = 0; + z.value = x->value; + iter = x->prev; + + while (iter->prev) { + n = iter; + iter = n->prev; + + copy.prev = z.prev; + copy.value = z.value; + + z.prev = n; + z.value = n->value; + + n->prev = copy.prev; + n->value = copy.value; + } + + copy.prev = z.prev; + copy.value = z.value; + + x->prev = iter; + x->value = iter->value; + + iter->prev = copy.prev; + iter->value = copy.value; + } +} + + +void libcdsb_stack_flush(stack_t* x) { stack_t* c; - while (stack->prev) { - c = stack->prev; - stack->prev = c->prev; + while (x->prev) { + c = x->prev; + x->prev = c->prev; free(c); } - stack->value = 0; + x->value = 0; } From 4a174df6da863325c39c6cdac7ebd8397fce3d2a Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Wed, 24 Aug 2022 12:28:45 +0300 Subject: [PATCH 14/18] Add rbtree iterator implementation --- src/__internal/include.h | 13 ++++ src/__internal/rbtree.h | 12 ++- src/rbtree.c | 157 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 3 deletions(-) diff --git a/src/__internal/include.h b/src/__internal/include.h index 1fcb493..ab46005 100644 --- a/src/__internal/include.h +++ b/src/__internal/include.h @@ -64,6 +64,17 @@ extern int libcdsb_builtin_vtype_compare_values (const void* s0, vtype t0, extern int libcdsb_builtin_vtype_compare_values_eq(const void* s0, const void* s1, vtype t) pure__ wur__; extern hash_t libcdsb_builtin_vtype_hash (const void* value, vtype type) pure__ wur__; +ainline(stack_t* libcdsb_builtin_stack_insert(stack_t* x, void* v)) { + stack_t* p = x->prev; + + if (!is_null(x->prev = malloc(sizeof(*x)))) { + x->prev->prev = p; + x->prev->value = v; + } else abort(); + + return x->prev; +} + #define aligned_alloc libcdsb_aalloc #define malloc libcdsb_malloc #define calloc libcdsb_calloc @@ -72,7 +83,9 @@ extern hash_t libcdsb_builtin_vtype_hash (const void* value, vtype t #define stack_init libcdsb_stack_init #define stack_push libcdsb_stack_push #define stack_push_many libcdsb_stack_push_many +#define stack_insert libcdsb_builtin_stack_insert #define stack_pop libcdsb_stack_pop +#define stack_reverse libcdsb_stack_reverse #define stack_flush libcdsb_stack_flush #define strlen libcdsb_strlen #define strasciilen libcdsb_strasciilen diff --git a/src/__internal/rbtree.h b/src/__internal/rbtree.h index a974485..3cdde2b 100644 --- a/src/__internal/rbtree.h +++ b/src/__internal/rbtree.h @@ -21,9 +21,10 @@ extern void* libcdsb_builtin_rbtree_node_create(void* value, rbnode_t* paren extern void libcdsb_builtin_rbtree_node_fixup (rbnode_t** root, rbnode_t* node) Nonnull__(1,2); extern rbnode_t* libcdsb_builtin_rbtree_node_delete(rbnode_t** root, rbnode_t* node) Nonnull__(1,2); -extern rbnode_t* libcdsb_builtin_rbtree_next_inorder (rbnode_t** root, rbnode_t* prev, bool reverse); -extern rbnode_t* libcdsb_builtin_rbtree_next_preorder (rbnode_t** root, rbnode_t* prev, bool reverse); -extern rbnode_t* libcdsb_builtin_rbtree_next_postorder(rbnode_t** root, rbnode_t* prev, bool reverse); +extern stack_t libcdsb_builtin_rbtree_iter_inorder (rbnode_t** root, bool reverse); +extern stack_t libcdsb_builtin_rbtree_iter_preorder (rbnode_t** root, bool reverse); +extern stack_t libcdsb_builtin_rbtree_iter_postorder (rbnode_t** root, bool reverse); +extern stack_t libcdsb_builtin_rbtree_iter_breath_first(rbnode_t** root, bool reverse); #define rbnode_empty ((rbnode_t*)LIBCDSB_BUILTIN_RBTREE_NODE_EMPTY) #define rbnode_create(v, p, c) ((rbnode_t*)libcdsb_builtin_rbtree_node_create(v, p, c, sizeof(rbnode_t))) @@ -33,4 +34,9 @@ extern rbnode_t* libcdsb_builtin_rbtree_next_postorder(rbnode_t** root, rbnode_t #define rbnode_is_empty(n) ((n) == rbnode_empty) #define rbnode_is_root(n) rbnode_is_empty((n)->parent) +#define rbiter_inorder libcdsb_builtin_rbtree_iter_inorder +#define rbiter_preorder libcdsb_builtin_rbtree_iter_preorder +#define rbiter_postorder libcdsb_builtin_rbtree_iter_postorder +#define rbiter_breath_first libcdsb_builtin_rbtree_iter_breath_first + #endif /* LIBCDSB_SRC_INTERNAL_RBTREE_H */ diff --git a/src/rbtree.c b/src/rbtree.c index 4d9df47..025ff6d 100644 --- a/src/rbtree.c +++ b/src/rbtree.c @@ -193,3 +193,160 @@ void* libcdsb_builtin_rbtree_node_create(void* v, rbnode_t* p, int c, int n) { return x; } + + +stack_t libcdsb_builtin_rbtree_iter_inorder(rbnode_t** root, bool reverse) { + rbnode_t *n, hack; + stack_t z, *bot; + + memset(&z, 0, sizeof(z)); + + if (rbnode_is_empty(*root)) + return z; + + hack.right = *root; + n = &hack; + + for (bot = &z;;) { + for (;;) { + if (rbnode_is_empty(n->right)) { + + if (rbnode_is_root(n->parent) || n->parent->left == n) { + n = n->parent; + break; + } else n = n->parent; + + if (rbnode_is_root(n->parent) || n->parent->left == n) { + n = n->parent; + break; + } + + do { + n = n->parent; + } while (n->parent->right == n); + + n = n->parent; + } else { + n = n->right; + + while (!rbnode_is_empty(n->left)) + n = n->left; + + break; + } + + if (rbnode_is_root(n)) { + bot = z.prev; + z = *bot; + + free(bot); + + if (reverse) + stack_reverse(&z); + + return z; + } + } + + bot = stack_insert(bot, n); + } +} + + +stack_t libcdsb_builtin_rbtree_iter_preorder(rbnode_t** root, bool reverse) { + stack_t z, *cur, *next; + rbnode_t *n; + + memset(&z, 0, sizeof(z)); + + if (rbnode_is_empty(*root)) + return z; + + z.value = *root; + cur = &z; + + do { + n = (next = cur)->value; + + if (!rbnode_is_empty(n->left)) next = stack_insert(cur, n->left); + if (!rbnode_is_empty(n->right)) stack_insert(next, n->right); + } while (!is_null(cur = cur->prev)); + + if (reverse) + stack_reverse(&z); + + return z; +} + + +stack_t libcdsb_builtin_rbtree_iter_postorder(rbnode_t** root, bool reverse) { + rbnode_t *p, *n; + stack_t z, *bot; + + bot = &z; + z.prev = 0; + z.value = 0; + + if (rbnode_is_empty(p = *root)) + return z; + + goto mid_; + + do { + if (n->parent->right != n && !rbnode_is_empty(n->parent->right)) { + p = n->parent->right; + do { mid_: + n = p; + p = !rbnode_is_empty(p->left) ? p->left : p->right; + } while (!rbnode_is_empty(p)); + } else n = n->parent; + + bot = stack_insert(bot, n); + } while (!rbnode_is_root(n)); + + bot = z.prev; + z = *bot; + + free(bot); + + if (reverse) + stack_reverse(&z); + + return z; +} + + +stack_t libcdsb_builtin_rbtree_iter_breath_first(rbnode_t** root, bool reverse) { + + stack_t z, *top, *bot, *cur; + rbnode_t* n; + + memset(&z, 0, sizeof(z)); + + if (rbnode_is_empty(z.value = *root)) + return z; + + for (top = bot = &z;;) { + for (cur = bot;;) { + + n = top->value; + + if (!rbnode_is_empty(n->left)) cur = stack_insert(cur, n->left); + if (!rbnode_is_empty(n->right)) cur = stack_insert(cur, n->right); + + if (top == bot) { + top = top->prev; + break; + } else top = top->prev; + } + + if (!is_null(top)) { + while (!is_null(bot->prev)) bot = bot->prev; + } else break; + } + + if (reverse) + stack_reverse(&z); + + return z; +} From 1d8e8efe90c3e429d6fc0bb05a5ba351cbf33f9f Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Wed, 24 Aug 2022 12:29:55 +0300 Subject: [PATCH 15/18] Update rbtree-based foreach implementation --- src/map/access.c | 100 ++++++++++++++++++++++++++++++--------------- src/map/include.h | 5 +++ src/set/access.c | 101 +++++++++++++++++++++++++++++++--------------- 3 files changed, 142 insertions(+), 64 deletions(-) diff --git a/src/map/access.c b/src/map/access.c index 83c51fe..d3b62cc 100644 --- a/src/map/access.c +++ b/src/map/access.c @@ -3,6 +3,48 @@ #include "include.h" +static int libcdsb_builtin_foreach(map_t* x, void* data, map_access_callback callback) { + stack_t z, *top, *bot, *cur; + mnode_t* n; + int r = 0; + + memset(&z, 0, sizeof(z)); + + if (rbnode_is_empty(z.value = x->root)) + return 0; + + for (top = bot = &z;;) { + for (cur = bot;;) { + + n = top->value; + + if (!mnode_is_empty(n->left)) cur = stack_insert(cur, n->left); + if (!mnode_is_empty(n->right)) cur = stack_insert(cur, n->right); + + if (!r) { + r = callback(vnode_peek(&n->key, x->type), x->type, vnode_peek(&n->value, n->type), n->type, data); + } else { + stack_flush(&z); + return r; + } + + if (top == bot) { + top = top->prev; + break; + } else top = top->prev; + } + + if (!is_null(top)) { + while (!is_null(bot->prev)) bot = bot->prev; + } else break; + } + + stack_flush(&z); + return r; +} + +/*#####################################################################################################################*/ + int libcdsb_map_find(map_t* x, const void* k, vtype t, void* _, map_access_callback callback, bool cut) { mnode_t* c; void *key; @@ -32,47 +74,41 @@ int libcdsb_map_find(map_t* x, const void* k, vtype t, void* _, map_access_callb } -int libcdsb_map_foreach(map_t* x, void* dt, map_access_callback callback, bool flush) { - stack_t z; - int r; - mnode_t* c; +int libcdsb_map_foreach(map_t* x, void* data, map_access_callback callback, rbforeach_t type, bool flush) { + bool reverse; + stack_t iter; + mnode_t* n; + int r = 0; - stack_init(&z); - stack_push(&z, x->root); + reverse = type&RBFOREACH_REVERSE; - r = 0; + switch (type&(RBFOREACH_INORDER|RBFOREACH_PREORDER|RBFOREACH_POSTORDER|RBFOREACH_BREADTH_FIRST)) { + case RBFOREACH_INORDER: iter = miter_inorder (&x->root, reverse); break; + case RBFOREACH_PREORDER: iter = miter_preorder (&x->root, reverse); break; + case RBFOREACH_POSTORDER: iter = miter_postorder(&x->root, reverse); break; - if (mnode_is_empty(x->root)) - return 0; + default: + case RBFOREACH_BREADTH_FIRST: if (reverse || flush) { + iter = miter_breath_first(&x->root, type&RBFOREACH_REVERSE); + break; + } else return libcdsb_builtin_foreach(x, data, callback); + } - while ((c = stack_pop(&z))) { - if ((r = callback(vnode_peek(&c->key, x->type), x->type, vnode_peek(&c->value, c->type), c->type, dt))) - break; - - if (!mnode_is_empty(c->right)) stack_push(&z, c->right); - if (!mnode_is_empty(c->left)) stack_push(&z, c->left); + while ((n = stack_pop(&iter))) { + if (!r) { + r = callback(vnode_peek(&n->key, x->type), x->type, vnode_peek(&n->value, n->type), n->type, data); + } else if (!flush) { + stack_flush(&iter); + return r; + } if (flush) { - vnode_free(&c->key, x->type); - vnode_free(&c->value, c->type); - free(c); + vnode_free(&n->value, x->type); + free(n); } } - if (flush) { - while (c) { - if (!mnode_is_empty(c->right)) stack_push(&z, c->right); - if (!mnode_is_empty(c->left)) stack_push(&z, c->left); - - vnode_free(&c->key, x->type); - vnode_free(&c->value, c->type); - free(c); - - c = stack_pop(&z); - } - - memset(x, 0, sizeof(*x)); - } else stack_flush(&z); + if (flush) x->root = mnode_empty; return r; } diff --git a/src/map/include.h b/src/map/include.h index 2c12f93..5587d97 100644 --- a/src/map/include.h +++ b/src/map/include.h @@ -35,4 +35,9 @@ static_assert(offsetof(struct libcdsb_set, type) == offsetof(struct l #define mnode_is_empty(n) ((n) == mnode_empty) #define mnode_is_root(n) mnode_is_empty((n)->parent) +#define miter_inorder(x, reverse) rbiter_inorder((void*)x, reverse) +#define miter_preorder(x, reverse) rbiter_preorder((void*)x, reverse) +#define miter_postorder(x, reverse) rbiter_postorder((void*)x, reverse) +#define miter_breath_first(x, reverse) rbiter_breath_first((void*)x, reverse) + #endif /* LIBCDSB_SRC_MAP_INCLUDE_H */ diff --git a/src/set/access.c b/src/set/access.c index 2f022c1..2e5a4c4 100644 --- a/src/set/access.c +++ b/src/set/access.c @@ -4,6 +4,48 @@ #include "../../include/set.h" #include "../__internal/rbtree.h" +static int libcdsb_builtin_foreach(set_t* x, void* data, vset_access_callback callback) { + stack_t z, *top, *bot, *cur; + rbnode_t* n; + int r = 0; + + memset(&z, 0, sizeof(z)); + + if (rbnode_is_empty(z.value = x->root)) + return 0; + + for (top = bot = &z;;) { + for (cur = bot;;) { + + n = top->value; + + if (!rbnode_is_empty(n->left)) cur = stack_insert(cur, n->left); + if (!rbnode_is_empty(n->right)) cur = stack_insert(cur, n->right); + + if (!r) { + r = callback(vnode_peek(&n->value, x->type), x->type, data); + } else { + stack_flush(&z); + return r; + } + + if (top == bot) { + top = top->prev; + break; + } else top = top->prev; + } + + if (!is_null(top)) { + while (!is_null(bot->prev)) bot = bot->prev; + } else break; + } + + stack_flush(&z); + return r; +} + +/*#####################################################################################################################*/ + int libcdsb_vset_find(vtype_set* x, const void* v, vtype t, void* _, vset_access_callback callback, bool cut) { rbnode_t* c; void *val; @@ -32,46 +74,41 @@ int libcdsb_vset_find(vtype_set* x, const void* v, vtype t, void* _, vset_access } -int libcdsb_vset_foreach(set_t* x, void* data, vset_access_callback callback, bool flush) { - stack_t z; - int r; - rbnode_t* c; +int libcdsb_vset_foreach(set_t* x, void* data, vset_access_callback callback, rbforeach_t type, bool flush) { + bool reverse; + stack_t iter; + rbnode_t* n; + int r = 0; - stack_init(&z); - stack_push(&z, x->root); + reverse = type&RBFOREACH_REVERSE; - r = 0; + switch (type&(RBFOREACH_INORDER|RBFOREACH_PREORDER|RBFOREACH_POSTORDER|RBFOREACH_BREADTH_FIRST)) { + case RBFOREACH_INORDER: iter = rbiter_inorder (&x->root, reverse); break; + case RBFOREACH_PREORDER: iter = rbiter_preorder (&x->root, reverse); break; + case RBFOREACH_POSTORDER: iter = rbiter_postorder(&x->root, reverse); break; + + default: + case RBFOREACH_BREADTH_FIRST: if (reverse || flush) { + iter = rbiter_breath_first(&x->root, type&RBFOREACH_REVERSE); + break; + } else return libcdsb_builtin_foreach(x, data, callback); + } - if (rbnode_is_empty(x->root)) - return 0; - - while ((c = stack_pop(&z))) { - if ((r = callback(vnode_peek(&c->value, x->type), x->type, data))) - break; - - - if (!rbnode_is_empty(c->right)) stack_push(&z, c->right); - if (!rbnode_is_empty(c->left)) stack_push(&z, c->left); + while ((n = stack_pop(&iter))) { + if (!r) { + r = callback(vnode_peek(&n->value, x->type), x->type, data); + } else if (!flush) { + stack_flush(&iter); + return r; + } if (flush) { - vnode_free(&c->value, x->type); - free(c); + vnode_free(&n->value, x->type); + free(n); } } - if (flush) { - while (c) { - if (!rbnode_is_empty(c->right)) stack_push(&z, c->right); - if (!rbnode_is_empty(c->left)) stack_push(&z, c->left); - - vnode_free(&c->value, x->type); - free(c); - - c = stack_pop(&z); - } - - memset(x, 0, sizeof(*x)); - } else stack_flush(&z); + if (flush) x->root = rbnode_empty; return r; } From 804769d85cc414d3aa0efe32dc4e516a055930f5 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Wed, 24 Aug 2022 12:31:33 +0300 Subject: [PATCH 16/18] Fix dict keys copy implementation --- src/dict/compute.c | 10 ---------- src/dict/copy.c | 38 +++++++++++++++++++++++--------------- src/list/copy.c | 27 --------------------------- src/list/include.h | 25 +++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 52 deletions(-) diff --git a/src/dict/compute.c b/src/dict/compute.c index 2750de4..a22d4d6 100644 --- a/src/dict/compute.c +++ b/src/dict/compute.c @@ -3,16 +3,6 @@ #include "include.h" -size_t dict_size(const dict_t* x) { - return x->size; -} - - -size_t dict_capacity(const dict_t* x) { - return x->capacity; -} - - hash_t dict_hash(const dict_t* s) { dnode_t *min, *max; size_t i; diff --git a/src/dict/copy.c b/src/dict/copy.c index 312d7c7..5845b7e 100644 --- a/src/dict/copy.c +++ b/src/dict/copy.c @@ -1,7 +1,7 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "../../include/list.h" +#include "../list/include.h" #include "include.h" static inline dnode_t* libcdsb_builtin_duplicate(const dnode_t* s, dnode_t* p) { @@ -81,10 +81,10 @@ void dict_copy_init(dict_t* x, const dict_t* s) { } -vtype_list libcdsb_dict_copy_keys(const vtype_dict* s) { - vtype_list x; - dnode_t *c; - size_t i; +list_t libcdsb_dict_copy_keys(const dict_t* s) { + list_t x; + dnode_t *c; + size_t i; i = s->capacity; @@ -94,7 +94,11 @@ vtype_list libcdsb_dict_copy_keys(const vtype_dict* s) { c = s->nodes[i]; while (!is_null(c)) { - libcdsb_list_insert(&x, -1, vnode_peek(&c->key, c->key_type), c->key_type, 1); + + if (is_null(x.first)) { + libcdsb_builtin_init(&x, vnode_duplicate(&c->key, c->key_type), c->key_type); + } else libcdsb_builtin_push(&x, vnode_duplicate(&c->key, c->key_type), c->key_type); + c = c->prev; } } @@ -103,10 +107,10 @@ vtype_list libcdsb_dict_copy_keys(const vtype_dict* s) { } -vtype_list* libcdsb_dict_duplicate_keys(const vtype_dict* s) { - vtype_list* x; - dnode_t *c; - size_t i; +list_t* libcdsb_dict_duplicate_keys(const dict_t* s) { + list_t* x; + dnode_t *c; + size_t i; x = malloc(sizeof(*x)); i = s->capacity; @@ -117,7 +121,9 @@ vtype_list* libcdsb_dict_duplicate_keys(const vtype_dict* s) { c = s->nodes[i]; while (!is_null(c)) { - libcdsb_list_insert(x, -1, vnode_peek(&c->key, c->key_type), c->key_type, 1); + if (is_null(x->first)) { + libcdsb_builtin_init(x, vnode_duplicate(&c->key, c->key_type), c->key_type); + } else libcdsb_builtin_push(x, vnode_duplicate(&c->key, c->key_type), c->key_type); c = c->prev; } } @@ -126,9 +132,9 @@ vtype_list* libcdsb_dict_duplicate_keys(const vtype_dict* s) { } -void libcdsb_dict_init_keys(vtype_list* x, const vtype_dict* s) { - dnode_t *c; - size_t i; +void libcdsb_dict_init_keys(list_t* x, const dict_t* s) { + dnode_t *c; + size_t i; x = malloc(sizeof(*x)); i = s->capacity; @@ -139,7 +145,9 @@ void libcdsb_dict_init_keys(vtype_list* x, const vtype_dict* s) { c = s->nodes[i]; while (!is_null(c)) { - libcdsb_list_insert(x, -1, vnode_peek(&c->key, c->key_type), c->key_type, 1); + if (is_null(x->first)) { + libcdsb_builtin_init(x, vnode_duplicate(&c->key, c->key_type), c->key_type); + } else libcdsb_builtin_push(x, vnode_duplicate(&c->key, c->key_type), c->key_type); c = c->prev; } } diff --git a/src/list/copy.c b/src/list/copy.c index 34e5b77..ed6b03d 100644 --- a/src/list/copy.c +++ b/src/list/copy.c @@ -3,33 +3,6 @@ #include "include.h" -static void libcdsb_builtin_init(list_t* x, vnode_t v, vtype t) { - lnode_t* node = malloc(sizeof(*node)); - - node->next = nullptr; - node->prev = nullptr; - node->node = v; - node->type = t; - - x->first = node; - x->last = node; -} - - -static void libcdsb_builtin_push(list_t* x, vnode_t v, vtype t) { - lnode_t* node = malloc(sizeof(*node)); - - node->next = nullptr; - node->prev = x->last; - node->node = v; - node->type = t; - - x->last->next = node; - x->last = node; -} - -/*#####################################################################################################################*/ - list_t list_copy(const list_t* s) { list_t x; lnode_t* c; diff --git a/src/list/include.h b/src/list/include.h index 463e872..f10b0a8 100644 --- a/src/list/include.h +++ b/src/list/include.h @@ -20,6 +20,31 @@ typedef struct libcdsb_list_node { vtype type; } lnode_t; + +ainline(void libcdsb_builtin_init(list_t* x, vnode_t v, vtype t)) { + lnode_t* node = malloc(sizeof(*node)); + + node->next = nullptr; + node->prev = nullptr; + node->node = v; + node->type = t; + + x->first = node; + x->last = node; +} + +ainline(void libcdsb_builtin_push(list_t* x, vnode_t v, vtype t)) { + lnode_t* node = malloc(sizeof(*node)); + + node->next = nullptr; + node->prev = x->last; + node->node = v; + node->type = t; + + x->last->next = node; + x->last = node; +} + #define ldir_dir(cur, d) (&((cur)->prev))[(d)>>1] #define ldir_inv(cur, d) (&((cur)->prev))[(d)&1] From f78d7f7ed9c1efbe8aa8927d3adbb523b600deb3 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Wed, 24 Aug 2022 12:32:06 +0300 Subject: [PATCH 17/18] Update tests --- tests/Makefile | 6 +- tests/src/array/plug.h | 2 +- tests/src/array/src/plug.c | 5 +- tests/src/array/src/random.c | 2 +- tests/src/dict/src/plug.c | 2 - tests/src/global/plug.h | 2 +- tests/src/global/src/random.c | 102 +++++++++++++++++++--------------- tests/src/list/src/plug.c | 2 - tests/src/list/src/random.c | 6 +- tests/src/map/src/plug.c | 2 - tests/src/set/src/plug.c | 2 - 11 files changed, 69 insertions(+), 64 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index bb8f5ee..a5297ce 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -51,6 +51,8 @@ tests: $(addprefix $(BUILD_PATH)/global-,$(notdir $(basename $(wildcard ./src/gl ######################################################################################################################## +CFLAGS:=$(CFLAGS) ../modules/libunic/bin/libunic.a + $(BUILD_PATH)/obj/%.o: ./src/%.c | $(BUILD_PATH)/obj/ $(CC) $^ -o $@ $(CFLAGS) @@ -72,7 +74,7 @@ $(BUILD_PATH)/obj/global-%.o: ./src/global/src/%.c | $(BUILD_PATH)/obj/ $(BUILD_PATH)/array-%: ./src/array/%.c $(OBJECTS_ARRAY) | $(BUILD_PATH)/ $(CC) $^ -o $@ $(CFLAGS) -g3 -Wall $(BUILD_PATH)/string-%: ./src/string/%.c $(OBJECTS_STRING) | $(BUILD_PATH)/ - $(CC) $^ -o $@ ../modules/libunic/bin/libunic.a $(CFLAGS) -g3 -Wall + $(CC) $^ -o $@ $(CFLAGS) -g3 -Wall $(BUILD_PATH)/list-%: ./src/list/%.c $(OBJECTS_LIST) | $(BUILD_PATH)/ $(CC) $^ -o $@ $(CFLAGS) -g3 -Wall $(BUILD_PATH)/map-%: ./src/map/%.c $(OBJECTS_MAP) | $(BUILD_PATH)/ @@ -82,7 +84,7 @@ $(BUILD_PATH)/set-%: ./src/set/%.c $(OBJECTS_SET) | $(BUILD_PATH)/ $(BUILD_PATH)/dict-%: ./src/dict/%.c $(OBJECTS_DICT) | $(BUILD_PATH)/ $(CC) $^ -o $@ $(CFLAGS) -g3 -Wall $(BUILD_PATH)/global-%: ./src/global/%.c $(OBJECTS_GLOBAL) | $(BUILD_PATH)/ - $(CC) $^ ../bin/debug/libcdsb.a ../modules/libunic/bin/libunic.a -o $@ $(CFLAGS) -g3 -Wall + $(CC) $^ ../bin/debug/libcdsb.a -o $@ $(CFLAGS) -g3 -Wall ######################################################################################################################## diff --git a/tests/src/array/plug.h b/tests/src/array/plug.h index 0243a08..dbf0956 100644 --- a/tests/src/array/plug.h +++ b/tests/src/array/plug.h @@ -2,7 +2,7 @@ /* Copyright © 2022 Gregory Lirent */ #include -#include "../../../include/extra/vtype.h" +#include "../../../include/vtype.h" #include "../../../include/array.h" #include "../../include/random.h" diff --git a/tests/src/array/src/plug.c b/tests/src/array/src/plug.c index 0ed9a6b..4c9a95a 100644 --- a/tests/src/array/src/plug.c +++ b/tests/src/array/src/plug.c @@ -2,16 +2,14 @@ /* Copyright © 2022 Gregory Lirent */ #include -#include "../../../../include/extra/vtype.h" +#include "../../../../include/vtype.h" #include "../../../include/random.h" -vtype_string* string_duplicate(const vtype_string* x) { return 0; } vtype_list* list_duplicate (const vtype_list* x) { return 0; } vtype_map* map_duplicate (const vtype_map* x) { return 0; } vtype_set* vset_duplicate (const vtype_set* x) { return 0; } vtype_dict* dict_duplicate (const vtype_dict* x) { return 0; } -void string_free(vtype_string* x) {} void list_free (vtype_list* x) {} void map_free (vtype_map* x) {} void vset_free (vtype_set* x) {} @@ -29,7 +27,6 @@ hash_t map_hash (const vtype_map* s) { return 0; } hash_t vset_hash (const vtype_set* s) { return 0; } hash_t dict_hash (const vtype_dict* s) { return 0; } -void string_copy_init(vtype_string* x, const vtype_string* s) { memset(x, 0, sizeof(*x)); } void list_copy_init (vtype_list* x, const vtype_list* s) { memset(x, 0, sizeof(*x)); } void map_copy_init (vtype_map* x, const vtype_map* s) { memset(x, 0, sizeof(*x)); } void vset_copy_init (vtype_set* x, const vtype_set* s) { memset(x, 0, sizeof(*x)); } diff --git a/tests/src/array/src/random.c b/tests/src/array/src/random.c index 4dcc8b7..be9de57 100644 --- a/tests/src/array/src/random.c +++ b/tests/src/array/src/random.c @@ -31,7 +31,7 @@ void array_push_random(arr_t* x, _Bool silent, unsigned int hpos) { printf("\e[%dG\e[36mTry to push value to back of the array:\e[m\n", hpos+1); } - r = libcdsb_array_push(x, _.v.value, _.v.type) >= 0; + r = libcdsb_array_insert(x, _.v.value, _.v.type) >= 0; } else { ssize_t i = array_size(x); diff --git a/tests/src/dict/src/plug.c b/tests/src/dict/src/plug.c index bb5545a..24fc959 100644 --- a/tests/src/dict/src/plug.c +++ b/tests/src/dict/src/plug.c @@ -4,13 +4,11 @@ #include "../../../../src/__internal/include.h" #include "../../../include/random.h" -vtype_string* string_duplicate(const vtype_string* x) { return 0; } vtype_array* array_duplicate (const vtype_array* x) { return 0; } vtype_list* list_duplicate (const vtype_list* x) { return 0; } vtype_map* map_duplicate (const vtype_map* x) { return 0; } vtype_set* vset_duplicate (const vtype_set* x) { return 0; } -void string_free(vtype_string* x) {} void array_free (vtype_array* x) {} void list_free (vtype_list* x) {} void map_free (vtype_map* x) {} diff --git a/tests/src/global/plug.h b/tests/src/global/plug.h index b2dce62..97d1eda 100644 --- a/tests/src/global/plug.h +++ b/tests/src/global/plug.h @@ -1,7 +1,7 @@ /* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ -#include "../../../include/extra/string.h" +#include "../../../include/string.h" #include "../../../include/array.h" #include "../../../include/list.h" #include "../../../include/set.h" diff --git a/tests/src/global/src/random.c b/tests/src/global/src/random.c index df0de0f..cef5267 100644 --- a/tests/src/global/src/random.c +++ b/tests/src/global/src/random.c @@ -80,30 +80,34 @@ static arr_t random_array(bool embd) { size_t n = random_uint16()%((!embd)?MAX_ELEMENTS:100); value_t v = (!embd) ? random_value2() : real_random_value(1); - void (*callback)(void*); - - switch (v.type) { - default: callback = nullptr; break; - case VTYPE_STRING: callback = (void*)string_free; break; - case VTYPE_ARRAY: callback = (void*)array_free; break; - case VTYPE_LIST: callback = (void*)list_free; break; - case VTYPE_MAP: callback = (void*)map_free; break; - case VTYPE_SET: callback = (void*)vset_free; break; - case VTYPE_DICT: callback = (void*)dict_free; break; - } - array_init(&x, v.type); while(n--) { - libcdsb_array_push(&x, v.value, v.type); + libcdsb_array_insert(&x, v.value, v.type); - if (callback) callback(v.value); + switch (v.type) { + default: break; + case VTYPE_STRING: string_free((void*)v.value); break; + case VTYPE_ARRAY: array_free((void*)v.value); break; + case VTYPE_LIST: list_free((void*)v.value); break; + case VTYPE_MAP: map_free((void*)v.value); break; + case VTYPE_SET: vset_free((void*)v.value); break; + case VTYPE_DICT: dict_free((void*)v.value); break; + } v = random_value_by_type(v.type, 1); } - if (callback) callback(v.value); + switch (v.type) { + default: break; + case VTYPE_STRING: string_free((void*)v.value); break; + case VTYPE_ARRAY: array_free((void*)v.value); break; + case VTYPE_LIST: list_free((void*)v.value); break; + case VTYPE_MAP: map_free((void*)v.value); break; + case VTYPE_SET: vset_free((void*)v.value); break; + case VTYPE_DICT: dict_free((void*)v.value); break; + } return x; } @@ -113,30 +117,35 @@ static set_t random_set(bool embd) { size_t n = random_uint16()%((!embd)?MAX_ELEMENTS:100); value_t v = (!embd) ? random_value2() : real_random_value(1); - void (*callback)(void*); - - switch (v.type) { - default: callback = nullptr; break; - case VTYPE_STRING: callback = (void*)string_free; break; - case VTYPE_ARRAY: callback = (void*)array_free; break; - case VTYPE_LIST: callback = (void*)list_free; break; - case VTYPE_MAP: callback = (void*)map_free; break; - case VTYPE_SET: callback = (void*)vset_free; break; - case VTYPE_DICT: callback = (void*)dict_free; break; - } - vset_init(&x, v.type); while(n--) { libcdsb_vset_insert(&x, v.value, v.type); - if (callback) callback(v.value); + switch (v.type) { + default: break; + case VTYPE_STRING: string_free((void*)v.value); break; + case VTYPE_ARRAY: array_free((void*)v.value); break; + case VTYPE_LIST: list_free((void*)v.value); break; + case VTYPE_MAP: map_free((void*)v.value); break; + case VTYPE_SET: vset_free((void*)v.value); break; + case VTYPE_DICT: dict_free((void*)v.value); break; + } v = random_value_by_type(v.type, 1); } - if (callback) callback(v.value); + switch (v.type) { + default: break; + case VTYPE_STRING: string_free((void*)v.value); break; + case VTYPE_ARRAY: array_free((void*)v.value); break; + case VTYPE_LIST: list_free((void*)v.value); break; + case VTYPE_MAP: map_free((void*)v.value); break; + case VTYPE_SET: vset_free((void*)v.value); break; + case VTYPE_DICT: dict_free((void*)v.value); break; + } + return x; } @@ -149,7 +158,7 @@ static list_t random_list(bool embd) { while(n--) { v = (!embd) ? random_value2() : real_random_value(1); - libcdsb_list_update(&x, -1, v.value, v.type, 1); + libcdsb_list_insert(&x, -1, v.value, v.type, 1); switch (v.type) { default: break; @@ -170,18 +179,6 @@ static map_t random_map(bool embd) { size_t n = random_uint16()%((!embd)?MAX_ELEMENTS:100); value_t k = (!embd) ? random_value2() : real_random_value(1); - void (*callback)(void*); - - switch (k.type) { - default: callback = nullptr; break; - case VTYPE_STRING: callback = (void*)string_free; break; - case VTYPE_ARRAY: callback = (void*)array_free; break; - case VTYPE_LIST: callback = (void*)list_free; break; - case VTYPE_MAP: callback = (void*)map_free; break; - case VTYPE_SET: callback = (void*)vset_free; break; - case VTYPE_DICT: callback = (void*)dict_free; break; - } - map_init(&x, k.type); while(n--) { @@ -189,7 +186,15 @@ static map_t random_map(bool embd) { libcdsb_map_update(&x, k.value, k.type, v.value, v.type); - if (callback) callback(k.value); + switch (k.type) { + default: break; + case VTYPE_STRING: string_free((void*)k.value); break; + case VTYPE_ARRAY: array_free((void*)k.value); break; + case VTYPE_LIST: list_free((void*)k.value); break; + case VTYPE_MAP: map_free((void*)k.value); break; + case VTYPE_SET: vset_free((void*)k.value); break; + case VTYPE_DICT: dict_free((void*)k.value); break; + } switch (v.type) { default: break; @@ -204,7 +209,16 @@ static map_t random_map(bool embd) { k = random_value_by_type(k.type, 1); } - if (callback) callback(k.value); + switch (k.type) { + default: break; + case VTYPE_STRING: string_free((void*)k.value); break; + case VTYPE_ARRAY: array_free((void*)k.value); break; + case VTYPE_LIST: list_free((void*)k.value); break; + case VTYPE_MAP: map_free((void*)k.value); break; + case VTYPE_SET: vset_free((void*)k.value); break; + case VTYPE_DICT: dict_free((void*)k.value); break; + } + return x; } diff --git a/tests/src/list/src/plug.c b/tests/src/list/src/plug.c index 7a32c0e..6c79e8a 100644 --- a/tests/src/list/src/plug.c +++ b/tests/src/list/src/plug.c @@ -4,13 +4,11 @@ #include "../../../../src/__internal/include.h" #include "../../../include/random.h" -vtype_string* string_duplicate(const vtype_string* x) { return 0; } vtype_array* array_duplicate (const vtype_array* x) { return 0; } vtype_map* map_duplicate (const vtype_map* x) { return 0; } vtype_set* vset_duplicate (const vtype_set* x) { return 0; } vtype_dict* dict_duplicate (const vtype_dict* x) { return 0; } -void string_free(vtype_string* x) {} void array_free (vtype_array* x) {} void map_free (vtype_map* x) {} void vset_free (vtype_set* x) {} diff --git a/tests/src/list/src/random.c b/tests/src/list/src/random.c index 5a4a1a9..504c5ad 100644 --- a/tests/src/list/src/random.c +++ b/tests/src/list/src/random.c @@ -26,12 +26,12 @@ void list_push_random(list_t* x, _Bool silent, unsigned int hpos) { if (!silent) { printf("\e[%dG\e[36mTry to push value to back of the list:\e[m\n", hpos+1); } - r = libcdsb_list_update(x, -1, v.value, v.type, 1); + r = libcdsb_list_insert(x, -1, v.value, v.type, 1); } else if (random_boolean()) { if (!silent) { printf("\e[%dG\e[36mTry to push value to front of the list:\e[m\n", hpos+1); } - r = libcdsb_list_update(x, -1, v.value, v.type, 1); + r = libcdsb_list_insert(x, -1, v.value, v.type, 1); } else { ssize_t i = list_size(x); i = random_uint64()% (i ? i : 1); @@ -41,7 +41,7 @@ void list_push_random(list_t* x, _Bool silent, unsigned int hpos) { printf("\e[%dG\e[36mTry to change value with index \e[32;1m%ld\e[36m in the list:\e[m\n", hpos+1, i); } - r = libcdsb_list_update(x, i, v.value, v.type, 0); + r = libcdsb_list_insert(x, i, v.value, v.type, 0); } if (!silent) { diff --git a/tests/src/map/src/plug.c b/tests/src/map/src/plug.c index 2462c64..da3cbe2 100644 --- a/tests/src/map/src/plug.c +++ b/tests/src/map/src/plug.c @@ -4,13 +4,11 @@ #include "../../../../src/__internal/include.h" #include "../../../include/random.h" -vtype_string* string_duplicate(const vtype_string* x) { return 0; } vtype_array* array_duplicate (const vtype_array* x) { return 0; } vtype_list* list_duplicate (const vtype_list* x) { return 0; } vtype_set* vset_duplicate (const vtype_set* x) { return 0; } vtype_dict* dict_duplicate (const vtype_dict* x) { return 0; } -void string_free(vtype_string* x) {} void array_free (vtype_array* x) {} void list_free (vtype_list* x) {} void vset_free (vtype_set* x) {} diff --git a/tests/src/set/src/plug.c b/tests/src/set/src/plug.c index 6dc338a..86d9620 100644 --- a/tests/src/set/src/plug.c +++ b/tests/src/set/src/plug.c @@ -4,13 +4,11 @@ #include "../../../../src/__internal/include.h" #include "../../../include/random.h" -vtype_string* string_duplicate(const vtype_string* x) { return 0; } vtype_array* array_duplicate (const vtype_array* x) { return 0; } vtype_list* list_duplicate (const vtype_list* x) { return 0; } vtype_map* map_duplicate (const vtype_map* x) { return 0; } vtype_dict* dict_duplicate (const vtype_dict* x) { return 0; } -void string_free(vtype_string* x) {} void array_free (vtype_array* x) {} void list_free (vtype_list* x) {} void map_free (vtype_map* x) {} From 6412adbc9f38a3eea63d02511f5f7a0331bc057f Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Wed, 24 Aug 2022 12:44:11 +0300 Subject: [PATCH 18/18] Rename --- src/{extra.c => cstring.c} | 0 src/{extra-memory.c => memory.c} | 0 src/{extra-stack.c => stack.c} | 0 src/{vtype-extra.c => stringify.c} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/{extra.c => cstring.c} (100%) rename src/{extra-memory.c => memory.c} (100%) rename src/{extra-stack.c => stack.c} (100%) rename src/{vtype-extra.c => stringify.c} (100%) diff --git a/src/extra.c b/src/cstring.c similarity index 100% rename from src/extra.c rename to src/cstring.c diff --git a/src/extra-memory.c b/src/memory.c similarity index 100% rename from src/extra-memory.c rename to src/memory.c diff --git a/src/extra-stack.c b/src/stack.c similarity index 100% rename from src/extra-stack.c rename to src/stack.c diff --git a/src/vtype-extra.c b/src/stringify.c similarity index 100% rename from src/vtype-extra.c rename to src/stringify.c