Compare commits

..

No commits in common. "master" and "v0.1.0-beta" have entirely different histories.

144 changed files with 3847 additions and 6193 deletions

View File

@ -34,8 +34,7 @@ OBJECTS = $(call c_objects,./src/,)\
$(call c_objects,./src/array/,array-)\ $(call c_objects,./src/array/,array-)\
$(call c_objects,./src/list/,list-)\ $(call c_objects,./src/list/,list-)\
$(call c_objects,./src/map/,map-)\ $(call c_objects,./src/map/,map-)\
$(call c_objects,./src/set/,set-)\ $(call c_objects,./src/set/,set-)
$(call c_objects,./src/dict/,dict-)
######################################################################################################################## ########################################################################################################################
@ -54,8 +53,6 @@ $(DEBUG_PATH)/obj/map-%.o: ./src/map/%.c | $(DEBUG_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS) $(CC) $^ -o $@ $(CFLAGS)
$(DEBUG_PATH)/obj/set-%.o: ./src/set/%.c | $(DEBUG_PATH)/obj/ $(DEBUG_PATH)/obj/set-%.o: ./src/set/%.c | $(DEBUG_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS) $(CC) $^ -o $@ $(CFLAGS)
$(DEBUG_PATH)/obj/dict-%.o: ./src/dict/%.c | $(DEBUG_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(DEBUG_PATH)/obj/%.o: ./src/%.c | $(DEBUG_PATH)/obj/ $(DEBUG_PATH)/obj/%.o: ./src/%.c | $(DEBUG_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS) $(CC) $^ -o $@ $(CFLAGS)
@ -71,8 +68,6 @@ $(RELEASE_PATH)/obj/map-%.o: ./src/map/%.c | $(RELEASE_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS) $(CC) $^ -o $@ $(CFLAGS)
$(RELEASE_PATH)/obj/set-%.o: ./src/set/%.c | $(RELEASE_PATH)/obj/ $(RELEASE_PATH)/obj/set-%.o: ./src/set/%.c | $(RELEASE_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS) $(CC) $^ -o $@ $(CFLAGS)
$(RELEASE_PATH)/obj/dict-%.o: ./src/dict/%.c | $(RELEASE_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS)
$(RELEASE_PATH)/obj/%.o: ./src/%.c | $(RELEASE_PATH)/obj/ $(RELEASE_PATH)/obj/%.o: ./src/%.c | $(RELEASE_PATH)/obj/
$(CC) $^ -o $@ $(CFLAGS) $(CC) $^ -o $@ $(CFLAGS)

View File

@ -1,40 +0,0 @@
# This software is licensed by the MIT License, see LICENSE file
# Copyright © 2022 Gregory Lirent
########################################################################################################################
BUILD_PATH ?= ./bin
########################################################################################################################
CC = clang
MKDIR = mkdir -p
RMRF = rm -rf
AR = ar crs
CP = cp
########################################################################################################################
examples: modules
examples: $(addprefix $(BUILD_PATH)/,$(notdir $(basename $(wildcard ./*.c))))
$(BUILD_PATH)/%: ./%.c | $(BUILD_PATH)/
$(CC) $^ ../bin/release/libcdsb.a ../modules/libunic/bin/libunic.a -o $@ $(CFLAGS) -O2 -Wall
$(BUILD_PATH)/:
$(MKDIR) $@
$(BUILD_PATH)/obj/: | $(BUILD_PATH)/
$(MKDIR) $@
clean:
$(RMRF) ./bin/
cd ../ && $(MAKE) clean
########################################################################################################################
FORCE:
modules: ../bin/release/libcdsb.a
../bin/release/libcdsb.a: FORCE
cd ../ && $(MAKE) release

View File

@ -1,37 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <assert.h>
#include <stdio.h>
#include "../include/array.h"
typedef vtype_array arr_t;
int print_value(void* value, ssize_t index, vtype type, void* data) {
const char *n = data;
vtype_int32 *v = value;
assert(type == VTYPE_INT32);
printf("%s %d (index: %ld)\n", n, *v, index);
return 0;
}
int main(int argc, char** argv) {
arr_t arr;
array_init(&arr, VTYPE_INT32);
for (size_t i = 0; i < 28; ++i) {
array_push_back(&arr, i);
}
array_get_by_index(&arr, 13, "Get value:", print_value);
array_pop_by_index(&arr, 18, "Pop value:", print_value);
array_foreach(&arr, "Foreach loop:", print_value);
array_free(&arr);
}

View File

@ -1,66 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "../include/dict.h"
typedef vtype_dict dict_t;
int print_value(const void* key, vtype key_type, void* value, vtype value_type, void* data) {
const char *n = data;
switch (key_type) {
default: abort();
case VTYPE_INT32:
printf("%s %d: ", n, *(vtype_int32*)key);
break;
case VTYPE_FLOAT:
printf("%s %f: ", n, *(vtype_float*)key);
break;
}
switch (value_type) {
default: abort();
case VTYPE_INT32:
printf("%d\n", *(vtype_int32*)value);
break;
case VTYPE_FLOAT:
printf("%f\n", *(vtype_float*)value);
break;
}
return 0;
}
int main(int argc, char** argv) {
dict_t dict;
vtype_float fl = 0.0;
int a;
vtype_float b;
dict_init(&dict);
for (vtype_int32 i = 0; i < 28; ++i) {
if (i%2) {
dict_update(&dict, fl, i);
} else {
dict_update(&dict, i, fl);
}
fl += 0.05;
}
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);
dict_free(&dict);
}

View File

@ -1,51 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stdio.h>
#include <stdlib.h>
#include "../include/list.h"
typedef vtype_list list_t;
int print_value(void* value, ssize_t index, vtype type, void* data) {
const char *n = data;
switch (type) {
default: abort();
case VTYPE_INT32:
printf("%s %d (index: %ld)\n", n, *(vtype_int32*)value, index);
break;
case VTYPE_FLOAT:
printf("%s %f (index: %ld)\n", n, *(vtype_float*)value, index);
break;
}
return 0;
}
int main(int argc, char** argv) {
list_t list;
vtype_float fl = 0.0;
list_init(&list);
for (vtype_int32 i = 0; i < 28; ++i) {
if (i%2) {
list_push_back(&list, i);
} else {
list_push_back(&list, fl);
fl += 0.05;
}
}
list_get_by_index(&list, 13, "Get value:", print_value);
list_pop_by_index(&list, 18, "Pop value:", print_value);
list_foreach(&list, "Foreach loop:", print_value);
list_free(&list);
}

View File

@ -1,59 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "../include/map.h"
typedef vtype_map map_t;
int print_value(const void* key, vtype key_type, void* value, vtype value_type, void* data) {
const char *n = data;
vtype_int32 *k = (void*)key;
assert(key_type == VTYPE_INT32);
printf("%s %d: ", n, *k);
switch (value_type) {
default: abort();
case VTYPE_INT32:
printf("%d\n", *(vtype_int32*)value);
break;
case VTYPE_FLOAT:
printf("%f\n", *(vtype_float*)value);
break;
}
return 0;
}
int main(int argc, char** argv) {
map_t map;
vtype_float fl = 0.0;
int a, b;
map_init(&map, VTYPE_INT32);
for (vtype_int32 i = 0; i < 28; ++i) {
if (i%2) {
map_update(&map, i, i);
} else {
map_update(&map, i, fl);
fl += 0.05;
}
}
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);
map_free(&map);
}

View File

@ -1,42 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <assert.h>
#include <stdio.h>
#include "../include/set.h"
typedef vtype_set vset_t;
int print_value(const void* value, vtype type, void* data) {
const char *n = data;
vtype_int32 *v = (void*)value;
assert(type == VTYPE_INT32);
printf("%s %d\n", n, *v);
return 0;
}
int main(int argc, char** argv) {
vset_t set;
int a, b;
vset_init(&set, VTYPE_INT32);
for (size_t i = 0; i < 28; ++i) {
vset_push(&set, i);
}
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);
vset_free(&set);
}

View File

@ -1,42 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stdio.h>
#include "../include/array.h"
#include "../include/string.h"
typedef vtype_string str_t;
typedef vtype_array arr_t;
int main(int argc, char** argv) {
str_t str;
string_init(&str, "sed ut perspiciatis");
string_concat(&str, ", Unde omnis iste natus error sit voluptatem accusantium doloremque laudantium");
string_concat(&str, ", Totam rem aperiam eaque ipsa");
string_concat(&str, ", Quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt");
string_concat(&str, ", Explicabo.");
string_capitalize(&str);
string_reverse(&str);
printf("%s\n", str.buffer);
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 = at_array(&parts, i);
string_trim(value, 0);
printf("%s (%lu)\n", value->buffer, string_nmemb(value));
}
array_free(&parts);
string_free(&str);
}

23
include/__attributes.h Normal file
View File

@ -0,0 +1,23 @@
/* 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
#define LIBCDSB_nt__ __attribute__ ((nothrow))
#define LIBCDSB_nn1__ __attribute__ ((nonnull (1)))
#define LIBCDSB_nn2__ __attribute__ ((nonnull (2)))
#define LIBCDSB_nn12__ __attribute__ ((nonnull (1,2)))
#define LIBCDSB_nn123__ __attribute__ ((nonnull (1,2,3)))
#define LIBCDSB_nn124__ __attribute__ ((nonnull (1,2,4)))
#define LIBCDSB_nn13__ __attribute__ ((nonnull (1,3)))
#define LIBCDSB_nn23__ __attribute__ ((nonnull (2,3)))
#define LIBCDSB_nn23__ __attribute__ ((nonnull (2,3)))
#define LIBCDSB_pure__ LIBCDSB_nt__ __attribute__ ((pure))
#define LIBCDSB_wur__ __attribute__ ((warn_unused_result))
#define LIBCDSB_cmpattr__ LIBCDSB_pure__ LIBCDSB_nn12__
#define LIBCDSB_cpyattr__ LIBCDSB_pure__ LIBCDSB_wur__ LIBCDSB_nn1__
#define LIBCDSB_dupattr__ LIBCDSB_wur__ LIBCDSB_nn1__
#endif /* LIBCDSB_CORE_ATTRIBUTES_H */

90
include/__generics.h Normal file
View File

@ -0,0 +1,90 @@
/* 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 _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_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_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_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)\
)
#define _LIBCDSB_GenericP(T, f, v) _Generic((v),\
void**: T ## _ ## f ## _pointers, const void**: T ## _ ## f ## _pointers,\
STRING_VIEW*: T ## _ ## f ## _strings, const STRING_VIEW*: T ## _ ## f ## _strings,\
ARRAY*: T ## _ ## f ## _arrays, const ARRAY*: T ## _ ## f ## _arrays,\
LIST*: T ## _ ## f ## _lists, const LIST*: T ## _ ## f ## _lists,\
MAP*: T ## _ ## f ## _maps, const MAP*: T ## _ ## f ## _maps,\
VSET*: T ## _ ## f ## _vsets, const VSET*: T ## _ ## f ## _vsets,\
vtype_bool*: T ## _ ## f ## _booleans, const vtype_bool*: T ## _ ## f ## _booleans,\
vtype_uint8*: T ## _ ## f ## _uint8s, const vtype_uint8*: T ## _ ## f ## _uint8s,\
vtype_uint16*: T ## _ ## f ## _uint16s, const vtype_uint16*: T ## _ ## f ## _uint16s,\
vtype_uint32*: T ## _ ## f ## _uint32s, const vtype_uint32*: T ## _ ## f ## _uint32s,\
vtype_uint64*: T ## _ ## f ## _uint64s, const vtype_uint64*: T ## _ ## f ## _uint64s,\
vtype_int8*: T ## _ ## f ## _int8s, const vtype_int8*: T ## _ ## f ## _int8s,\
vtype_int16*: T ## _ ## f ## _int16s, const vtype_int16*: T ## _ ## f ## _int16s,\
vtype_int32*: T ## _ ## f ## _int32s, const vtype_int32*: T ## _ ## f ## _int32s,\
vtype_int64*: T ## _ ## f ## _int64s, const vtype_int64*: T ## _ ## f ## _int64s,\
vtype_float*: T ## _ ## f ## _floats, const vtype_float*: T ## _ ## f ## _floats,\
vtype_double*: T ## _ ## f ## _doubles, const vtype_double*: T ## _ ## f ## _doubles,\
vtype_ldouble*: T ## _ ## f ## _ldoubles, const vtype_ldouble*: T ## _ ## f ## _ldoubles\
)
#endif /* LIBCDSB_CORE_GENERICS_H */

View File

@ -1,50 +1,93 @@
/* This software is licensed by the MIT License, see LICENSE file */ /* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "bits/__generics.h" #include "__generics.h"
#include "vtype.h" #include "vtype.h"
#ifndef LIBCDSB_ARRAY_H #ifndef LIBCDSB_ARRAY_H
#define LIBCDSB_ARRAY_H #define LIBCDSB_ARRAY_H
/*#####################################################################################################################*/
typedef int (*array_access_callback)(void* value, ssize_t index, vtype type, void* data); typedef int (*array_access_callback)(void* value, ssize_t index, vtype type, void* data);
/*#####################################################################################################################*/ extern void array_init(vtype_array* x, vtype type) LIBCDSB_nt__ LIBCDSB_nn1__;
inline void array_init (vtype_array* x, vtype type) Always_inline__ Nonnull__(1); extern void* array_at(const vtype_array* s, ssize_t index) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t array_slice (vtype_array* x, vtype_array* src, ssize_t index, size_t count, bool cut) Nonnull__(1); extern size_t array_slice(vtype_array* x, vtype_array* src, ssize_t index, size_t count, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
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); extern void array_sort (vtype_array* x) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void array_reverse(vtype_array* x) LIBCDSB_nt__ LIBCDSB_nn1__;
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_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 list_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)
/*#####################################################################################################################*/ /*#####################################################################################################################*/
#define array_pop(x, value, data, callback) libcdsb_array_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0, 1) extern void libcdsb_array_push_pointer(vtype_array* x, const void* value) LIBCDSB_nt__ LIBCDSB_nn1__;
#define array_get array_find extern void libcdsb_array_push_cstring(vtype_array* x, const char* value) LIBCDSB_nt__ LIBCDSB_nn1__;
#define array_pop_by_index(x, index, data, callback) libcdsb_array_get (x, index, data, callback, 1) extern void libcdsb_array_push_string (vtype_array* x, const vtype_string* value) LIBCDSB_nt__ LIBCDSB_nn12__;
#define array_get_by_index(x, index, data, callback) libcdsb_array_get (x, index, data, callback, 0) extern void libcdsb_array_push_array (vtype_array* x, const vtype_array* value) LIBCDSB_nt__ LIBCDSB_nn12__;
#define array_find(x, value, data, callback) libcdsb_array_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0, 0) extern void libcdsb_array_push_list (vtype_array* x, const vtype_list* value) LIBCDSB_nt__ LIBCDSB_nn12__;
#define array_rfind(x, value, data, callback) libcdsb_array_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 1, 0) extern void libcdsb_array_push_map (vtype_array* x, const vtype_map* value) LIBCDSB_nt__ LIBCDSB_nn12__;
#define array_countof(x, value) libcdsb_array_count (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) extern void libcdsb_array_push_vset (vtype_array* x, const vtype_set* value) LIBCDSB_nt__ LIBCDSB_nn12__;
#define array_push_back(x, value) libcdsb_array_insert (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) extern void libcdsb_array_push_boolean(vtype_array* x, vtype_bool value) LIBCDSB_nt__ LIBCDSB_nn1__;
#define array_attach_back(x, value) libcdsb_array_attach (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) extern void libcdsb_array_push_uint8 (vtype_array* x, vtype_uint8 value) LIBCDSB_nt__ LIBCDSB_nn1__;
#define array_foreach(x, data, callback) libcdsb_array_foreach(x, data, callback, 0) extern void libcdsb_array_push_uint16 (vtype_array* x, vtype_uint16 value) LIBCDSB_nt__ LIBCDSB_nn1__;
#define array_remove(x, value) array_pop (x, value, 0, 0) extern void libcdsb_array_push_uint32 (vtype_array* x, vtype_uint32 value) LIBCDSB_nt__ LIBCDSB_nn1__;
#define array_remove_by_index(x, index) array_pop_by_index (x, index, 0, 0) extern void libcdsb_array_push_uint64 (vtype_array* x, vtype_uint64 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_int8 (vtype_array* x, vtype_int8 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_int16 (vtype_array* x, vtype_int16 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_int32 (vtype_array* x, vtype_int32 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_int64 (vtype_array* x, vtype_int64 value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_float (vtype_array* x, vtype_float value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_double (vtype_array* x, vtype_double value) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_array_push_ldouble(vtype_array* x, vtype_ldouble value) LIBCDSB_nt__ LIBCDSB_nn1__;
#define in_array(x, value) (array_get(x, value, 0, 0) == 0) extern size_t libcdsb_array_count_pointer(const vtype_array* s, const void* value);
extern size_t libcdsb_array_count_cstring(const vtype_array* s, const char* value);
extern size_t libcdsb_array_count_string (const vtype_array* s, const vtype_string* value);
extern size_t libcdsb_array_count_array (const vtype_array* s, const vtype_array* value);
extern size_t libcdsb_array_count_list (const vtype_array* s, const vtype_list* value);
extern size_t libcdsb_array_count_map (const vtype_array* s, const vtype_map* value);
extern size_t libcdsb_array_count_vset (const vtype_array* s, const vtype_set* value);
extern size_t libcdsb_array_count_boolean(const vtype_array* s, vtype_bool value);
extern size_t libcdsb_array_count_int8 (const vtype_array* s, vtype_int8 value);
extern size_t libcdsb_array_count_int16 (const vtype_array* s, vtype_int16 value);
extern size_t libcdsb_array_count_int32 (const vtype_array* s, vtype_int32 value);
extern size_t libcdsb_array_count_int64 (const vtype_array* s, vtype_int64 value);
extern size_t libcdsb_array_count_uint8 (const vtype_array* s, vtype_uint8 value);
extern size_t libcdsb_array_count_uint16 (const vtype_array* s, vtype_uint16 value);
extern size_t libcdsb_array_count_uint32 (const vtype_array* s, vtype_uint32 value);
extern size_t libcdsb_array_count_uint64 (const vtype_array* s, vtype_uint64 value);
extern size_t libcdsb_array_count_float (const vtype_array* s, vtype_float value);
extern size_t libcdsb_array_count_double (const vtype_array* s, vtype_double value);
extern size_t libcdsb_array_count_ldouble(const vtype_array* s, vtype_ldouble value);
/*#####################################################################################################################*/ extern int libcdsb_array_find_pointer(vtype_array* x, const void* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_string (vtype_array* x, const char* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
extern ssize_t libcdsb_array_insert (vtype_array* x, const void* value, vtype type) Nonnull__(1); extern int libcdsb_array_find_array (vtype_array* x, const vtype_string* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
extern ssize_t libcdsb_array_attach (vtype_array* x, const void* value, vtype type) Nonnull__(1); extern int libcdsb_array_find_list (vtype_array* x, const vtype_array* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
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_find_map (vtype_array* x, const vtype_list* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
extern int libcdsb_array_get (vtype_array* x, ssize_t index, void* data, array_access_callback, bool cut) Nonnull__(1); extern int libcdsb_array_find_vset (vtype_array* x, const vtype_map* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
extern int libcdsb_array_foreach (vtype_array* x, void* data, array_access_callback, bool flush) Nonnull__(1,3); extern int libcdsb_array_find_cstring(vtype_array* x, const vtype_set* value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_boolean(vtype_array* x, vtype_bool value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
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_uint8 (vtype_array* x, vtype_uint8 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_uint16 (vtype_array* x, vtype_uint16 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_uint32 (vtype_array* x, vtype_uint32 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_uint64 (vtype_array* x, vtype_uint64 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_int8 (vtype_array* x, vtype_int8 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_int16 (vtype_array* x, vtype_int16 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_int32 (vtype_array* x, vtype_int32 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_int64 (vtype_array* x, vtype_int64 value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_float (vtype_array* x, vtype_float value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_double (vtype_array* x, vtype_double value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find_ldouble(vtype_array* x, vtype_ldouble value, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
#endif /* LIBCDSB_ARRAY_H */ #endif /* LIBCDSB_ARRAY_H */

View File

@ -1,12 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#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_BITS_ATTRIBUTES_H */

View File

@ -1,51 +0,0 @@
/* 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 */

View File

@ -1,20 +0,0 @@
/* 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 */

View File

@ -1,19 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <string.h>
#include "__attributes.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);
extern char* libcdsb_strdup (const char* s) Warn_unused_result__ Nonnull__(1);
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);
#endif /* LIBCDSB_BITS_CSTRING_H */

View File

@ -1,40 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stddef.h>
#include "__attributes.h"
#ifndef LIBCDSB_BITS_MEMORY_H
#define LIBCDSB_BITS_MEMORY_H
typedef struct libcdsb_stack_node {
struct libcdsb_stack_node* prev;
void* value;
} stack_t;
typedef struct libcdsb_queue {
struct libcdsb_stack_node* back;
struct libcdsb_stack_node* front;
} queue_t;
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_queue_init (queue_t* queue) Nonnull__(1);
extern void libcdsb_queue_push (queue_t* queue, void* value) Nonnull__(1);
extern void libcdsb_queue_push_many(queue_t* queue, size_t n, ...) Nonnull__(1);
extern void* libcdsb_queue_pop (queue_t* queue) Nonnull__(1);
extern void libcdsb_queue_flush (queue_t* queue) Nonnull__(1);
extern void* libcdsb_aalloc (size_t a, size_t n) Warn_unused_result__;
extern void* libcdsb_malloc (size_t n) Warn_unused_result__;
extern void* libcdsb_calloc (size_t n, size_t c) Warn_unused_result__;
extern void* libcdsb_realloc(void *p, size_t n) Warn_unused_result__;
extern void libcdsb_free(void* s);
#endif /* LIBCDSB_BITS_MEMORY_H */

View File

@ -1,37 +0,0 @@
/* 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
#define LIBCDSB_DICT_H
typedef int (*dict_access_callback)(const void* key, vtype key_type, void* value, vtype value_type, void* data);
/*#####################################################################################################################*/
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); }
/*#####################################################################################################################*/
#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), 0, 0)
#define dict_inject(x, key, value) libcdsb_dict_inject (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), 0, 0)
#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 bool libcdsb_dict_update (vtype_dict* x, const void* key, vtype key_type, const void* value, vtype value_type, void* data, dict_access_callback) Nonnull__(1);
extern bool libcdsb_dict_inject (vtype_dict* x, const void* key, vtype key_type, const void* value, vtype value_type, void* data, dict_access_callback) 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 */

23
include/extra/array.h Normal file
View File

@ -0,0 +1,23 @@
/* 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) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t libcdsb_array_count(const vtype_array* s, const void* value, vtype type) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_find (vtype_array* x, const void* value, vtype type, void* data, array_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_get (vtype_array* x, ssize_t index, void* data, array_access_callback, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_array_foreach(vtype_array* x, void* data, array_access_callback, bool flush) LIBCDSB_nt__ LIBCDSB_nn13__;
#endif /* LIBCDSB_EXTRA_ARRAY_H */

24
include/extra/cstring.h Normal file
View File

@ -0,0 +1,24 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <string.h>
#include "../__attributes.h"
#ifndef LIBCDSB_EXTRA_CSTRING_H
#define LIBCDSB_EXTRA_CSTRING_H
extern size_t libcdsb_strlen (const char* s) LIBCDSB_pure__ LIBCDSB_nn1__;
extern size_t libcdsb_strasciilen(const char* s) LIBCDSB_pure__ LIBCDSB_nn1__;
extern char* libcdsb_strdup (const char* s) LIBCDSB_nt__ LIBCDSB_wur__ LIBCDSB_nn1__;
extern char* libcdsb_strndup(const char* s, size_t n) LIBCDSB_nt__ LIBCDSB_wur__ LIBCDSB_nn1__;
extern void* libcdsb_memndup(const void* m, size_t n) LIBCDSB_nt__ LIBCDSB_wur__ LIBCDSB_nn1__;
#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 */

23
include/extra/list.h Normal file
View File

@ -0,0 +1,23 @@
/* 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) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t libcdsb_list_count(const vtype_list* s, const void* value, vtype type) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_list_find (vtype_list* x, const void* value, vtype type, void* data, list_access_callback, bool reverse, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_list_get (vtype_list* x, ssize_t index, void* data, list_access_callback, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_list_foreach(vtype_list* x, void* data, list_access_callback, bool flush) LIBCDSB_nt__ LIBCDSB_nn13__;
#endif /* LIBCDSB_EXTRA_LIST_H */

43
include/extra/map.h Normal file
View File

@ -0,0 +1,43 @@
/* 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* k, vtype kt, const void* v, vtype vt) LIBCDSB_nt__ LIBCDSB_nn124__;
extern int libcdsb_map_find (vtype_map* x, const void* key, vtype key_type, void* data, map_access_callback, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_map_foreach(vtype_map* x, void* data, map_access_callback, bool flush) LIBCDSB_nt__ LIBCDSB_nn13__;
#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 */

35
include/extra/memory.h Normal file
View File

@ -0,0 +1,35 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stddef.h>
#include "../__attributes.h"
#ifndef LIBCDSB_EXTRA_MEMORY_H
#define LIBCDSB_EXTRA_MEMORY_H
typedef struct libcdsb_stack_node {
struct libcdsb_stack_node* prev;
void* value;
} stack_t;
extern void libcdsb_stack_init (stack_t* stack);
extern void libcdsb_stack_push (stack_t* stack, void* value);
extern void* libcdsb_stack_pop (stack_t* stack);
extern void libcdsb_stack_flush(stack_t* stack);
extern void* libcdsb_aalloc (size_t a, size_t n) LIBCDSB_nt__ LIBCDSB_wur__;
extern void* libcdsb_malloc (size_t n) LIBCDSB_nt__ LIBCDSB_wur__;
extern void* libcdsb_calloc (size_t n, size_t c) LIBCDSB_nt__ LIBCDSB_wur__;
extern void* libcdsb_realloc(void *p, size_t n) LIBCDSB_nt__ LIBCDSB_wur__;
#define aligned_alloc libcdsb_aalloc
#define malloc libcdsb_malloc
#define calloc libcdsb_calloc
#define realloc libcdsb_realloc
#define stack_init libcdsb_stack_init
#define stack_push libcdsb_stack_push
#define stack_pop libcdsb_stack_pop
#define stack_flush libcdsb_stack_flush
#endif /* LIBCDSB_EXTRA_MEMORY_H */

16
include/extra/set.h Normal file
View File

@ -0,0 +1,16 @@
/* 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) LIBCDSB_nt__ LIBCDSB_nn12__;
extern int libcdsb_vset_find (vtype_set* x, const void* value, vtype type, void* data, vset_access_callback, bool cut) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int libcdsb_vset_foreach(vtype_set* x, void* data, vset_access_callback, bool flush) LIBCDSB_nt__ LIBCDSB_nn13__;
#endif /* LIBCDSB_EXTRA_SET_H */

84
include/extra/string.h Normal file
View File

@ -0,0 +1,84 @@
/* 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(x, sep, maxn) _LIBCDSB_GenericS(libcdsb_string, split, sep)(x, 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) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t string_to_upper (vtype_string* x) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t string_capitalize(vtype_string* x) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t string_reverse (vtype_string* x) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t string_align_center(vtype_string* x, size_t padsize, int padchr) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t string_align_right (vtype_string* x, size_t padsize, int padchr) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t string_align_left (vtype_string* x, size_t padsize, int padchr) LIBCDSB_nt__ LIBCDSB_nn1__;
extern int string_compare_case_insensitive(const vtype_string* s0, const vtype_string* s1) LIBCDSB_cmpattr__;
extern void libcdsb_string_replace(vtype_string* x, char* dest, size_t dest_nmemb, const char* src, size_t nmemb);
/*#####################################################################################################################*/
inline vtype_array libcdsb_string_split_string (const vtype_string* x, const vtype_string* sep, size_t maxn) __attribute__((always_inline));
extern vtype_array libcdsb_string_split_cstring(const vtype_string* string, const char* sep, size_t maxn) LIBCDSB_nt__ LIBCDSB_nn1__;
extern vtype_array libcdsb_string_split_char (const vtype_string* string, int chr, size_t maxn) LIBCDSB_nt__ LIBCDSB_nn1__;
inline void libcdsb_string_trim_string (vtype_string* x, const vtype_string* s, int direction) __attribute__((always_inline));
extern void libcdsb_string_trim_cstring(vtype_string* x, const char* s, int direction) LIBCDSB_nt__ LIBCDSB_nn1__;
extern void libcdsb_string_trim_char (vtype_string* x, int sc, int direction) LIBCDSB_nt__ LIBCDSB_nn1__;
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) __attribute__((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) __attribute__((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) __attribute__((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) __attribute__((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) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t libcdsb_string_replace_r_cstring_char (vtype_string*restrict x, const char*restrict src, int dest, size_t maxn) LIBCDSB_nt__ LIBCDSB_nn1__;
inline size_t libcdsb_string_replace_r_char_string (vtype_string*restrict x, int src, const vtype_string*restrict dest, size_t maxn) __attribute__((always_inline));
extern size_t libcdsb_string_replace_r_char_cstring (vtype_string*restrict x, int src, const char*restrict dest, size_t maxn) LIBCDSB_nt__ LIBCDSB_nn1__;
#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 */

14
include/extra/vtype.h Normal file
View File

@ -0,0 +1,14 @@
/* 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 size_t LIBCDSB_VTYPE_SIZES[18];
extern const char* libcdsb_vtype_name(vtype t);
extern const char* libcdsb_vtype_stringify(const void* value, vtype t);
#endif /* LIBCDSB_EXTRA_VTYPE_H */

View File

@ -1,53 +1,96 @@
/* This software is licensed by the MIT License, see LICENSE file */ /* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "bits/__generics.h" #include "__generics.h"
#include "vtype.h" #include "vtype.h"
#ifndef LIBCDSB_LIST_H #ifndef LIBCDSB_LIST_H
#define LIBCDSB_LIST_H #define LIBCDSB_LIST_H
/*#####################################################################################################################*/
typedef int (*list_access_callback)(void* value, ssize_t index, vtype type, void* data); typedef int (*list_access_callback)(void* value, ssize_t index, vtype type, void* data);
/*#####################################################################################################################*/ extern void list_init(vtype_list* x);
extern void list_extend(vtype_list* x, const vtype_list* s);
inline void list_init (vtype_list* x) Always_inline__ Nonnull__(1); extern size_t list_slice(vtype_list* x, vtype_list* src, ssize_t index, size_t count, _Bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
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; } extern void list_sort(vtype_list* x);
extern void list_reverse(vtype_list* x);
#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) extern int libcdsb_list_find_pointer(vtype_list* x, const void* value, void* data, list_access_callback, bool reverse, bool cut);
#define list_get list_find extern int libcdsb_list_find_cstring(vtype_list* x, const char* value, void* data, list_access_callback, bool reverse, bool cut);
#define list_pop_by_index(x, index, data, callback) libcdsb_list_get (x, index, data, callback, 1) extern int libcdsb_list_find_string (vtype_list* x, const vtype_string* value, void* data, list_access_callback, bool reverse, bool cut);
#define list_get_by_index(x, index, data, callback) libcdsb_list_get (x, index, data, callback, 0) extern int libcdsb_list_find_array (vtype_list* x, const vtype_array* value, void* data, list_access_callback, bool reverse, bool cut);
#define list_find(x, value, data, callback) libcdsb_list_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0, 0) extern int libcdsb_list_find_list (vtype_list* x, const vtype_list* value, void* data, list_access_callback, bool reverse, bool cut);
#define list_rfind(x, value, data, callback) libcdsb_list_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 1, 0) extern int libcdsb_list_find_map (vtype_list* x, const vtype_map* value, void* data, list_access_callback, bool reverse, bool cut);
#define list_countof(x, value) libcdsb_list_count (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) extern int libcdsb_list_find_vset (vtype_list* x, const vtype_set* value, void* data, list_access_callback, bool reverse, bool cut);
#define list_insert(x, index, value) libcdsb_list_insert (x, index, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), -1, 0, 0) extern int libcdsb_list_find_boolean(vtype_list* x, vtype_bool value, void* data, list_access_callback, bool reverse, bool cut);
#define list_replace(x, index, value) libcdsb_list_insert (x, index, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), 0, 0, 0) extern int libcdsb_list_find_int8 (vtype_list* x, vtype_int8 value, void* data, list_access_callback, bool reverse, bool cut);
#define list_push_back(x, value) libcdsb_list_insert (x, -1, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), 1, 0, 0) extern int libcdsb_list_find_int16 (vtype_list* x, vtype_int16 value, void* data, list_access_callback, bool reverse, bool cut);
#define list_push_front(x, value) libcdsb_list_insert (x, 0, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), -1, 0, 0) extern int libcdsb_list_find_int32 (vtype_list* x, vtype_int32 value, void* data, list_access_callback, bool reverse, bool cut);
#define list_attach_back(x, value) libcdsb_list_attach (x, -1, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), 1, 0, 0) extern int libcdsb_list_find_int64 (vtype_list* x, vtype_int64 value, void* data, list_access_callback, bool reverse, bool cut);
#define list_attach_front(x, value) libcdsb_list_attach (x, 0, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), -1, 0, 0) extern int libcdsb_list_find_uint8 (vtype_list* x, vtype_uint8 value, void* data, list_access_callback, bool reverse, bool cut);
#define list_foreach(x, data, callback) libcdsb_list_foreach(x, data, callback, 0) extern int libcdsb_list_find_uint16 (vtype_list* x, vtype_uint16 value, void* data, list_access_callback, bool reverse, bool cut);
#define list_remove(x, value) list_pop (x, value, 0, 0) extern int libcdsb_list_find_uint32 (vtype_list* x, vtype_uint32 value, void* data, list_access_callback, bool reverse, bool cut);
#define list_remove_by_index(x, index) list_pop_by_index (x, index, 0, 0) extern int libcdsb_list_find_uint64 (vtype_list* x, vtype_uint64 value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_float (vtype_list* x, vtype_float value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_double (vtype_list* x, vtype_double value, void* data, list_access_callback, bool reverse, bool cut);
extern int libcdsb_list_find_ldouble(vtype_list* x, vtype_ldouble value, void* data, list_access_callback, bool reverse, bool cut);
#define in_list(x, value) (list_get(x, value, 0, 0) == 0) extern size_t libcdsb_list_count_pointer(const vtype_list* s, const void* value);
extern size_t libcdsb_list_count_cstring(const vtype_list* s, const char* value);
extern size_t libcdsb_list_count_string (const vtype_list* s, const vtype_string* value);
extern size_t libcdsb_list_count_array (const vtype_list* s, const vtype_array* value);
extern size_t libcdsb_list_count_list (const vtype_list* s, const vtype_list* value);
extern size_t libcdsb_list_count_map (const vtype_list* s, const vtype_map* value);
extern size_t libcdsb_list_count_vset (const vtype_list* s, const vtype_set* value);
extern size_t libcdsb_list_count_boolean(const vtype_list* s, vtype_bool value);
extern size_t libcdsb_list_count_int8 (const vtype_list* s, vtype_int8 value);
extern size_t libcdsb_list_count_int16 (const vtype_list* s, vtype_int16 value);
extern size_t libcdsb_list_count_int32 (const vtype_list* s, vtype_int32 value);
extern size_t libcdsb_list_count_int64 (const vtype_list* s, vtype_int64 value);
extern size_t libcdsb_list_count_uint8 (const vtype_list* s, vtype_uint8 value);
extern size_t libcdsb_list_count_uint16 (const vtype_list* s, vtype_uint16 value);
extern size_t libcdsb_list_count_uint32 (const vtype_list* s, vtype_uint32 value);
extern size_t libcdsb_list_count_uint64 (const vtype_list* s, vtype_uint64 value);
extern size_t libcdsb_list_count_float (const vtype_list* s, vtype_float value);
extern size_t libcdsb_list_count_double (const vtype_list* s, vtype_double value);
extern size_t libcdsb_list_count_ldouble(const vtype_list* s, vtype_ldouble value);
/*#####################################################################################################################*/ extern bool libcdsb_list_update_pointer(vtype_list* x, ssize_t index, const void* value, int ins_direction);
extern bool libcdsb_list_update_cstring(vtype_list* x, ssize_t index, const char* value, int ins_direction);
extern bool libcdsb_list_insert (vtype_list* x, ssize_t index, const void* value, vtype type, int ins_direction, void* data, list_access_callback) Nonnull__(1); extern bool libcdsb_list_update_string (vtype_list* x, ssize_t index, const vtype_string* value, int ins_direction);
extern bool libcdsb_list_attach (vtype_list* x, ssize_t index, const void* value, vtype type, int ins_direction, void* data, list_access_callback) Nonnull__(1); extern bool libcdsb_list_update_array (vtype_list* x, ssize_t index, const vtype_array* value, int ins_direction);
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 bool libcdsb_list_update_list (vtype_list* x, ssize_t index, const vtype_list* value, int ins_direction);
extern int libcdsb_list_get (vtype_list* x, ssize_t index, void* data, list_access_callback, bool cut) Nonnull__(1); extern bool libcdsb_list_update_map (vtype_list* x, ssize_t index, const vtype_map* value, int ins_direction);
extern int libcdsb_list_foreach (vtype_list* x, void* data, list_access_callback, bool flush) Nonnull__(1,3); extern bool libcdsb_list_update_vset (vtype_list* x, ssize_t index, const vtype_set* value, int ins_direction);
extern bool libcdsb_list_update_boolean(vtype_list* x, ssize_t index, vtype_bool value, int ins_direction);
extern size_t libcdsb_list_count(const vtype_list* s, const void* value, vtype type) Pure__ Warn_unused_result__ Nonnull__(1); extern bool libcdsb_list_update_int8 (vtype_list* x, ssize_t index, vtype_int8 value, int ins_direction);
extern bool libcdsb_list_update_int16 (vtype_list* x, ssize_t index, vtype_int16 value, int ins_direction);
extern bool libcdsb_list_update_int32 (vtype_list* x, ssize_t index, vtype_int32 value, int ins_direction);
extern bool libcdsb_list_update_int64 (vtype_list* x, ssize_t index, vtype_int64 value, int ins_direction);
extern bool libcdsb_list_update_uint8 (vtype_list* x, ssize_t index, vtype_uint8 value, int ins_direction);
extern bool libcdsb_list_update_uint16 (vtype_list* x, ssize_t index, vtype_uint16 value, int ins_direction);
extern bool libcdsb_list_update_uint32 (vtype_list* x, ssize_t index, vtype_uint32 value, int ins_direction);
extern bool libcdsb_list_update_uint64 (vtype_list* x, ssize_t index, vtype_uint64 value, int ins_direction);
extern bool libcdsb_list_update_float (vtype_list* x, ssize_t index, vtype_float value, int ins_direction);
extern bool libcdsb_list_update_double (vtype_list* x, ssize_t index, vtype_double value, int ins_direction);
extern bool libcdsb_list_update_ldouble(vtype_list* x, ssize_t index, vtype_ldouble value, int ins_direction);
#endif /* LIBCDSB_LIST_H */ #endif /* LIBCDSB_LIST_H */

View File

@ -1,8 +1,7 @@
/* This software is licensed by the MIT License, see LICENSE file */ /* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "bits/__generics.h" #include "__generics.h"
#include "bits/__rbtree.h"
#include "vtype.h" #include "vtype.h"
#ifndef LIBCDSB_MAP_H #ifndef LIBCDSB_MAP_H
@ -10,26 +9,411 @@
typedef int (*map_access_callback)(const void* key, vtype key_type, void* value, vtype value_type, void* data); 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);
extern void map_init(vtype_map* x, vtype key_type) Nonnull__(1); #define map_pop(x, s, key) _LIBCDSB_Generic (libcdsb_map, find, key)(x, s, key, 1)
#define map_get(x, s, key) _LIBCDSB_Generic (libcdsb_map, find, key)(x, s, key, 0)
#define map_update(x, key, value) _LIBCDSB_Generic2(libcdsb_map, update, key, value)(x, key, value)
#define map_remove(x, key) map_pop(0, x, key)
/*#####################################################################################################################*/ extern int libcdsb_map_find_pointer(vtype_map* x, const void* key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_cstring(vtype_map* x, const char* key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_string (vtype_map* x, const vtype_string* key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_array (vtype_map* x, const vtype_array* key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_list (vtype_map* x, const vtype_list* key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_map (vtype_map* x, const vtype_map* key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_vset (vtype_map* x, const vtype_set* key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_boolean(vtype_map* x, vtype_bool key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_int8 (vtype_map* x, vtype_int8 key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_int16 (vtype_map* x, vtype_int16 key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_int32 (vtype_map* x, vtype_int32 key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_int64 (vtype_map* x, vtype_int64 key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_uint8 (vtype_map* x, vtype_uint8 key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_uint16 (vtype_map* x, vtype_uint16 key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_uint32 (vtype_map* x, vtype_uint32 key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_uint64 (vtype_map* x, vtype_uint64 key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_float (vtype_map* x, vtype_float key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_double (vtype_map* x, vtype_double key, void* data, map_access_callback, bool cut);
extern int libcdsb_map_find_ldouble(vtype_map* x, vtype_ldouble key, void* data, map_access_callback, bool cut);
#define map_pop(x, key, data, callback) libcdsb_map_find (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), data, callback, 1) extern bool libcdsb_map_update_pointer_pointer(vtype_map* x, const void* key, const void* value);
#define map_get(x, key, data, callback) libcdsb_map_find (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), data, callback, 0) extern bool libcdsb_map_update_pointer_cstring(vtype_map* x, const void* key, const char* value);
#define map_update(x, key, value) libcdsb_map_update (x, _LIBCDSB_value_pointer(key), _LIBCDSB_vtypeof(key), _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), 0, 0) extern bool libcdsb_map_update_pointer_string (vtype_map* x, const void* key, const vtype_string* 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), 0, 0) extern bool libcdsb_map_update_pointer_array (vtype_map* x, const void* key, const vtype_array* value);
#define map_foreach(x, data, callback) libcdsb_map_foreach(x, data, callback, RBFOREACH_UNSPECIFIED, 0) extern bool libcdsb_map_update_pointer_list (vtype_map* x, const void* key, const vtype_list* value);
#define map_remove(x, key) map_pop (x, key, 0, 0) extern bool libcdsb_map_update_pointer_map (vtype_map* x, const void* key, const vtype_map* value);
extern bool libcdsb_map_update_pointer_vset (vtype_map* x, const void* key, const vtype_set* value);
extern bool libcdsb_map_update_pointer_boolean(vtype_map* x, const void* key, vtype_bool value);
extern bool libcdsb_map_update_pointer_int8 (vtype_map* x, const void* key, vtype_int8 value);
extern bool libcdsb_map_update_pointer_int16 (vtype_map* x, const void* key, vtype_int16 value);
extern bool libcdsb_map_update_pointer_int32 (vtype_map* x, const void* key, vtype_int32 value);
extern bool libcdsb_map_update_pointer_int64 (vtype_map* x, const void* key, vtype_int64 value);
extern bool libcdsb_map_update_pointer_uint8 (vtype_map* x, const void* key, vtype_uint8 value);
extern bool libcdsb_map_update_pointer_uint16 (vtype_map* x, const void* key, vtype_uint16 value);
extern bool libcdsb_map_update_pointer_uint32 (vtype_map* x, const void* key, vtype_uint32 value);
extern bool libcdsb_map_update_pointer_uint64 (vtype_map* x, const void* key, vtype_uint64 value);
extern bool libcdsb_map_update_pointer_float (vtype_map* x, const void* key, vtype_float value);
extern bool libcdsb_map_update_pointer_double (vtype_map* x, const void* key, vtype_double value);
extern bool libcdsb_map_update_pointer_ldouble(vtype_map* x, const void* key, vtype_ldouble value);
#define in_map(x, key) (map_get(x, key, 0, 0) == 0) extern bool libcdsb_map_update_string_pointer(vtype_map* x, const vtype_string* key, const void* value);
extern bool libcdsb_map_update_string_cstring(vtype_map* x, const vtype_string* key, const char* value);
extern bool libcdsb_map_update_string_string (vtype_map* x, const vtype_string* key, const vtype_string* value);
extern bool libcdsb_map_update_string_array (vtype_map* x, const vtype_string* key, const vtype_array* value);
extern bool libcdsb_map_update_string_list (vtype_map* x, const vtype_string* key, const vtype_list* value);
extern bool libcdsb_map_update_string_map (vtype_map* x, const vtype_string* key, const vtype_map* value);
extern bool libcdsb_map_update_string_vset (vtype_map* x, const vtype_string* key, const vtype_set* value);
extern bool libcdsb_map_update_string_boolean(vtype_map* x, const vtype_string* key, vtype_bool value);
extern bool libcdsb_map_update_string_int8 (vtype_map* x, const vtype_string* key, vtype_int8 value);
extern bool libcdsb_map_update_string_int16 (vtype_map* x, const vtype_string* key, vtype_int16 value);
extern bool libcdsb_map_update_string_int32 (vtype_map* x, const vtype_string* key, vtype_int32 value);
extern bool libcdsb_map_update_string_int64 (vtype_map* x, const vtype_string* key, vtype_int64 value);
extern bool libcdsb_map_update_string_uint8 (vtype_map* x, const vtype_string* key, vtype_uint8 value);
extern bool libcdsb_map_update_string_uint16 (vtype_map* x, const vtype_string* key, vtype_uint16 value);
extern bool libcdsb_map_update_string_uint32 (vtype_map* x, const vtype_string* key, vtype_uint32 value);
extern bool libcdsb_map_update_string_uint64 (vtype_map* x, const vtype_string* key, vtype_uint64 value);
extern bool libcdsb_map_update_string_float (vtype_map* x, const vtype_string* key, vtype_float value);
extern bool libcdsb_map_update_string_double (vtype_map* x, const vtype_string* key, vtype_double value);
extern bool libcdsb_map_update_string_ldouble(vtype_map* x, const vtype_string* key, vtype_ldouble value);
/*#####################################################################################################################*/ extern bool libcdsb_map_update_array_pointer(vtype_map* x, const vtype_array* key, const void* value);
extern bool libcdsb_map_update_array_cstring(vtype_map* x, const vtype_array* key, const char* value);
extern bool libcdsb_map_update_array_string (vtype_map* x, const vtype_array* key, const vtype_string* value);
extern bool libcdsb_map_update_array_array (vtype_map* x, const vtype_array* key, const vtype_array* value);
extern bool libcdsb_map_update_array_list (vtype_map* x, const vtype_array* key, const vtype_list* value);
extern bool libcdsb_map_update_array_map (vtype_map* x, const vtype_array* key, const vtype_map* value);
extern bool libcdsb_map_update_array_vset (vtype_map* x, const vtype_array* key, const vtype_set* value);
extern bool libcdsb_map_update_array_boolean(vtype_map* x, const vtype_array* key, vtype_bool value);
extern bool libcdsb_map_update_array_int8 (vtype_map* x, const vtype_array* key, vtype_int8 value);
extern bool libcdsb_map_update_array_int16 (vtype_map* x, const vtype_array* key, vtype_int16 value);
extern bool libcdsb_map_update_array_int32 (vtype_map* x, const vtype_array* key, vtype_int32 value);
extern bool libcdsb_map_update_array_int64 (vtype_map* x, const vtype_array* key, vtype_int64 value);
extern bool libcdsb_map_update_array_uint8 (vtype_map* x, const vtype_array* key, vtype_uint8 value);
extern bool libcdsb_map_update_array_uint16 (vtype_map* x, const vtype_array* key, vtype_uint16 value);
extern bool libcdsb_map_update_array_uint32 (vtype_map* x, const vtype_array* key, vtype_uint32 value);
extern bool libcdsb_map_update_array_uint64 (vtype_map* x, const vtype_array* key, vtype_uint64 value);
extern bool libcdsb_map_update_array_float (vtype_map* x, const vtype_array* key, vtype_float value);
extern bool libcdsb_map_update_array_double (vtype_map* x, const vtype_array* key, vtype_double value);
extern bool libcdsb_map_update_array_ldouble(vtype_map* x, const vtype_array* key, vtype_ldouble value);
extern bool libcdsb_map_update (vtype_map* x, const void* key, vtype key_type, const void* value, vtype value_type, void* data, map_access_callback) Nonnull__(1); extern bool libcdsb_map_update_list_pointer(vtype_map* x, const vtype_list* key, const void* value);
extern bool libcdsb_map_inject (vtype_map* x, const void* key, vtype key_type, const void* value, vtype value_type, void* data, map_access_callback) Nonnull__(1); extern bool libcdsb_map_update_list_cstring(vtype_map* x, const vtype_list* key, const char* value);
extern int libcdsb_map_find (vtype_map* x, const void* key, vtype key_type, void* data, map_access_callback, bool cut) Nonnull__(1); extern bool libcdsb_map_update_list_string (vtype_map* x, const vtype_list* key, const vtype_string* value);
extern int libcdsb_map_foreach(vtype_map* x, void* data, map_access_callback, rbforeach_t, bool flush) Nonnull__(1,3); extern bool libcdsb_map_update_list_array (vtype_map* x, const vtype_list* key, const vtype_array* value);
extern bool libcdsb_map_update_list_list (vtype_map* x, const vtype_list* key, const vtype_list* value);
extern bool libcdsb_map_update_list_map (vtype_map* x, const vtype_list* key, const vtype_map* value);
extern bool libcdsb_map_update_list_vset (vtype_map* x, const vtype_list* key, const vtype_set* value);
extern bool libcdsb_map_update_list_boolean(vtype_map* x, const vtype_list* key, vtype_bool value);
extern bool libcdsb_map_update_list_int8 (vtype_map* x, const vtype_list* key, vtype_int8 value);
extern bool libcdsb_map_update_list_int16 (vtype_map* x, const vtype_list* key, vtype_int16 value);
extern bool libcdsb_map_update_list_int32 (vtype_map* x, const vtype_list* key, vtype_int32 value);
extern bool libcdsb_map_update_list_int64 (vtype_map* x, const vtype_list* key, vtype_int64 value);
extern bool libcdsb_map_update_list_uint8 (vtype_map* x, const vtype_list* key, vtype_uint8 value);
extern bool libcdsb_map_update_list_uint16 (vtype_map* x, const vtype_list* key, vtype_uint16 value);
extern bool libcdsb_map_update_list_uint32 (vtype_map* x, const vtype_list* key, vtype_uint32 value);
extern bool libcdsb_map_update_list_uint64 (vtype_map* x, const vtype_list* key, vtype_uint64 value);
extern bool libcdsb_map_update_list_float (vtype_map* x, const vtype_list* key, vtype_float value);
extern bool libcdsb_map_update_list_double (vtype_map* x, const vtype_list* key, vtype_double value);
extern bool libcdsb_map_update_list_ldouble(vtype_map* x, const vtype_list* key, vtype_ldouble value);
extern bool libcdsb_map_update_map_pointer(vtype_map* x, const vtype_map* key, const void* value);
extern bool libcdsb_map_update_map_cstring(vtype_map* x, const vtype_map* key, const char* value);
extern bool libcdsb_map_update_map_string (vtype_map* x, const vtype_map* key, const vtype_string* value);
extern bool libcdsb_map_update_map_array (vtype_map* x, const vtype_map* key, const vtype_array* value);
extern bool libcdsb_map_update_map_list (vtype_map* x, const vtype_map* key, const vtype_list* value);
extern bool libcdsb_map_update_map_map (vtype_map* x, const vtype_map* key, const vtype_map* value);
extern bool libcdsb_map_update_map_vset (vtype_map* x, const vtype_map* key, const vtype_set* value);
extern bool libcdsb_map_update_map_boolean(vtype_map* x, const vtype_map* key, vtype_bool value);
extern bool libcdsb_map_update_map_int8 (vtype_map* x, const vtype_map* key, vtype_int8 value);
extern bool libcdsb_map_update_map_int16 (vtype_map* x, const vtype_map* key, vtype_int16 value);
extern bool libcdsb_map_update_map_int32 (vtype_map* x, const vtype_map* key, vtype_int32 value);
extern bool libcdsb_map_update_map_int64 (vtype_map* x, const vtype_map* key, vtype_int64 value);
extern bool libcdsb_map_update_map_uint8 (vtype_map* x, const vtype_map* key, vtype_uint8 value);
extern bool libcdsb_map_update_map_uint16 (vtype_map* x, const vtype_map* key, vtype_uint16 value);
extern bool libcdsb_map_update_map_uint32 (vtype_map* x, const vtype_map* key, vtype_uint32 value);
extern bool libcdsb_map_update_map_uint64 (vtype_map* x, const vtype_map* key, vtype_uint64 value);
extern bool libcdsb_map_update_map_float (vtype_map* x, const vtype_map* key, vtype_float value);
extern bool libcdsb_map_update_map_double (vtype_map* x, const vtype_map* key, vtype_double value);
extern bool libcdsb_map_update_map_ldouble(vtype_map* x, const vtype_map* key, vtype_ldouble value);
extern bool libcdsb_map_update_vset_pointer(vtype_map* x, const vtype_set* key, const void* value);
extern bool libcdsb_map_update_vset_cstring(vtype_map* x, const vtype_set* key, const char* value);
extern bool libcdsb_map_update_vset_string (vtype_map* x, const vtype_set* key, const vtype_string* value);
extern bool libcdsb_map_update_vset_array (vtype_map* x, const vtype_set* key, const vtype_array* value);
extern bool libcdsb_map_update_vset_list (vtype_map* x, const vtype_set* key, const vtype_list* value);
extern bool libcdsb_map_update_vset_map (vtype_map* x, const vtype_set* key, const vtype_map* value);
extern bool libcdsb_map_update_vset_vset (vtype_map* x, const vtype_set* key, const vtype_set* value);
extern bool libcdsb_map_update_vset_boolean(vtype_map* x, const vtype_set* key, vtype_bool value);
extern bool libcdsb_map_update_vset_int8 (vtype_map* x, const vtype_set* key, vtype_int8 value);
extern bool libcdsb_map_update_vset_int16 (vtype_map* x, const vtype_set* key, vtype_int16 value);
extern bool libcdsb_map_update_vset_int32 (vtype_map* x, const vtype_set* key, vtype_int32 value);
extern bool libcdsb_map_update_vset_int64 (vtype_map* x, const vtype_set* key, vtype_int64 value);
extern bool libcdsb_map_update_vset_uint8 (vtype_map* x, const vtype_set* key, vtype_uint8 value);
extern bool libcdsb_map_update_vset_uint16 (vtype_map* x, const vtype_set* key, vtype_uint16 value);
extern bool libcdsb_map_update_vset_uint32 (vtype_map* x, const vtype_set* key, vtype_uint32 value);
extern bool libcdsb_map_update_vset_uint64 (vtype_map* x, const vtype_set* key, vtype_uint64 value);
extern bool libcdsb_map_update_vset_float (vtype_map* x, const vtype_set* key, vtype_float value);
extern bool libcdsb_map_update_vset_double (vtype_map* x, const vtype_set* key, vtype_double value);
extern bool libcdsb_map_update_vset_ldouble(vtype_map* x, const vtype_set* key, vtype_ldouble value);
extern bool libcdsb_map_update_cstring_pointer(vtype_map* x, const char* key, const void* value);
extern bool libcdsb_map_update_cstring_cstring(vtype_map* x, const char* key, const char* value);
extern bool libcdsb_map_update_cstring_string (vtype_map* x, const char* key, const vtype_string* value);
extern bool libcdsb_map_update_cstring_array (vtype_map* x, const char* key, const vtype_array* value);
extern bool libcdsb_map_update_cstring_list (vtype_map* x, const char* key, const vtype_list* value);
extern bool libcdsb_map_update_cstring_map (vtype_map* x, const char* key, const vtype_map* value);
extern bool libcdsb_map_update_cstring_vset (vtype_map* x, const char* key, const vtype_set* value);
extern bool libcdsb_map_update_cstring_boolean(vtype_map* x, const char* key, vtype_bool value);
extern bool libcdsb_map_update_cstring_int8 (vtype_map* x, const char* key, vtype_int8 value);
extern bool libcdsb_map_update_cstring_int16 (vtype_map* x, const char* key, vtype_int16 value);
extern bool libcdsb_map_update_cstring_int32 (vtype_map* x, const char* key, vtype_int32 value);
extern bool libcdsb_map_update_cstring_int64 (vtype_map* x, const char* key, vtype_int64 value);
extern bool libcdsb_map_update_cstring_uint8 (vtype_map* x, const char* key, vtype_uint8 value);
extern bool libcdsb_map_update_cstring_uint16 (vtype_map* x, const char* key, vtype_uint16 value);
extern bool libcdsb_map_update_cstring_uint32 (vtype_map* x, const char* key, vtype_uint32 value);
extern bool libcdsb_map_update_cstring_uint64 (vtype_map* x, const char* key, vtype_uint64 value);
extern bool libcdsb_map_update_cstring_float (vtype_map* x, const char* key, vtype_float value);
extern bool libcdsb_map_update_cstring_double (vtype_map* x, const char* key, vtype_double value);
extern bool libcdsb_map_update_cstring_ldouble(vtype_map* x, const char* key, vtype_ldouble value);
extern bool libcdsb_map_update_boolean_pointer(vtype_map* x, vtype_bool key, const void* value);
extern bool libcdsb_map_update_boolean_cstring(vtype_map* x, vtype_bool key, const char* value);
extern bool libcdsb_map_update_boolean_string (vtype_map* x, vtype_bool key, const vtype_string* value);
extern bool libcdsb_map_update_boolean_array (vtype_map* x, vtype_bool key, const vtype_array* value);
extern bool libcdsb_map_update_boolean_list (vtype_map* x, vtype_bool key, const vtype_list* value);
extern bool libcdsb_map_update_boolean_map (vtype_map* x, vtype_bool key, const vtype_map* value);
extern bool libcdsb_map_update_boolean_vset (vtype_map* x, vtype_bool key, const vtype_set* value);
extern bool libcdsb_map_update_boolean_boolean(vtype_map* x, vtype_bool key, vtype_bool value);
extern bool libcdsb_map_update_boolean_int8 (vtype_map* x, vtype_bool key, vtype_int8 value);
extern bool libcdsb_map_update_boolean_int16 (vtype_map* x, vtype_bool key, vtype_int16 value);
extern bool libcdsb_map_update_boolean_int32 (vtype_map* x, vtype_bool key, vtype_int32 value);
extern bool libcdsb_map_update_boolean_int64 (vtype_map* x, vtype_bool key, vtype_int64 value);
extern bool libcdsb_map_update_boolean_uint8 (vtype_map* x, vtype_bool key, vtype_uint8 value);
extern bool libcdsb_map_update_boolean_uint16 (vtype_map* x, vtype_bool key, vtype_uint16 value);
extern bool libcdsb_map_update_boolean_uint32 (vtype_map* x, vtype_bool key, vtype_uint32 value);
extern bool libcdsb_map_update_boolean_uint64 (vtype_map* x, vtype_bool key, vtype_uint64 value);
extern bool libcdsb_map_update_boolean_float (vtype_map* x, vtype_bool key, vtype_float value);
extern bool libcdsb_map_update_boolean_double (vtype_map* x, vtype_bool key, vtype_double value);
extern bool libcdsb_map_update_boolean_ldouble(vtype_map* x, vtype_bool key, vtype_ldouble value);
extern bool libcdsb_map_update_uint8_pointer(vtype_map* x, vtype_uint8 key, const void* value);
extern bool libcdsb_map_update_uint8_cstring(vtype_map* x, vtype_uint8 key, const char* value);
extern bool libcdsb_map_update_uint8_string (vtype_map* x, vtype_uint8 key, const vtype_string* value);
extern bool libcdsb_map_update_uint8_array (vtype_map* x, vtype_uint8 key, const vtype_array* value);
extern bool libcdsb_map_update_uint8_list (vtype_map* x, vtype_uint8 key, const vtype_list* value);
extern bool libcdsb_map_update_uint8_map (vtype_map* x, vtype_uint8 key, const vtype_map* value);
extern bool libcdsb_map_update_uint8_vset (vtype_map* x, vtype_uint8 key, const vtype_set* value);
extern bool libcdsb_map_update_uint8_boolean(vtype_map* x, vtype_uint8 key, vtype_bool value);
extern bool libcdsb_map_update_uint8_int8 (vtype_map* x, vtype_uint8 key, vtype_int8 value);
extern bool libcdsb_map_update_uint8_int16 (vtype_map* x, vtype_uint8 key, vtype_int16 value);
extern bool libcdsb_map_update_uint8_int32 (vtype_map* x, vtype_uint8 key, vtype_int32 value);
extern bool libcdsb_map_update_uint8_int64 (vtype_map* x, vtype_uint8 key, vtype_int64 value);
extern bool libcdsb_map_update_uint8_uint8 (vtype_map* x, vtype_uint8 key, vtype_uint8 value);
extern bool libcdsb_map_update_uint8_uint16 (vtype_map* x, vtype_uint8 key, vtype_uint16 value);
extern bool libcdsb_map_update_uint8_uint32 (vtype_map* x, vtype_uint8 key, vtype_uint32 value);
extern bool libcdsb_map_update_uint8_uint64 (vtype_map* x, vtype_uint8 key, vtype_uint64 value);
extern bool libcdsb_map_update_uint8_float (vtype_map* x, vtype_uint8 key, vtype_float value);
extern bool libcdsb_map_update_uint8_double (vtype_map* x, vtype_uint8 key, vtype_double value);
extern bool libcdsb_map_update_uint8_ldouble(vtype_map* x, vtype_uint8 key, vtype_ldouble value);
extern bool libcdsb_map_update_uint16_pointer(vtype_map* x, vtype_uint16 key, const void* value);
extern bool libcdsb_map_update_uint16_cstring(vtype_map* x, vtype_uint16 key, const char* value);
extern bool libcdsb_map_update_uint16_string (vtype_map* x, vtype_uint16 key, const vtype_string* value);
extern bool libcdsb_map_update_uint16_array (vtype_map* x, vtype_uint16 key, const vtype_array* value);
extern bool libcdsb_map_update_uint16_list (vtype_map* x, vtype_uint16 key, const vtype_list* value);
extern bool libcdsb_map_update_uint16_map (vtype_map* x, vtype_uint16 key, const vtype_map* value);
extern bool libcdsb_map_update_uint16_vset (vtype_map* x, vtype_uint16 key, const vtype_set* value);
extern bool libcdsb_map_update_uint16_boolean(vtype_map* x, vtype_uint16 key, vtype_bool value);
extern bool libcdsb_map_update_uint16_int8 (vtype_map* x, vtype_uint16 key, vtype_int8 value);
extern bool libcdsb_map_update_uint16_int16 (vtype_map* x, vtype_uint16 key, vtype_int16 value);
extern bool libcdsb_map_update_uint16_int32 (vtype_map* x, vtype_uint16 key, vtype_int32 value);
extern bool libcdsb_map_update_uint16_int64 (vtype_map* x, vtype_uint16 key, vtype_int64 value);
extern bool libcdsb_map_update_uint16_uint8 (vtype_map* x, vtype_uint16 key, vtype_uint8 value);
extern bool libcdsb_map_update_uint16_uint16 (vtype_map* x, vtype_uint16 key, vtype_uint16 value);
extern bool libcdsb_map_update_uint16_uint32 (vtype_map* x, vtype_uint16 key, vtype_uint32 value);
extern bool libcdsb_map_update_uint16_uint64 (vtype_map* x, vtype_uint16 key, vtype_uint64 value);
extern bool libcdsb_map_update_uint16_float (vtype_map* x, vtype_uint16 key, vtype_float value);
extern bool libcdsb_map_update_uint16_double (vtype_map* x, vtype_uint16 key, vtype_double value);
extern bool libcdsb_map_update_uint16_ldouble(vtype_map* x, vtype_uint16 key, vtype_ldouble value);
extern bool libcdsb_map_update_uint32_pointer(vtype_map* x, vtype_uint32 key, const void* value);
extern bool libcdsb_map_update_uint32_cstring(vtype_map* x, vtype_uint32 key, const char* value);
extern bool libcdsb_map_update_uint32_string (vtype_map* x, vtype_uint32 key, const vtype_string* value);
extern bool libcdsb_map_update_uint32_array (vtype_map* x, vtype_uint32 key, const vtype_array* value);
extern bool libcdsb_map_update_uint32_list (vtype_map* x, vtype_uint32 key, const vtype_list* value);
extern bool libcdsb_map_update_uint32_map (vtype_map* x, vtype_uint32 key, const vtype_map* value);
extern bool libcdsb_map_update_uint32_vset (vtype_map* x, vtype_uint32 key, const vtype_set* value);
extern bool libcdsb_map_update_uint32_boolean(vtype_map* x, vtype_uint32 key, vtype_bool value);
extern bool libcdsb_map_update_uint32_int8 (vtype_map* x, vtype_uint32 key, vtype_int8 value);
extern bool libcdsb_map_update_uint32_int16 (vtype_map* x, vtype_uint32 key, vtype_int16 value);
extern bool libcdsb_map_update_uint32_int32 (vtype_map* x, vtype_uint32 key, vtype_int32 value);
extern bool libcdsb_map_update_uint32_int64 (vtype_map* x, vtype_uint32 key, vtype_int64 value);
extern bool libcdsb_map_update_uint32_uint8 (vtype_map* x, vtype_uint32 key, vtype_uint8 value);
extern bool libcdsb_map_update_uint32_uint16 (vtype_map* x, vtype_uint32 key, vtype_uint16 value);
extern bool libcdsb_map_update_uint32_uint32 (vtype_map* x, vtype_uint32 key, vtype_uint32 value);
extern bool libcdsb_map_update_uint32_uint64 (vtype_map* x, vtype_uint32 key, vtype_uint64 value);
extern bool libcdsb_map_update_uint32_float (vtype_map* x, vtype_uint32 key, vtype_float value);
extern bool libcdsb_map_update_uint32_double (vtype_map* x, vtype_uint32 key, vtype_double value);
extern bool libcdsb_map_update_uint32_ldouble(vtype_map* x, vtype_uint32 key, vtype_ldouble value);
extern bool libcdsb_map_update_uint64_pointer(vtype_map* x, vtype_uint64 key, const void* value);
extern bool libcdsb_map_update_uint64_cstring(vtype_map* x, vtype_uint64 key, const char* value);
extern bool libcdsb_map_update_uint64_string (vtype_map* x, vtype_uint64 key, const vtype_string* value);
extern bool libcdsb_map_update_uint64_array (vtype_map* x, vtype_uint64 key, const vtype_array* value);
extern bool libcdsb_map_update_uint64_list (vtype_map* x, vtype_uint64 key, const vtype_list* value);
extern bool libcdsb_map_update_uint64_map (vtype_map* x, vtype_uint64 key, const vtype_map* value);
extern bool libcdsb_map_update_uint64_vset (vtype_map* x, vtype_uint64 key, const vtype_set* value);
extern bool libcdsb_map_update_uint64_boolean(vtype_map* x, vtype_uint64 key, vtype_bool value);
extern bool libcdsb_map_update_uint64_int8 (vtype_map* x, vtype_uint64 key, vtype_int8 value);
extern bool libcdsb_map_update_uint64_int16 (vtype_map* x, vtype_uint64 key, vtype_int16 value);
extern bool libcdsb_map_update_uint64_int32 (vtype_map* x, vtype_uint64 key, vtype_int32 value);
extern bool libcdsb_map_update_uint64_int64 (vtype_map* x, vtype_uint64 key, vtype_int64 value);
extern bool libcdsb_map_update_uint64_uint8 (vtype_map* x, vtype_uint64 key, vtype_uint8 value);
extern bool libcdsb_map_update_uint64_uint16 (vtype_map* x, vtype_uint64 key, vtype_uint16 value);
extern bool libcdsb_map_update_uint64_uint32 (vtype_map* x, vtype_uint64 key, vtype_uint32 value);
extern bool libcdsb_map_update_uint64_uint64 (vtype_map* x, vtype_uint64 key, vtype_uint64 value);
extern bool libcdsb_map_update_uint64_float (vtype_map* x, vtype_uint64 key, vtype_float value);
extern bool libcdsb_map_update_uint64_double (vtype_map* x, vtype_uint64 key, vtype_double value);
extern bool libcdsb_map_update_uint64_ldouble(vtype_map* x, vtype_uint64 key, vtype_ldouble value);
extern bool libcdsb_map_update_int8_pointer(vtype_map* x, vtype_int8 key, const void* value);
extern bool libcdsb_map_update_int8_cstring(vtype_map* x, vtype_int8 key, const char* value);
extern bool libcdsb_map_update_int8_string (vtype_map* x, vtype_int8 key, const vtype_string* value);
extern bool libcdsb_map_update_int8_array (vtype_map* x, vtype_int8 key, const vtype_array* value);
extern bool libcdsb_map_update_int8_list (vtype_map* x, vtype_int8 key, const vtype_list* value);
extern bool libcdsb_map_update_int8_map (vtype_map* x, vtype_int8 key, const vtype_map* value);
extern bool libcdsb_map_update_int8_vset (vtype_map* x, vtype_int8 key, const vtype_set* value);
extern bool libcdsb_map_update_int8_boolean(vtype_map* x, vtype_int8 key, vtype_bool value);
extern bool libcdsb_map_update_int8_int8 (vtype_map* x, vtype_int8 key, vtype_int8 value);
extern bool libcdsb_map_update_int8_int16 (vtype_map* x, vtype_int8 key, vtype_int16 value);
extern bool libcdsb_map_update_int8_int32 (vtype_map* x, vtype_int8 key, vtype_int32 value);
extern bool libcdsb_map_update_int8_int64 (vtype_map* x, vtype_int8 key, vtype_int64 value);
extern bool libcdsb_map_update_int8_uint8 (vtype_map* x, vtype_int8 key, vtype_uint8 value);
extern bool libcdsb_map_update_int8_uint16 (vtype_map* x, vtype_int8 key, vtype_uint16 value);
extern bool libcdsb_map_update_int8_uint32 (vtype_map* x, vtype_int8 key, vtype_uint32 value);
extern bool libcdsb_map_update_int8_uint64 (vtype_map* x, vtype_int8 key, vtype_uint64 value);
extern bool libcdsb_map_update_int8_float (vtype_map* x, vtype_int8 key, vtype_float value);
extern bool libcdsb_map_update_int8_double (vtype_map* x, vtype_int8 key, vtype_double value);
extern bool libcdsb_map_update_int8_ldouble(vtype_map* x, vtype_int8 key, vtype_ldouble value);
extern bool libcdsb_map_update_int16_pointer(vtype_map* x, vtype_int16 key, const void* value);
extern bool libcdsb_map_update_int16_cstring(vtype_map* x, vtype_int16 key, const char* value);
extern bool libcdsb_map_update_int16_string (vtype_map* x, vtype_int16 key, const vtype_string* value);
extern bool libcdsb_map_update_int16_array (vtype_map* x, vtype_int16 key, const vtype_array* value);
extern bool libcdsb_map_update_int16_list (vtype_map* x, vtype_int16 key, const vtype_list* value);
extern bool libcdsb_map_update_int16_map (vtype_map* x, vtype_int16 key, const vtype_map* value);
extern bool libcdsb_map_update_int16_vset (vtype_map* x, vtype_int16 key, const vtype_set* value);
extern bool libcdsb_map_update_int16_boolean(vtype_map* x, vtype_int16 key, vtype_bool value);
extern bool libcdsb_map_update_int16_int8 (vtype_map* x, vtype_int16 key, vtype_int8 value);
extern bool libcdsb_map_update_int16_int16 (vtype_map* x, vtype_int16 key, vtype_int16 value);
extern bool libcdsb_map_update_int16_int32 (vtype_map* x, vtype_int16 key, vtype_int32 value);
extern bool libcdsb_map_update_int16_int64 (vtype_map* x, vtype_int16 key, vtype_int64 value);
extern bool libcdsb_map_update_int16_uint8 (vtype_map* x, vtype_int16 key, vtype_uint8 value);
extern bool libcdsb_map_update_int16_uint16 (vtype_map* x, vtype_int16 key, vtype_uint16 value);
extern bool libcdsb_map_update_int16_uint32 (vtype_map* x, vtype_int16 key, vtype_uint32 value);
extern bool libcdsb_map_update_int16_uint64 (vtype_map* x, vtype_int16 key, vtype_uint64 value);
extern bool libcdsb_map_update_int16_float (vtype_map* x, vtype_int16 key, vtype_float value);
extern bool libcdsb_map_update_int16_double (vtype_map* x, vtype_int16 key, vtype_double value);
extern bool libcdsb_map_update_int16_ldouble(vtype_map* x, vtype_int16 key, vtype_ldouble value);
extern bool libcdsb_map_update_int32_pointer(vtype_map* x, vtype_int32 key, const void* value);
extern bool libcdsb_map_update_int32_cstring(vtype_map* x, vtype_int32 key, const char* value);
extern bool libcdsb_map_update_int32_string (vtype_map* x, vtype_int32 key, const vtype_string* value);
extern bool libcdsb_map_update_int32_array (vtype_map* x, vtype_int32 key, const vtype_array* value);
extern bool libcdsb_map_update_int32_list (vtype_map* x, vtype_int32 key, const vtype_list* value);
extern bool libcdsb_map_update_int32_map (vtype_map* x, vtype_int32 key, const vtype_map* value);
extern bool libcdsb_map_update_int32_vset (vtype_map* x, vtype_int32 key, const vtype_set* value);
extern bool libcdsb_map_update_int32_boolean(vtype_map* x, vtype_int32 key, vtype_bool value);
extern bool libcdsb_map_update_int32_int8 (vtype_map* x, vtype_int32 key, vtype_int8 value);
extern bool libcdsb_map_update_int32_int16 (vtype_map* x, vtype_int32 key, vtype_int16 value);
extern bool libcdsb_map_update_int32_int32 (vtype_map* x, vtype_int32 key, vtype_int32 value);
extern bool libcdsb_map_update_int32_int64 (vtype_map* x, vtype_int32 key, vtype_int64 value);
extern bool libcdsb_map_update_int32_uint8 (vtype_map* x, vtype_int32 key, vtype_uint8 value);
extern bool libcdsb_map_update_int32_uint16 (vtype_map* x, vtype_int32 key, vtype_uint16 value);
extern bool libcdsb_map_update_int32_uint32 (vtype_map* x, vtype_int32 key, vtype_uint32 value);
extern bool libcdsb_map_update_int32_uint64 (vtype_map* x, vtype_int32 key, vtype_uint64 value);
extern bool libcdsb_map_update_int32_float (vtype_map* x, vtype_int32 key, vtype_float value);
extern bool libcdsb_map_update_int32_double (vtype_map* x, vtype_int32 key, vtype_double value);
extern bool libcdsb_map_update_int32_ldouble(vtype_map* x, vtype_int32 key, vtype_ldouble value);
extern bool libcdsb_map_update_int64_pointer(vtype_map* x, vtype_int64 key, const void* value);
extern bool libcdsb_map_update_int64_cstring(vtype_map* x, vtype_int64 key, const char* value);
extern bool libcdsb_map_update_int64_string (vtype_map* x, vtype_int64 key, const vtype_string* value);
extern bool libcdsb_map_update_int64_array (vtype_map* x, vtype_int64 key, const vtype_array* value);
extern bool libcdsb_map_update_int64_list (vtype_map* x, vtype_int64 key, const vtype_list* value);
extern bool libcdsb_map_update_int64_map (vtype_map* x, vtype_int64 key, const vtype_map* value);
extern bool libcdsb_map_update_int64_vset (vtype_map* x, vtype_int64 key, const vtype_set* value);
extern bool libcdsb_map_update_int64_boolean(vtype_map* x, vtype_int64 key, vtype_bool value);
extern bool libcdsb_map_update_int64_int8 (vtype_map* x, vtype_int64 key, vtype_int8 value);
extern bool libcdsb_map_update_int64_int16 (vtype_map* x, vtype_int64 key, vtype_int16 value);
extern bool libcdsb_map_update_int64_int32 (vtype_map* x, vtype_int64 key, vtype_int32 value);
extern bool libcdsb_map_update_int64_int64 (vtype_map* x, vtype_int64 key, vtype_int64 value);
extern bool libcdsb_map_update_int64_uint8 (vtype_map* x, vtype_int64 key, vtype_uint8 value);
extern bool libcdsb_map_update_int64_uint16 (vtype_map* x, vtype_int64 key, vtype_uint16 value);
extern bool libcdsb_map_update_int64_uint32 (vtype_map* x, vtype_int64 key, vtype_uint32 value);
extern bool libcdsb_map_update_int64_uint64 (vtype_map* x, vtype_int64 key, vtype_uint64 value);
extern bool libcdsb_map_update_int64_float (vtype_map* x, vtype_int64 key, vtype_float value);
extern bool libcdsb_map_update_int64_double (vtype_map* x, vtype_int64 key, vtype_double value);
extern bool libcdsb_map_update_int64_ldouble(vtype_map* x, vtype_int64 key, vtype_ldouble value);
extern bool libcdsb_map_update_float_pointer(vtype_map* x, vtype_float key, const void* value);
extern bool libcdsb_map_update_float_cstring(vtype_map* x, vtype_float key, const char* value);
extern bool libcdsb_map_update_float_string (vtype_map* x, vtype_float key, const vtype_string* value);
extern bool libcdsb_map_update_float_array (vtype_map* x, vtype_float key, const vtype_array* value);
extern bool libcdsb_map_update_float_list (vtype_map* x, vtype_float key, const vtype_list* value);
extern bool libcdsb_map_update_float_map (vtype_map* x, vtype_float key, const vtype_map* value);
extern bool libcdsb_map_update_float_vset (vtype_map* x, vtype_float key, const vtype_set* value);
extern bool libcdsb_map_update_float_boolean(vtype_map* x, vtype_float key, vtype_bool value);
extern bool libcdsb_map_update_float_int8 (vtype_map* x, vtype_float key, vtype_int8 value);
extern bool libcdsb_map_update_float_int16 (vtype_map* x, vtype_float key, vtype_int16 value);
extern bool libcdsb_map_update_float_int32 (vtype_map* x, vtype_float key, vtype_int32 value);
extern bool libcdsb_map_update_float_int64 (vtype_map* x, vtype_float key, vtype_int64 value);
extern bool libcdsb_map_update_float_uint8 (vtype_map* x, vtype_float key, vtype_uint8 value);
extern bool libcdsb_map_update_float_uint16 (vtype_map* x, vtype_float key, vtype_uint16 value);
extern bool libcdsb_map_update_float_uint32 (vtype_map* x, vtype_float key, vtype_uint32 value);
extern bool libcdsb_map_update_float_uint64 (vtype_map* x, vtype_float key, vtype_uint64 value);
extern bool libcdsb_map_update_float_float (vtype_map* x, vtype_float key, vtype_float value);
extern bool libcdsb_map_update_float_double (vtype_map* x, vtype_float key, vtype_double value);
extern bool libcdsb_map_update_float_ldouble(vtype_map* x, vtype_float key, vtype_ldouble value);
extern bool libcdsb_map_update_double_pointer(vtype_map* x, vtype_double key, const void* value);
extern bool libcdsb_map_update_double_cstring(vtype_map* x, vtype_double key, const char* value);
extern bool libcdsb_map_update_double_string (vtype_map* x, vtype_double key, const vtype_string* value);
extern bool libcdsb_map_update_double_array (vtype_map* x, vtype_double key, const vtype_array* value);
extern bool libcdsb_map_update_double_list (vtype_map* x, vtype_double key, const vtype_list* value);
extern bool libcdsb_map_update_double_map (vtype_map* x, vtype_double key, const vtype_map* value);
extern bool libcdsb_map_update_double_vset (vtype_map* x, vtype_double key, const vtype_set* value);
extern bool libcdsb_map_update_double_boolean(vtype_map* x, vtype_double key, vtype_bool value);
extern bool libcdsb_map_update_double_int8 (vtype_map* x, vtype_double key, vtype_int8 value);
extern bool libcdsb_map_update_double_int16 (vtype_map* x, vtype_double key, vtype_int16 value);
extern bool libcdsb_map_update_double_int32 (vtype_map* x, vtype_double key, vtype_int32 value);
extern bool libcdsb_map_update_double_int64 (vtype_map* x, vtype_double key, vtype_int64 value);
extern bool libcdsb_map_update_double_uint8 (vtype_map* x, vtype_double key, vtype_uint8 value);
extern bool libcdsb_map_update_double_uint16 (vtype_map* x, vtype_double key, vtype_uint16 value);
extern bool libcdsb_map_update_double_uint32 (vtype_map* x, vtype_double key, vtype_uint32 value);
extern bool libcdsb_map_update_double_uint64 (vtype_map* x, vtype_double key, vtype_uint64 value);
extern bool libcdsb_map_update_double_float (vtype_map* x, vtype_double key, vtype_float value);
extern bool libcdsb_map_update_double_double (vtype_map* x, vtype_double key, vtype_double value);
extern bool libcdsb_map_update_double_ldouble(vtype_map* x, vtype_double key, vtype_ldouble value);
extern bool libcdsb_map_update_ldouble_pointer(vtype_map* x, vtype_ldouble key, const void* value);
extern bool libcdsb_map_update_ldouble_cstring(vtype_map* x, vtype_ldouble key, const char* value);
extern bool libcdsb_map_update_ldouble_string (vtype_map* x, vtype_ldouble key, const vtype_string* value);
extern bool libcdsb_map_update_ldouble_array (vtype_map* x, vtype_ldouble key, const vtype_array* value);
extern bool libcdsb_map_update_ldouble_list (vtype_map* x, vtype_ldouble key, const vtype_list* value);
extern bool libcdsb_map_update_ldouble_map (vtype_map* x, vtype_ldouble key, const vtype_map* value);
extern bool libcdsb_map_update_ldouble_vset (vtype_map* x, vtype_ldouble key, const vtype_set* value);
extern bool libcdsb_map_update_ldouble_boolean(vtype_map* x, vtype_ldouble key, vtype_bool value);
extern bool libcdsb_map_update_ldouble_int8 (vtype_map* x, vtype_ldouble key, vtype_int8 value);
extern bool libcdsb_map_update_ldouble_int16 (vtype_map* x, vtype_ldouble key, vtype_int16 value);
extern bool libcdsb_map_update_ldouble_int32 (vtype_map* x, vtype_ldouble key, vtype_int32 value);
extern bool libcdsb_map_update_ldouble_int64 (vtype_map* x, vtype_ldouble key, vtype_int64 value);
extern bool libcdsb_map_update_ldouble_uint8 (vtype_map* x, vtype_ldouble key, vtype_uint8 value);
extern bool libcdsb_map_update_ldouble_uint16 (vtype_map* x, vtype_ldouble key, vtype_uint16 value);
extern bool libcdsb_map_update_ldouble_uint32 (vtype_map* x, vtype_ldouble key, vtype_uint32 value);
extern bool libcdsb_map_update_ldouble_uint64 (vtype_map* x, vtype_ldouble key, vtype_uint64 value);
extern bool libcdsb_map_update_ldouble_float (vtype_map* x, vtype_ldouble key, vtype_float value);
extern bool libcdsb_map_update_ldouble_double (vtype_map* x, vtype_ldouble key, vtype_double value);
extern bool libcdsb_map_update_ldouble_ldouble(vtype_map* x, vtype_ldouble key, vtype_ldouble value);
#endif /* LIBCDSB_MAP_H */ #endif /* LIBCDSB_MAP_H */

View File

@ -1,8 +1,7 @@
/* This software is licensed by the MIT License, see LICENSE file */ /* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "bits/__generics.h" #include "__generics.h"
#include "bits/__rbtree.h"
#include "vtype.h" #include "vtype.h"
#ifndef LIBCDSB_SET_H #ifndef LIBCDSB_SET_H
@ -10,26 +9,51 @@
typedef int (*vset_access_callback)(const void* value, vtype type, void* data); typedef int (*vset_access_callback)(const void* value, vtype type, void* data);
/*#####################################################################################################################*/ extern void vset_init(vtype_set* x, vtype type);
extern void vset_init(vtype_set* x, vtype type) Nonnull__(1); #define vset_remove(x, value) _LIBCDSB_Generic (libcdsb_vset, touch, value)(x, value, 1)
#define vset_push(x, value) _LIBCDSB_Generic (libcdsb_vset, push, value)(x, value)
/*#####################################################################################################################*/ #define in_vset(x, value) _LIBCDSB_Generic (libcdsb_vset, touch, value)(x, value, 0)
#define vset_pop(x, value, data, callback) libcdsb_vset_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 1) extern bool libcdsb_vset_push_pointer(vtype_set* x, const void* value);
#define vset_get(x, value, data, callback) libcdsb_vset_find (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value), data, callback, 0) extern bool libcdsb_vset_push_cstring(vtype_set* x, const char* value);
#define vset_push(x, value) libcdsb_vset_insert (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) extern bool libcdsb_vset_push_string (vtype_set* x, const vtype_string* value);
#define vset_attach(x, value) libcdsb_vset_attach (x, _LIBCDSB_value_pointer(value), _LIBCDSB_vtypeof(value)) extern bool libcdsb_vset_push_array (vtype_set* x, const vtype_array* value);
#define vset_foreach(x, data, callback) libcdsb_vset_foreach(x, data, callback, RBFOREACH_UNSPECIFIED, 0) extern bool libcdsb_vset_push_list (vtype_set* x, const vtype_list* value);
#define vset_remove(x, value) vset_pop (x, value, 0, 0) extern bool libcdsb_vset_push_map (vtype_set* x, const vtype_map* value);
extern bool libcdsb_vset_push_vset (vtype_set* x, const vtype_set* value);
extern bool libcdsb_vset_push_boolean(vtype_set* x, vtype_bool value);
extern bool libcdsb_vset_push_uint8 (vtype_set* x, vtype_uint8 value);
extern bool libcdsb_vset_push_uint16 (vtype_set* x, vtype_uint16 value);
extern bool libcdsb_vset_push_uint32 (vtype_set* x, vtype_uint32 value);
extern bool libcdsb_vset_push_uint64 (vtype_set* x, vtype_uint64 value);
extern bool libcdsb_vset_push_int8 (vtype_set* x, vtype_int8 value);
extern bool libcdsb_vset_push_int16 (vtype_set* x, vtype_int16 value);
extern bool libcdsb_vset_push_int32 (vtype_set* x, vtype_int32 value);
extern bool libcdsb_vset_push_int64 (vtype_set* x, vtype_int64 value);
extern bool libcdsb_vset_push_float (vtype_set* x, vtype_float value);
extern bool libcdsb_vset_push_double (vtype_set* x, vtype_double value);
extern bool libcdsb_vset_push_ldouble(vtype_set* x, vtype_ldouble value);
#define in_vset(x, value) (vset_get(x, value, 0, 0) == 0) extern int libcdsb_vset_find_pointer(vtype_set* x, const void* value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_cstring(vtype_set* x, const char* value, void* data, vset_access_callback, bool cut);
/*#####################################################################################################################*/ extern int libcdsb_vset_find_string (vtype_set* x, const vtype_string* value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_array (vtype_set* x, const vtype_array* value, void* data, vset_access_callback, bool cut);
extern bool libcdsb_vset_insert (vtype_set* x, const void* value, vtype type) Nonnull__(1); extern int libcdsb_vset_find_list (vtype_set* x, const vtype_list* value, void* data, vset_access_callback, bool cut);
extern bool libcdsb_vset_attach (vtype_set* x, const void* value, vtype type) Nonnull__(1); extern int libcdsb_vset_find_map (vtype_set* x, const vtype_map* value, void* data, vset_access_callback, bool cut);
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_find_vset (vtype_set* x, const vtype_set* value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_foreach(vtype_set* x, void* data, vset_access_callback, rbforeach_t, bool flush) Nonnull__(1,3); extern int libcdsb_vset_find_boolean(vtype_set* x, vtype_bool value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_uint8 (vtype_set* x, vtype_uint8 value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_uint16 (vtype_set* x, vtype_uint16 value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_uint32 (vtype_set* x, vtype_uint32 value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_uint64 (vtype_set* x, vtype_uint64 value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_int8 (vtype_set* x, vtype_int8 value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_int16 (vtype_set* x, vtype_int16 value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_int32 (vtype_set* x, vtype_int32 value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_int64 (vtype_set* x, vtype_int64 value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_float (vtype_set* x, vtype_float value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_double (vtype_set* x, vtype_double value, void* data, vset_access_callback, bool cut);
extern int libcdsb_vset_find_ldouble(vtype_set* x, vtype_ldouble value, void* data, vset_access_callback, bool cut);
#endif /* LIBCDSB_SET_H */ #endif /* LIBCDSB_SET_H */

View File

@ -1,48 +1,88 @@
/* This software is licensed by the MIT License, see LICENSE file */ /* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "bits/__generics.h" #include "__generics.h"
#include "vtype.h" #include "vtype.h"
#include <uchar.h>
#ifndef LIBCDSB_STRING_H #ifndef LIBCDSB_STRING_H
#define LIBCDSB_STRING_H #define LIBCDSB_STRING_H
/*#####################################################################################################################*/ /*#####################################################################################################################*/
extern size_t string_slice (vtype_string* x, vtype_string* s, ssize_t index, size_t nchars, bool cut) Nonnull__(1,2); extern void string_init(vtype_string* x, const char* value) LIBCDSB_nt__ LIBCDSB_nn1__;
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* at_string (const vtype_string* s, ssize_t index) Nonnull__(1); extern char* string_at(const vtype_string* s, ssize_t index) LIBCDSB_nt__ LIBCDSB_nn1__;
extern bool string_slice(vtype_string* x, vtype_string* s, ssize_t index, size_t nchars, bool cut) LIBCDSB_nt__ LIBCDSB_nn12__;
#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(s, value) _LIBCDSB_GenericS(libcdsb_string, concat, value)(s, 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)
/*#####################################################################################################################*/ /*#####################################################################################################################*/
#define string_init(x, s) libcdsb_string_init (x, _LIBCDSB_to_cstring(s), 0) inline ssize_t libcdsb_string_indexof_string (const vtype_string* s, const vtype_string* arg) __attribute__((always_inline));
#define string_indexof(x, s) libcdsb_string_indexof(x, _LIBCDSB_to_cstring(s)) extern ssize_t libcdsb_string_indexof_cstring(const vtype_string* s, const char* arg) LIBCDSB_pure__ LIBCDSB_nn1__;
#define string_count(x, s) libcdsb_string_count (x, _LIBCDSB_to_cstring(s), 0) extern ssize_t libcdsb_string_indexof_char (const vtype_string* s, int arg) LIBCDSB_pure__ LIBCDSB_nn1__;
#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) inline size_t libcdsb_string_count_string (const vtype_string* s, const vtype_string* arg) __attribute__((always_inline));
#define string_lalign(x, n, c) libcdsb_string_align (x, n, c, -1) extern size_t libcdsb_string_count_cstring(const vtype_string* s, const char* arg) LIBCDSB_pure__ LIBCDSB_nn1__;
#define string_ralign(x, n, c) libcdsb_string_align (x, n, c, 1) extern size_t libcdsb_string_count_char (const vtype_string* s, int arg) LIBCDSB_pure__ LIBCDSB_nn1__;
#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) inline bool libcdsb_string_concat_string (vtype_string* x, const vtype_string* value) __attribute__((always_inline));
#define string_ltrim(x, s) libcdsb_string_trim (x, _LIBCDSB_to_cstring(s), -1) extern bool libcdsb_string_concat_cstring(vtype_string* x, const char* value) LIBCDSB_nt__ LIBCDSB_nn1__;
#define string_rtrim(x, s) libcdsb_string_trim (x, _LIBCDSB_to_cstring(s), 1) extern bool libcdsb_string_concat_char (vtype_string* x, int value) LIBCDSB_nt__ LIBCDSB_nn1__;
#define string_replace(x, s, d) libcdsb_string_replace(x, _LIBCDSB_to_cstring(s), 0, _LIBCDSB_to_cstring(d), 0, -1)
extern void libcdsb_string_trim_spaces(vtype_string* x, int direction) LIBCDSB_nt__ LIBCDSB_nn1__;
inline size_t libcdsb_string_replace_string_string (vtype_string* x, const vtype_string* src, const vtype_string* dest, size_t maxn) __attribute__((always_inline));
inline size_t libcdsb_string_replace_string_cstring (vtype_string* x, const vtype_string* src, const char* dest, size_t maxn) __attribute__((always_inline));
inline size_t libcdsb_string_replace_string_char (vtype_string* x, const vtype_string* src, int dest, size_t maxn) __attribute__((always_inline));
inline size_t libcdsb_string_replace_cstring_string (vtype_string* x, const char* src, const vtype_string* dest, size_t maxn) __attribute__((always_inline));
extern size_t libcdsb_string_replace_cstring_cstring(vtype_string* x, const char* src, const char* dest, size_t maxn) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t libcdsb_string_replace_cstring_char (vtype_string* x, const char* src, int dest, size_t maxn) LIBCDSB_nt__ LIBCDSB_nn1__;
inline size_t libcdsb_string_replace_char_string (vtype_string* x, int src, const vtype_string* dest, size_t maxn) __attribute__((always_inline));
extern size_t libcdsb_string_replace_char_cstring (vtype_string* x, int src, const char* dest, size_t maxn) LIBCDSB_nt__ LIBCDSB_nn1__;
extern size_t libcdsb_string_replace_char_char (vtype_string* x, int src, int dest, size_t maxn) LIBCDSB_nt__ LIBCDSB_nn1__;
/*#####################################################################################################################*/ /*#####################################################################################################################*/
inline void libcdsb_string_init (vtype_string* x, const char* s, size_t nmemb) Always_inline__ Nonnull__(1); inline ssize_t libcdsb_string_indexof_string(const vtype_string* s, const vtype_string* arg) {
extern bool libcdsb_string_concat (vtype_string* x, const char* s, size_t nmemb) Nonnull__(1); return string_indexof(s, arg->buffer);
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 void libcdsb_string_init (vtype_string* x, const char* s, size_t nmemb) { x->buffer = ((nmemb) ? libcdsb_strndup(s, nmemb) : libcdsb_strdup(s)); } inline size_t libcdsb_string_count_string(const vtype_string* s, const vtype_string* arg) {
return string_count(s, arg->buffer);
}
#endif /* LIBCDSB_STRING_H */ 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 */

View File

@ -5,8 +5,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdbool.h> #include <stdbool.h>
#include "bits/cstring.h" #include "__attributes.h"
#include "bits/memory.h"
#ifndef LIBCDSB_VTYPE_H #ifndef LIBCDSB_VTYPE_H
#define LIBCDSB_VTYPE_H #define LIBCDSB_VTYPE_H
@ -31,10 +30,10 @@ typedef enum libcdsb_value_types {
VTYPE_ARRAY = 15, VTYPE_ARRAY = 15,
VTYPE_LIST = 16, VTYPE_LIST = 16,
VTYPE_SET = 17, VTYPE_SET = 17,
VTYPE_DICT = 18,
LIBCDSB_VTYPE_TERMINATION, /* It must be at the end of the enum. Never be used */
} vtype; } vtype;
/*#####################################################################################################################*/
struct libcdsb_string { char* buffer; }; struct libcdsb_string { char* buffer; };
struct libcdsb_array { void* mem; size_t size; vtype type; }; struct libcdsb_array { void* mem; size_t size; vtype type; };
@ -43,9 +42,6 @@ struct libcdsb_map { struct libcdsb_map_node* root; vtype type; };
struct libcdsb_set { struct libcdsb_rbtree_node* root; vtype type; }; 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_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 void* vtype_pointer;
typedef bool vtype_bool; typedef bool vtype_bool;
@ -64,101 +60,82 @@ typedef float vtype_float;
typedef double vtype_double; typedef double vtype_double;
typedef long double vtype_ldouble; typedef long double vtype_ldouble;
typedef size_t vtype_hash;
typedef struct libcdsb_array vtype_array; typedef struct libcdsb_array vtype_array;
typedef struct libcdsb_map vtype_map; typedef struct libcdsb_map vtype_map;
typedef struct libcdsb_set vtype_set; typedef struct libcdsb_set vtype_set;
typedef struct libcdsb_list vtype_list; typedef struct libcdsb_list vtype_list;
typedef struct libcdsb_dict vtype_dict;
typedef struct libcdsb_string vtype_string; typedef struct libcdsb_string vtype_string;
extern const char* libcdsb_vtype_name (vtype t) Warn_unused_result__; /* Get utf8 chars count in string */
extern const char* libcdsb_vtype_stringify(const void* value, vtype t) Warn_unused_result__; extern size_t string_size(const vtype_string* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Get string size in bytes */
extern size_t string_nmemb(const vtype_string* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Get count of the array elements */
extern size_t array_size(const vtype_array* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Get array size in bytes */
extern size_t array_nmemb(const vtype_array* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Get count of the list elements */
extern size_t list_size(const vtype_list* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Get count of the map elements */
extern size_t map_size(const vtype_map* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/* Get count of the set elements */
extern size_t vset_size(const vtype_set* x) LIBCDSB_pure__ LIBCDSB_nn1__;
/*#####################################################################################################################*/
extern size_t string_size (const vtype_string* x) Pure__ Warn_unused_result__ Nonnull__(1); /* Cpmpare 2 strings */
extern size_t array_nmemb (const vtype_array* x) Pure__ Warn_unused_result__ Nonnull__(1); extern int string_compare(const vtype_string* s0, const vtype_string* s1) LIBCDSB_cmpattr__;
extern size_t list_size (const vtype_list* x) Pure__ Warn_unused_result__ Nonnull__(1); /* Compare 2 arrays */
extern size_t map_size (const vtype_map* x) Pure__ Warn_unused_result__ Nonnull__(1); extern int array_compare(const vtype_array* s0, const vtype_array* s1) LIBCDSB_cmpattr__;
extern size_t vset_size (const vtype_set* x) Pure__ Warn_unused_result__ Nonnull__(1); /* Compare 2 lists */
inline size_t string_nmemb (const vtype_string* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); extern int list_compare(const vtype_list* s0, const vtype_list* s1) LIBCDSB_cmpattr__;
inline size_t array_size (const vtype_array* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); /* Compare 2 maps */
inline size_t dict_size (const vtype_dict* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); extern int map_compare(const vtype_map* s0, const vtype_map* s1) LIBCDSB_cmpattr__;
inline size_t dict_capacity(const vtype_dict* x) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); /* Compare 2 sets */
extern int vset_compare(const vtype_set* s0, const vtype_set* s1) LIBCDSB_cmpattr__;
extern int string_case_compare(const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); /* Copy string to another */
extern int string_compare (const vtype_string* s0, const vtype_string* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); extern vtype_string string_copy(const vtype_string* s) LIBCDSB_cpyattr__;
extern int array_compare (const vtype_array* s0, const vtype_array* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); /* Copy array to another */
extern int list_compare (const vtype_list* s0, const vtype_list* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); extern vtype_array array_copy(const vtype_array* s) LIBCDSB_cpyattr__;
extern int map_compare (const vtype_map* s0, const vtype_map* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); /* Copy list to another */
extern int vset_compare (const vtype_set* s0, const vtype_set* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); extern vtype_list list_copy(const vtype_list* s) LIBCDSB_cpyattr__;
extern int dict_compare (const vtype_dict* s0, const vtype_dict* s1) Pure__ Warn_unused_result__ Nonnull__(1,2); /* Copy map to another */
extern vtype_map map_copy(const vtype_map* s) LIBCDSB_cpyattr__;
/* Copy set to another */
extern vtype_set vset_copy(const vtype_set* s) LIBCDSB_cpyattr__;
inline vtype_string string_copy (const vtype_string* s) Always_inline__ Pure__ Warn_unused_result__ Nonnull__(1); /* Duplicate string memory block */
extern vtype_array array_copy (const vtype_array* s) Pure__ Warn_unused_result__ Nonnull__(1); extern vtype_string* string_duplicate(const vtype_string* s) LIBCDSB_dupattr__;
extern vtype_list list_copy (const vtype_list* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Duplicate array memory block */
extern vtype_map map_copy (const vtype_map* s) Pure__ Warn_unused_result__ Nonnull__(1); extern vtype_array* array_duplicate(const vtype_array* s) LIBCDSB_dupattr__;
extern vtype_set vset_copy (const vtype_set* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Duplicate list memory block */
extern vtype_dict dict_copy (const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); extern vtype_list* list_duplicate(const vtype_list* s) LIBCDSB_dupattr__;
extern vtype_list dict_copy_keys(const vtype_dict* s) Pure__ Warn_unused_result__ Nonnull__(1); /* Duplicate map memory block */
#define map_copy_keys(s) vset_copy(_LIBCDSB_nothing(s)) extern vtype_map* map_duplicate(const vtype_map* s) LIBCDSB_dupattr__;
/* Duplicate set memory block */
extern vtype_set* vset_duplicate(const vtype_set* s) LIBCDSB_dupattr__;
inline vtype_string* string_duplicate (const vtype_string* s) Always_inline__ Warn_unused_result__ Nonnull__(1); /* Copy string and store result to the memory block */
extern vtype_array* array_duplicate (const vtype_array* s) Warn_unused_result__ Nonnull__(1); extern void string_copy_init(vtype_string* x, const vtype_string* s) LIBCDSB_nn12__;
extern vtype_list* list_duplicate (const vtype_list* s) Warn_unused_result__ Nonnull__(1); /* Copy array and store result to the memory block */
extern vtype_map* map_duplicate (const vtype_map* s) Warn_unused_result__ Nonnull__(1); extern void array_copy_init(vtype_array* x, const vtype_array* s) LIBCDSB_nn12__;
extern vtype_set* vset_duplicate (const vtype_set* s) Warn_unused_result__ Nonnull__(1); /* Copy list and store result to the memory block */
extern vtype_dict* dict_duplicate (const vtype_dict* s) Warn_unused_result__ Nonnull__(1); extern void list_copy_init(vtype_list* x, const vtype_list* s) LIBCDSB_nn12__;
extern vtype_list* dict_duplicate_keys(const vtype_dict* s) Warn_unused_result__ Nonnull__(1); /* Copy map and store result to the memory block */
#define map_duplicate_keys(s) vset_duplicate(_LIBCDSB_nothing(s)) extern void map_copy_init(vtype_map* x, const vtype_map* s) LIBCDSB_nn12__;
/* Copy set and store result to the memory block */
extern void vset_copy_init(vtype_set* x, const vtype_set* s) LIBCDSB_nn12__;
inline void string_copy_init (vtype_string* x, const vtype_string* s) Always_inline__ Nonnull__(1,2); /* Free string resources */
extern void array_copy_init (vtype_array* x, const vtype_array* s) Nonnull__(1,2); extern void string_free(vtype_string* x);
extern void list_copy_init (vtype_list* x, const vtype_list* s) Nonnull__(1,2); /* Free array resources */
extern void map_copy_init (vtype_map* x, const vtype_map* s) Nonnull__(1,2); extern void array_free(vtype_array* x);
extern void vset_copy_init (vtype_set* x, const vtype_set* s) Nonnull__(1,2); /* Free list resources */
extern void dict_copy_init (vtype_dict* x, const vtype_dict* s) Nonnull__(1,2); extern void list_free(vtype_list* x);
extern void dict_init_keys (vtype_list* x, const vtype_dict* s) Nonnull__(1,2); /* Free map resources */
#define map_copy_init_keys(x, s) vset_copy_init(x, _LIBCDSB_nothing(s)) extern void map_free(vtype_map* x);
/* Free set resources */
inline void string_free(vtype_string* x) Always_inline__; extern void vset_free(vtype_set* 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);
extern vtype_hash string_hash(const vtype_string* 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);
/*#####################################################################################################################*/
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) { if (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 */ #endif /* LIBCDSB_VTYPE_H */

@ -1 +1 @@
Subproject commit 350232189a32ef4762340e000bc21748e98b5544 Subproject commit 974541fd6e11dd6733f1be208f02f0445f18c7c6

View File

@ -1,12 +1,13 @@
/* This software is licensed by the MIT License, see LICENSE file */ /* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "../../include/bits/__attributes.h" #include "../../include/__attributes.h"
#define pure__ Pure__ #define throw__ HHTTPC_nt__
#define const__ __attribute__((const)) #define pure__ HHTTPC_pure__
#define leaf__ __attribute__((leaf)) #define const__ __attribute__((const)) HHTTPC_nt__
#define wur__ Warn_unused_result__ #define leaf__ __attribute__((leaf)) HHTTPC_nt__
#define inline__ Always_inline__ #define wur__ HHTTPC_wur__
#define inline__ __attribute__((always_inline))
#define ainline(...) inline __VA_ARGS__ inline__; inline __VA_ARGS__ #define ainline(...) inline __VA_ARGS__ inline__; inline __VA_ARGS__

View File

@ -7,7 +7,9 @@
#include <stdlib.h> #include <stdlib.h>
#include "../../include/vtype.h" #include "../../include/vtype.h"
#include "__attributes.h" #include "../../include/extra/memory.h"
#include "../../include/extra/cstring.h"
#include "../../include/extra/vtype.h"
#ifndef LIBCDSB_SRC_INTERNAL_INCLUDE #ifndef LIBCDSB_SRC_INTERNAL_INCLUDE
#define LIBCDSB_SRC_INTERNAL_INCLUDE #define LIBCDSB_SRC_INTERNAL_INCLUDE
@ -34,6 +36,8 @@
#define abs(v) _Generic((v), ldbl_t: fabsl, dbl_t: fabs, fl_t: fabsf)(v) #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_uint8 u8_t;
typedef vtype_uint16 u16_t; typedef vtype_uint16 u16_t;
typedef vtype_uint32 u32_t; typedef vtype_uint32 u32_t;
@ -53,51 +57,38 @@ typedef vtype_array arr_t;
typedef vtype_list list_t; typedef vtype_list list_t;
typedef vtype_map map_t; typedef vtype_map map_t;
typedef vtype_set set_t; typedef vtype_set set_t;
typedef vtype_dict dict_t;
typedef vtype_hash hash_t;
extern const size_t LIBCDSB_BUILTIN_VTYPE_SIZES[19]; extern int libcdsb_vtype_compare_values(const void* s0, vtype t0, const void* s1, vtype t1);
extern int libcdsb_vtype_compare_values_eq(const void* s0, const void* s1, vtype t);
extern int libcdsb_builtin_vtype_compare_values (const void* s0, vtype t0, const void* s1, vtype t1) pure__ wur__; #define vtype_stringify libcdsb_vtype_stringify
extern int libcdsb_builtin_vtype_compare_values_eq(const void* s0, const void* s1, vtype t) pure__ wur__; #define vtype_name libcdsb_vtype_name
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)) { #define vtype_compare libcdsb_vtype_compare_values
stack_t* p = x->prev; #define vtype_compare_eq libcdsb_vtype_compare_values_eq
if (!is_null(x->prev = malloc(sizeof(*x)))) { #define vtype_size(type) (LIBCDSB_VTYPE_SIZES[type])
x->prev->prev = p;
x->prev->value = v;
} else abort();
return x->prev; #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,\
#define aligned_alloc libcdsb_aalloc const str_t*: VTYPE_STRING, str_t*: VTYPE_STRING, str_t: VTYPE_STRING,\
#define malloc libcdsb_malloc const arr_t*: VTYPE_ARRAY, arr_t*: VTYPE_ARRAY, arr_t: VTYPE_ARRAY,\
#define calloc libcdsb_calloc const list_t*: VTYPE_LIST, list_t*: VTYPE_LIST, list_t: VTYPE_LIST,\
#define realloc libcdsb_realloc const map_t*: VTYPE_MAP, map_t*: VTYPE_MAP, map_t: VTYPE_MAP,\
#define free libcdsb_free const set_t*: VTYPE_SET, set_t*: VTYPE_SET, set_t: VTYPE_SET,\
#define stack_init libcdsb_stack_init const vtype_bool*: VTYPE_BOOLEAN, vtype_bool*: VTYPE_BOOLEAN, vtype_bool: VTYPE_BOOLEAN,\
#define stack_push libcdsb_stack_push const vtype_uint8*: VTYPE_UINT8, vtype_uint8*: VTYPE_UINT8, vtype_uint8: VTYPE_UINT8,\
#define stack_push_many libcdsb_stack_push_many const vtype_uint16*: VTYPE_UINT16, vtype_uint16*: VTYPE_UINT16, vtype_uint16: VTYPE_UINT16,\
#define stack_insert libcdsb_builtin_stack_insert const vtype_uint32*: VTYPE_UINT32, vtype_uint32*: VTYPE_UINT32, vtype_uint32: VTYPE_UINT32,\
#define stack_pop libcdsb_stack_pop const vtype_uint64*: VTYPE_UINT64, vtype_uint64*: VTYPE_UINT64, vtype_uint64: VTYPE_UINT64,\
#define stack_reverse libcdsb_stack_reverse const vtype_int8*: VTYPE_INT8, vtype_int8*: VTYPE_INT8, vtype_int8: VTYPE_INT8,\
#define stack_flush libcdsb_stack_flush const vtype_int16*: VTYPE_INT16, vtype_int16*: VTYPE_INT16, vtype_int16: VTYPE_INT16,\
#define strlen libcdsb_strlen const vtype_int32*: VTYPE_INT32, vtype_int32*: VTYPE_INT32, vtype_int32: VTYPE_INT32,\
#define strasciilen libcdsb_strasciilen const vtype_int64*: VTYPE_INT64, vtype_int64*: VTYPE_INT64, vtype_int64: VTYPE_INT64,\
#define strdup libcdsb_strdup const vtype_float*: VTYPE_FLOAT, vtype_float*: VTYPE_FLOAT, vtype_float: VTYPE_FLOAT,\
#define strndup libcdsb_strndup const vtype_double*: VTYPE_DOUBLE, vtype_double*: VTYPE_DOUBLE, vtype_double: VTYPE_DOUBLE,\
#define memndup libcdsb_memndup const vtype_ldouble*: VTYPE_LDOUBLE, vtype_ldouble*: VTYPE_LDOUBLE, vtype_ldouble: VTYPE_LDOUBLE))
#define vtype_stringify libcdsb_vtype_stringify
#define vtype_name libcdsb_vtype_name
#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 */ #endif /* LIBCDSB_SRC_INTERNAL_INCLUDE */

View File

@ -15,28 +15,18 @@ typedef struct libcdsb_rbtree_node {
short colored; short colored;
} rbnode_t; } rbnode_t;
extern rbnode_t LIBCDSB_BUILTIN_RBTREE_NODE_EMPTY[1]; extern rbnode_t LIBCDSB_RBTREE_NODE_EMPTY[1];
extern void* libcdsb_builtin_rbtree_node_create(void* value, rbnode_t* parent, int colored, int size) Nonnull__( 2); extern void* libcdsb_rbtree_node_create(void* value, rbnode_t* parent, int colored, int size);
extern void libcdsb_builtin_rbtree_node_fixup (rbnode_t** root, rbnode_t* node) Nonnull__(1,2); extern void libcdsb_rbtree_node_fixup (rbnode_t** root, rbnode_t* node);
extern rbnode_t* libcdsb_builtin_rbtree_node_delete(rbnode_t** root, rbnode_t* node) Nonnull__(1,2); extern rbnode_t* libcdsb_rbtree_node_delete(rbnode_t** root, rbnode_t* node);
extern stack_t libcdsb_builtin_rbtree_iter_inorder (rbnode_t** root, bool reverse); #define rbnode_empty ((rbnode_t*)LIBCDSB_RBTREE_NODE_EMPTY)
extern stack_t libcdsb_builtin_rbtree_iter_preorder (rbnode_t** root, bool reverse); #define rbnode_create(v, p, c) ((rbnode_t*)libcdsb_rbtree_node_create(v, p, c, sizeof(rbnode_t)))
extern stack_t libcdsb_builtin_rbtree_iter_postorder (rbnode_t** root, bool reverse); #define rbnode_fixup libcdsb_rbtree_node_fixup
extern stack_t libcdsb_builtin_rbtree_iter_breadth_first(rbnode_t** root, bool reverse); #define rbnode_delete libcdsb_rbtree_node_delete
#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_empty(n) ((n) == rbnode_empty)
#define rbnode_is_root(n) rbnode_is_empty((n)->parent) #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_breadth_first libcdsb_builtin_rbtree_iter_breadth_first
#endif /* LIBCDSB_SRC_INTERNAL_RBTREE_H */ #endif /* LIBCDSB_SRC_INTERNAL_RBTREE_H */

View File

@ -2,7 +2,6 @@
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "include.h" #include "include.h"
#include "assert.h"
#ifndef LIBCDSB_SRC_INTERNAL_VNODE_H #ifndef LIBCDSB_SRC_INTERNAL_VNODE_H
#define LIBCDSB_SRC_INTERNAL_VNODE_H #define LIBCDSB_SRC_INTERNAL_VNODE_H
@ -12,57 +11,27 @@
typedef union { typedef union {
void* ptr; bool b; void* ptr; bool b;
str_t s; arr_t a; list_t l; str_t s; arr_t a; list_t l;
map_t m; set_t vs; dict_t vd; map_t m; set_t vs;
u8_t u8; u16_t u16; u32_t u32; u64_t u64; u8_t u8; u16_t u16; u32_t u32; u64_t u64;
fl_t f; dbl_t d; ldbl_t ld; fl_t f; dbl_t d; ldbl_t ld;
} var_t; } var_t;
typedef void* vnode_t; typedef void* vnode_t;
extern vnode_t libcdsb_builtin_vnode_create (const void* value, vtype type) wur__; extern vnode_t libcdsb_vnode_create(const void* value, vtype type);
extern vnode_t libcdsb_builtin_vnode_create_target(vtype target_type, const void* value, vtype type) wur__; extern vnode_t libcdsb_vnode_create_target(vtype target_type, const void* value, vtype type);
extern void libcdsb_builtin_vnode_free(vnode_t* x, vtype type) Nonnull__(1); extern void libcdsb_vnode_free(vnode_t* x, vtype type);
extern void* libcdsb_builtin_vnode_peek(const vnode_t* x, vtype type) pure__ wur__ Nonnull__(1); extern void* libcdsb_vnode_peek(const vnode_t* x, vtype type);
ainline(void libcdsb_builtin_vnode_attach(vnode_t* node, const void* value, vtype type)) { #define vnode_create libcdsb_vnode_create
if (type < VTYPE_STRING) { #define vnode_tcreate libcdsb_vnode_create_target
*node = libcdsb_builtin_vnode_create(value, type); #define vnode_peek libcdsb_vnode_peek
} else if (sizeof(str_t) == sizeof(void*) && type == VTYPE_STRING) { #define vnode_free libcdsb_vnode_free
*node = *(char**)value;
} else {
*node = malloc(vtype_size(type));
memcpy(*node, value, vtype_size(type));
}
}
ainline(void libcdsb_builtin_vnode_tattach(vnode_t* node, vtype target_type, const void* value, vtype type)) {
if (type < VTYPE_STRING) {
*node = libcdsb_builtin_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_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(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_duplicate(vnode, type) 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_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) #define vnode_stringify(n, t) vtype_stringify(vnode_peek(n, t), t)

92
src/array/base.c Normal file
View File

@ -0,0 +1,92 @@
/* 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);
}
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);
}
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;
void (*free_)(void*);
assert(!is_null(p));
switch (x->type) {
default:
#ifndef NDEBUG
abort();
#endif
case VTYPE_STRING: free_ = (void*)string_free; break;
case VTYPE_ARRAY: free_ = (void*) array_free; break;
case VTYPE_LIST: free_ = (void*) list_free; break;
case VTYPE_MAP: free_ = (void*) map_free; break;
case VTYPE_SET: free_ = (void*) vset_free; break;
}
do {
free_(p);
p += vtype_size(x->type);
} while (--x->size);
}
free(x->mem);
memset(x, 0, sizeof(*x));
}
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;
}

View File

@ -1,35 +0,0 @@
/* 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;
}

View File

@ -1,46 +0,0 @@
/* 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_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;
}

View File

@ -4,6 +4,7 @@
#include "include.h" #include "include.h"
#include "../__internal/assert.h" #include "../__internal/assert.h"
arr_t array_copy(const arr_t* s) { arr_t array_copy(const arr_t* s) {
arr_t x = { .mem = 0, .size = 0, .type = 0 }; arr_t x = { .mem = 0, .size = 0, .type = 0 };
@ -13,13 +14,22 @@ arr_t array_copy(const arr_t* s) {
if (s->type >= VTYPE_STRING) { if (s->type >= VTYPE_STRING) {
void *p, *v, *e; void *p, *v, *e;
void (*init)(void*, const void*);
x.mem = p = malloc(x.size*vtype_size(x.type)); x.mem = p = malloc(x.size*vtype_size(x.type));
v = s->mem; v = s->mem;
e = array_end(&x); e = array_end(&x);
switch (s->type) { default: abort();
case VTYPE_STRING: init = (void*)string_copy_init; break;
case VTYPE_ARRAY: init = (void*) array_copy_init; break;
case VTYPE_LIST: init = (void*) list_copy_init; break;
case VTYPE_MAP: init = (void*) map_copy_init; break;
case VTYPE_SET: init = (void*) vset_copy_init; break;
}
do { do {
copy_init(p, v, s->type); init(p, v);
p += vtype_size(x.type); p += vtype_size(x.type);
v += vtype_size(x.type); v += vtype_size(x.type);
} while (p < e); } while (p < e);
@ -40,13 +50,22 @@ arr_t* array_duplicate(const arr_t* s) {
if (s->type >= VTYPE_STRING) { if (s->type >= VTYPE_STRING) {
void *p, *v, *e; void *p, *v, *e;
void (*init)(void*, const void*);
x->mem = p = malloc(x->size*vtype_size(x->type)); x->mem = p = malloc(x->size*vtype_size(x->type));
v = s->mem; v = s->mem;
e = array_end(x); e = array_end(x);
switch (s->type) { default: abort();
case VTYPE_STRING: init = (void*)string_copy_init; break;
case VTYPE_ARRAY: init = (void*) array_copy_init; break;
case VTYPE_LIST: init = (void*) list_copy_init; break;
case VTYPE_MAP: init = (void*) map_copy_init; break;
case VTYPE_SET: init = (void*) vset_copy_init; break;
}
do { do {
copy_init(p, v, s->type); init(p, v);
p += vtype_size(x->type); p += vtype_size(x->type);
v += vtype_size(x->type); v += vtype_size(x->type);
} while (p < e); } while (p < e);
@ -65,13 +84,22 @@ void array_copy_init(arr_t* x, const arr_t* s) {
if (s->type >= VTYPE_STRING) { if (s->type >= VTYPE_STRING) {
void *p, *v, *e; void *p, *v, *e;
void (*init)(void*, const void*);
x->mem = p = malloc(x->size*vtype_size(x->type)); x->mem = p = malloc(x->size*vtype_size(x->type));
v = s->mem; v = s->mem;
e = array_end(x); e = array_end(x);
switch (s->type) { default: abort();
case VTYPE_STRING: init = (void*)string_copy_init; break;
case VTYPE_ARRAY: init = (void*) array_copy_init; break;
case VTYPE_LIST: init = (void*) list_copy_init; break;
case VTYPE_MAP: init = (void*) map_copy_init; break;
case VTYPE_SET: init = (void*) vset_copy_init; break;
}
do { do {
copy_init(p, v, s->type); init(p, v);
p += vtype_size(x->type); p += vtype_size(x->type);
v += vtype_size(x->type); v += vtype_size(x->type);
} while (p < e); } while (p < e);
@ -97,13 +125,22 @@ size_t array_slice(arr_t* x, arr_t* s, ssize_t i, size_t n, _Bool cut) {
if (!cut && s->type >= VTYPE_STRING) { if (!cut && s->type >= VTYPE_STRING) {
void *p, *v, *e; void *p, *v, *e;
void (*init)(void*, const void*);
p = x->mem; p = x->mem;
v = array_internal_at(s, i); v = array_internal_at(s, i);
e = array_internal_at(x, n); e = array_internal_at(x, n);
switch (s->type) { default: abort();
case VTYPE_STRING: init = (void*)string_copy_init; break;
case VTYPE_ARRAY: init = (void*) array_copy_init; break;
case VTYPE_LIST: init = (void*) list_copy_init; break;
case VTYPE_MAP: init = (void*) map_copy_init; break;
case VTYPE_SET: init = (void*) vset_copy_init; break;
}
do { do {
copy_init(p, v, s->type); init(p, v);
p += vtype_size(x->type); p += vtype_size(x->type);
v += vtype_size(x->type); v += vtype_size(x->type);
} while (p < e); } while (p < e);

View File

@ -2,13 +2,45 @@
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "include.h" #include "include.h"
#include "../__internal/assert.h"
#include "../__internal/vnode.h"
void* at_array(const arr_t* x, ssize_t i) { ssize_t libcdsb_array_push(arr_t* x, const void* v, vtype t) {
if (i < 0 && (i += x->size) < 0) ssize_t i = x->size;
i = 0; vnode_t n = vnode_tcreate(x->type, v, t);
return x->mem + i * vtype_size(x->type);
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;
} }
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 libcdsb_array_get(vtype_array* x, ssize_t i, void* _, array_access_callback callback, vtype_bool cut) {
int r = 0; int r = 0;
@ -23,6 +55,7 @@ int libcdsb_array_get(vtype_array* x, ssize_t i, void* _, array_access_callback
return r; return r;
} }
int libcdsb_array_find(arr_t* x, const void* v, vtype t, void* _, array_access_callback callback, bool r, bool cut) { int libcdsb_array_find(arr_t* x, const void* v, vtype t, void* _, array_access_callback callback, bool r, bool cut) {
void *p; void *p;
ssize_t i; ssize_t i;
@ -64,6 +97,7 @@ int libcdsb_array_find(arr_t* x, const void* v, vtype t, void* _, array_access_c
return cmp; return cmp;
} }
int libcdsb_array_foreach(vtype_array* x, void* data, array_access_callback callback, bool flush) { int libcdsb_array_foreach(vtype_array* x, void* data, array_access_callback callback, bool flush) {
void* p; void* p;

64
src/array/generics.c Normal file
View File

@ -0,0 +1,64 @@
/* 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_string (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_array (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_list (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_map (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_vset (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_cstring(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_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_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_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)); }

View File

@ -2,26 +2,12 @@
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "../../include/array.h" #include "../../include/array.h"
#include "../../include/extra/array.h"
#include "../__internal/include.h" #include "../__internal/include.h"
#ifndef LIBCDSB_SRC_ARRAY_INCLUDE_H #ifndef LIBCDSB_SRC_ARRAY_INCLUDE_H
#define LIBCDSB_SRC_ARRAY_INCLUDE_H #define LIBCDSB_SRC_ARRAY_INCLUDE_H
ainline(void copy_init(void* x, const void* s, vtype t)) {
switch (t) {
default:
#ifndef NDEBUG
abort();
#endif
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;
}
}
ainline(void array_cut(arr_t* x, size_t i, size_t n)) { ainline(void array_cut(arr_t* x, size_t i, size_t n)) {
void* v = x->mem + i*vtype_size(x->type); void* v = x->mem + i*vtype_size(x->type);
void* e = v + n*vtype_size(x->type); void* e = v + n*vtype_size(x->type);

View File

@ -1,34 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "include.h"
#include "../__internal/assert.h"
void array_free(arr_t* x) {
if (is_null(x)) return;
if (x->size && x->type >= VTYPE_STRING) {
void* p = x->mem;
assert(!is_null(p));
do {
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);
}
free(x->mem);
memset(x, 0, sizeof(*x));
}

View File

@ -1,52 +0,0 @@
/* 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 {
type_assert(x->type, t);
copy_init(array_internal_at(x, i), v, t);
}
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 {
type_assert(x->type, t);
memcpy(array_internal_at(x, i), v, vtype_size(t));
}
return i;
}

View File

@ -4,42 +4,78 @@
#include "include.h" #include "include.h"
#include "../__internal/assert.h" #include "../__internal/assert.h"
typedef int (*compare_f)(const void*, const void*); 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");
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 uint8_compare (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 uint16_compare (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 uint32_compare (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 uint64_compare (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 int8_compare (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 int16_compare (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 int32_compare (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 int64_compare (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 float_compare (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 double_compare (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 ldouble_compare(const ldbl_t* s0, const ldbl_t* s1) { if (*s0 == *s1) return 0; return *s0 < *s1 ? -1 : 1; }
static compare_f libcdsb_builtin_get_comparator(vtype t) { static int (*COMPARE[16])(const void*, const void*) = {
static void* comparators[17] = { libcdsb_builtin_compare_uint8, libcdsb_builtin_compare_uint16, (void*) uint8_compare,
libcdsb_builtin_compare_uint32, libcdsb_builtin_compare_uint64, (void*) uint16_compare,
libcdsb_builtin_compare_int8, libcdsb_builtin_compare_int16, (void*) uint32_compare,
libcdsb_builtin_compare_int32, libcdsb_builtin_compare_int64, (void*) uint64_compare,
libcdsb_builtin_compare_float, libcdsb_builtin_compare_double, (void*) int8_compare,
libcdsb_builtin_compare_ldouble, string_compare, map_compare, (void*) int16_compare,
array_compare, list_compare, vset_compare, dict_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
};
/*#####################################################################################################################*/
ainline(int get_compare_index(vtype t)) {
if (t == VTYPE_POINTER) { if (t == VTYPE_POINTER) {
if (is_x64) t = VTYPE_UINT64; if (is_x64) t = VTYPE_UINT64;
else t = VTYPE_UINT32; else t = VTYPE_UINT32;
} else if (t == VTYPE_BOOLEAN) t = VTYPE_UINT8; } else if (t == VTYPE_BOOLEAN) t = VTYPE_UINT8;
return comparators[t - VTYPE_UINT8]; return t - VTYPE_UINT8;
} }
/*#####################################################################################################################*/ /*#####################################################################################################################*/
void array_sort(arr_t* x) { void array_sort(arr_t* x) {
int i = get_compare_index(x->type);
if (x->size > 1) if (x->size > 1)
qsort(x->mem, x->size, vtype_size(x->type), libcdsb_builtin_get_comparator(x->type)); qsort(x->mem, x->size, vtype_size(x->type), COMPARE[i]);
} }
void array_reverse(arr_t* x) { void array_reverse(arr_t* x) {

View File

@ -1,87 +0,0 @@
/* 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;
}

View File

@ -1,44 +0,0 @@
/* 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;
}

View File

@ -1,35 +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;
}

View File

@ -1,154 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "../list/include.h"
#include "include.h"
static inline dnode_t* libcdsb_builtin_duplicate(const dnode_t* s, dnode_t* p) {
dnode_t* x = malloc(sizeof(*x));
x->prev = p;
x->key = vnode_duplicate(&s->key, s->key_type);
x->value = vnode_duplicate(&s->value, s->value_type);
x->key_type = s->key_type;
x->value_type = s->value_type;
return x;
}
/*#####################################################################################################################*/
dict_t dict_copy(const dict_t* s) {
dict_t x;
size_t i;
dnode_t *n;
x.capacity = i = s->capacity;
x.size = s->size;
x.nodes = calloc(x.capacity, sizeof(*x.nodes));
while (i--) {
n = s->nodes[i];
while (!is_null(n)) {
x.nodes[i] = libcdsb_builtin_duplicate(n, x.nodes[i]);
n = n->prev;
}
}
return x;
}
dict_t* dict_duplicate(const dict_t* s) {
dict_t *x = malloc(sizeof(*x));
size_t i;
dnode_t *n;
x->capacity = i = s->capacity;
x->size = s->size;
x->nodes = calloc(x->capacity, sizeof(*x->nodes));
while (i--) {
n = s->nodes[i];
while (!is_null(n)) {
x->nodes[i] = libcdsb_builtin_duplicate(n, x->nodes[i]);
n = n->prev;
}
}
return x;
}
void dict_copy_init(dict_t* x, const dict_t* s) {
size_t i;
dnode_t *n;
x->capacity = i = s->capacity;
x->size = s->size;
x->nodes = calloc(x->capacity, sizeof(*x->nodes));
while (i--) {
n = s->nodes[i];
while (!is_null(n)) {
x->nodes[i] = libcdsb_builtin_duplicate(n, x->nodes[i]);
n = n->prev;
}
}
}
list_t libcdsb_dict_copy_keys(const dict_t* s) {
list_t x;
dnode_t *c;
size_t i;
i = s->capacity;
list_init(&x);
while (i--) {
c = s->nodes[i];
while (!is_null(c)) {
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;
}
}
return x;
}
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;
list_init(x);
while (i--) {
c = s->nodes[i];
while (!is_null(c)) {
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;
}
}
return x;
}
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;
list_init(x);
while (i--) {
c = s->nodes[i];
while (!is_null(c)) {
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;
}
}
}

View File

@ -1,30 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "../../include/dict.h"
#include "../__internal/assert.h"
#include "../__internal/rbtree.h"
#ifndef LIBCDSB_SRC_DICT_INCLUDE_H
#define LIBCDSB_SRC_DICT_INCLUDE_H
#ifndef DICT_CAPACITY_BLOCK
#define CAPACITY_BLOCK 100
#else
#define CAPACITY_BLOCK DICT_CAPACITY_BLOCK
#endif
#define REBUILD_POINT_MAX 0.65
typedef struct libcdsb_dict_node {
struct libcdsb_dict_node* prev;
vnode_t key;
vnode_t value;
u16_t key_type;
u16_t value_type;
} dnode_t;
#endif /* LIBCDSB_SRC_DICT_INCLUDE_H */

View File

@ -1,20 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "include.h"
void dict_free(dict_t* x) {
if (is_null(x)) return;
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));
}

View File

@ -1,118 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "../../include/list.h"
#include "include.h"
static void libcdsb_builtin_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;
libcdsb_builtin_rehash(s, capacity);
return true;
}
bool libcdsb_dict_update(dict_t* x, const void* k, vtype kt, const void* v, vtype vt, void* dt, dict_access_callback callback) {
dnode_t *c, **p;
if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX)
libcdsb_builtin_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) {
if (!callback) callback(vnode_peek(&c->key, c->key_type), c->key_type,
vnode_peek(&c->value, c->value_type), c->value_type, dt);
vnode_free(&c->value, c->value_type);
c->value = vnode_create(v, c->value_type = vt);
return true;
} else c = c->prev;
}
c = malloc(sizeof(*c));
c->prev = *p;
c->key = vnode_create(k, c->key_type = kt);
c->value = vnode_create(v, 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, void* dt, dict_access_callback callback) {
dnode_t *c, **p;
if (!x->capacity || (double)x->size / x->capacity > REBUILD_POINT_MAX)
libcdsb_builtin_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) {
if (!callback) callback(vnode_peek(&c->key, c->key_type), c->key_type,
vnode_peek(&c->value, c->value_type), c->value_type, dt);
vnode_free(&c->key, c->key_type);
vnode_free(&c->value, c->value_type);
vnode_attach(&c->key, k, c->key_type = kt);
vnode_attach(&c->value, v, c->value_type = vt);
return true;
} else c = c->prev;
}
(c = malloc(sizeof(*c)))->prev = *p;
vnode_attach(&c->key, k, c->key_type = kt);
vnode_attach(&c->value, v, c->value_type = vt);
*p = c;
++x->size;
return false;
}

View File

@ -2,13 +2,12 @@
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include <stdlib.h> #include <stdlib.h>
#include "../include/extra/cstring.h"
#include "__internal/include.h" #include "__internal/include.h"
#undef aligned_alloc #undef aligned_alloc
#undef malloc #undef malloc
#undef realloc #undef realloc
#undef calloc #undef calloc
#undef free
void* libcdsb_aalloc(size_t a, size_t n) { void* libcdsb_aalloc(size_t a, size_t n) {
void* x; void* x;
@ -56,9 +55,6 @@ char* libcdsb_strdup(const char* s) {
void* x; void* x;
size_t n; size_t n;
if (is_null(s))
return nullptr;
if ((x = malloc(n = strlen(s) + 1))) if ((x = malloc(n = strlen(s) + 1)))
return memcpy(x, s, n); return memcpy(x, s, n);
abort(); abort();
@ -74,7 +70,3 @@ char* libcdsb_strndup(const char* s, size_t n) {
} }
abort(); abort();
} }
void libcdsb_free(void* s) {
free(s);
}

56
src/extra-stack.c Normal file
View File

@ -0,0 +1,56 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stdlib.h>
#include "__internal/include.h"
#undef malloc
void libcdsb_stack_init(stack_t* x) {
memset(x, 0, sizeof(*x));
}
void libcdsb_stack_push(stack_t* x, void* value) {
stack_t* n;
if (x->value) {
if (!(n = malloc(sizeof(*n))))
abort();
n->prev = x->prev;
n->value = x->value;
x->prev = n;
}
x->value = value;
}
void* libcdsb_stack_pop(stack_t* x) {
stack_t* n;
void* v;
v = x->value;
if (x->prev) {
n = x->prev;
x->prev = n->prev;
x->value = n->value;
free(n);
} else x->value = 0;
return v;
}
void libcdsb_stack_flush(stack_t* stack) {
stack_t* c;
while (stack->prev) {
c = stack->prev;
stack->prev = c->prev;
free(c);
}
stack->value = 0;
}

View File

@ -1,27 +1,9 @@
/* This software is licensed by the MIT License, see LICENSE file */ /* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "../modules/libunic/include.h" #include "../include/extra/cstring.h"
#include "__internal/include.h" #include "__internal/include.h"
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 (LIBCDSB_BUILTIN_COUNTER > 15)
LIBCDSB_BUILTIN_COUNTER = 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 LIBCDSB_BUILTIN_BUFFER[LIBCDSB_BUILTIN_COUNTER++];
}
size_t libcdsb_strlen(const char* s) { size_t libcdsb_strlen(const char* s) {
static const size_t m = (sizeof(size_t) == 8) ? 0x8080808080808080UL : 0x80808080UL; static const size_t m = (sizeof(size_t) == 8) ? 0x8080808080808080UL : 0x80808080UL;
static const size_t d = (sizeof(size_t) == 8) ? 0x0101010101010101UL : 0x01010101UL; static const size_t d = (sizeof(size_t) == 8) ? 0x0101010101010101UL : 0x01010101UL;

77
src/list/base.c Normal file
View File

@ -0,0 +1,77 @@
/* 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));
}
/*#####################################################################################################################*/
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;
}
}
}

View File

@ -1,36 +0,0 @@
/* 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;
}
}
}

View File

@ -1,57 +0,0 @@
/* 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;
}

View File

@ -3,6 +3,34 @@
#include "include.h" #include "include.h"
/*#####################################################################################################################*/
static void init_first(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 push_next(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 list_copy(const list_t* s) {
list_t x; list_t x;
lnode_t* c; lnode_t* c;
@ -13,16 +41,15 @@ list_t list_copy(const list_t* s) {
if (is_null(c)) if (is_null(c))
return x; return x;
libcdsb_builtin_init(&x, vnode_duplicate(&c->node, c->type), c->type); init_first(&x, vnode_duplicate(&c->node, c->type), c->type);
while (!is_null(c = c->next)) { while (!is_null(c = c->next)) {
libcdsb_builtin_push(&x, vnode_duplicate(&c->node, c->type), c->type); push_next(&x, vnode_duplicate(&c->node, c->type), c->type);
} }
return x; return x;
} }
list_t* list_duplicate(const list_t* s) { list_t* list_duplicate(const list_t* s) {
list_t* x; list_t* x;
lnode_t* c; lnode_t* c;
@ -33,16 +60,15 @@ list_t* list_duplicate(const list_t* s) {
if (is_null(c)) if (is_null(c))
return x; return x;
libcdsb_builtin_init(x, vnode_duplicate(&c->node, c->type), c->type); init_first(x, vnode_duplicate(&c->node, c->type), c->type);
while (!is_null(c = c->next)) { while (!is_null(c = c->next)) {
libcdsb_builtin_push(x, vnode_duplicate(&c->node, c->type), c->type); push_next(x, vnode_duplicate(&c->node, c->type), c->type);
} }
return x; return x;
} }
void list_copy_init(list_t* x, const list_t* s) { void list_copy_init(list_t* x, const list_t* s) {
lnode_t* c; lnode_t* c;
@ -52,13 +78,14 @@ void list_copy_init(list_t* x, const list_t* s) {
if (is_null(c)) if (is_null(c))
return; return;
libcdsb_builtin_init(x, vnode_duplicate(&c->node, c->type), c->type); init_first(x, vnode_duplicate(&c->node, c->type), c->type);
while (!is_null(c = c->next)) { while (!is_null(c = c->next)) {
libcdsb_builtin_push(x, vnode_duplicate(&c->node, c->type), c->type); push_next(x, vnode_duplicate(&c->node, c->type), c->type);
} }
} }
/*#####################################################################################################################*/
void list_extend(list_t* x, const list_t* s) { void list_extend(list_t* x, const list_t* s) {
lnode_t* c; lnode_t* c;
@ -69,7 +96,7 @@ void list_extend(list_t* x, const list_t* s) {
return; return;
if (is_null(x->first)) { if (is_null(x->first)) {
libcdsb_builtin_init(x, vnode_duplicate(&c->node, c->type), c->type); init_first(x, vnode_duplicate(&c->node, c->type), c->type);
c = c->next; c = c->next;
if (is_null(c)) if (is_null(c))
@ -77,11 +104,12 @@ void list_extend(list_t* x, const list_t* s) {
} }
do { do {
libcdsb_builtin_push(x, vnode_duplicate(&c->node, c->type), c->type); push_next(x, vnode_duplicate(&c->node, c->type), c->type);
} while (!is_null(c = c->next)); } while (!is_null(c = c->next));
} }
size_t list_slice(list_t* x, list_t* s, ssize_t i, size_t n, _Bool cut) { size_t list_slice(list_t* x, list_t* s, ssize_t i, size_t n, _Bool cut) {
lnode_t* c; lnode_t* c;
@ -130,13 +158,13 @@ size_t list_slice(list_t* x, list_t* s, ssize_t i, size_t n, _Bool cut) {
else r -= n; else r -= n;
if (!cut) { if (!cut) {
libcdsb_builtin_init(x, vnode_duplicate(&c->node, c->type), c->type); init_first(x, vnode_duplicate(&c->node, c->type), c->type);
while ((c = c->next) != e) { while ((c = c->next) != e) {
libcdsb_builtin_push(x, vnode_duplicate(&c->node, c->type), c->type); push_next(x, vnode_duplicate(&c->node, c->type), c->type);
} }
libcdsb_builtin_push(x, vnode_duplicate(&e->node, e->type), e->type); push_next(x, vnode_duplicate(&e->node, e->type), e->type);
} else { } else {
if (c->prev) { if (c->prev) {
c->prev->next = e->next; c->prev->next = e->next;

View File

@ -3,7 +3,7 @@
#include "include.h" #include "include.h"
static void libcdsb_builtin_cut(list_t* s, lnode_t* cur) { static void lnode_cut(list_t* s, lnode_t* cur) {
vnode_free(&cur->node, cur->type); vnode_free(&cur->node, cur->type);
@ -18,8 +18,79 @@ static void libcdsb_builtin_cut(list_t* s, lnode_t* cur) {
free(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) { int libcdsb_list_get(vtype_list* x, ssize_t i, void* _, list_access_callback callback, bool cut) {
ldir_t dir; ldir_t dir;
@ -45,7 +116,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; i = (callback) ? callback(vnode_peek(&c->node, c->type), i, c->type, _) : 0;
if (cut) libcdsb_builtin_cut(x, c); if (cut) lnode_cut(x, c);
return i; return i;
} }
@ -67,7 +138,7 @@ int libcdsb_list_find(vtype_list* x, const void* v, vtype t, void* _, list_acces
if (cmp == 0) { if (cmp == 0) {
i = (callback) ? callback(vnode_peek(&c->node, c->type), (r)?~i:i, c->type, _) : 0; i = (callback) ? callback(vnode_peek(&c->node, c->type), (r)?~i:i, c->type, _) : 0;
if (cut) libcdsb_builtin_cut(x, c); if (cut) lnode_cut(x, c);
return i; return i;
} }

64
src/list/generics.c Normal file
View File

@ -0,0 +1,64 @@
/* 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_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_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_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); }

View File

@ -1,7 +1,7 @@
/* This software is licensed by the MIT License, see LICENSE file */ /* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "../../include/list.h" #include "../../include/extra/list.h"
#include "../__internal/vnode.h" #include "../__internal/vnode.h"
#ifndef LIBCDSB_SRC_LIST_INCLUDE_H #ifndef LIBCDSB_SRC_LIST_INCLUDE_H
@ -20,31 +20,6 @@ typedef struct libcdsb_list_node {
vtype type; vtype type;
} lnode_t; } 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_dir(cur, d) (&((cur)->prev))[(d)>>1]
#define ldir_inv(cur, d) (&((cur)->prev))[(d)&1] #define ldir_inv(cur, d) (&((cur)->prev))[(d)&1]

View File

@ -1,22 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "include.h"
void list_free(list_t* x) {
lnode_t* c;
lnode_t* next;
if (is_null(x)) return;
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));
}

View File

@ -1,102 +0,0 @@
/* 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, void* dt, list_access_callback callback) {
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 {
if (callback) callback(vnode_peek(&c->node, c->type), -1, c->type, dt);
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, void* dt, list_access_callback callback) {
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 {
if (callback) callback(vnode_peek(&c->node, c->type), -1, c->type, dt);
vnode_free(&c->node, c->type);
}
vnode_attach(&c->node, v, c->type = t);
return true;
}

View File

@ -3,7 +3,9 @@
#include "include.h" #include "include.h"
static inline void libcdsb_builtin_swap(lnode_t* s0, lnode_t* s1) { /*#####################################################################################################################*/
static inline void lnode_swap(lnode_t* s0, lnode_t* s1) {
vnode_t v = s0->node; vnode_t v = s0->node;
vtype t = s0->type; vtype t = s0->type;
@ -14,15 +16,13 @@ static inline void libcdsb_builtin_swap(lnode_t* s0, lnode_t* s1) {
s1->type = t; s1->type = t;
} }
/*#####################################################################################################################*/
void list_sort(list_t* x) { void list_sort(list_t* x) {
stack_t z; stack_t z = { .prev = 0, .value = x->last};
lnode_t *l; lnode_t *l;
lnode_t *r; lnode_t *r;
stack_init(&z); stack_push(&z, x->first);
stack_push_many(&z, 2, x->last, x->first);
while (z.value) { while (z.value) {
@ -36,12 +36,12 @@ void list_sort(list_t* x) {
for (lnode_t* c = l; c != r; c = c->next) { for (lnode_t* c = l; c != r; c = c->next) {
if (lnode_compare(c, r) <= 0) { if (lnode_compare(c, r) <= 0) {
p = (is_null(p)) ? l : p->next; p = (is_null(p)) ? l : p->next;
libcdsb_builtin_swap(p, c); lnode_swap(p, c);
} }
} }
p = (is_null(p)) ? l : p->next; p = (is_null(p)) ? l : p->next;
libcdsb_builtin_swap(p, r); lnode_swap(p, r);
stack_push(&z, r); stack_push(&z, r);
stack_push(&z, p->next); stack_push(&z, p->next);
@ -57,7 +57,7 @@ void list_reverse(list_t* x) {
lnode_t *r = x->last; lnode_t *r = x->last;
while (l != r) { while (l != r) {
libcdsb_builtin_swap(l, r); lnode_swap(l, r);
if ((r = r->prev) == l) if ((r = r->prev) == l)
break; break;
l = l->next; l = l->next;

View File

@ -1,114 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#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;
int cmp;
c = x->root;
while (!mnode_is_empty(c)) {
key = vnode_peek(&c->key, x->type);
cmp = vtype_compare(k, t, key, x->type);
if (cmp == 0) {
cmp = (callback) ? callback(key, x->type, vnode_peek(&c->value, c->type), c->type, _) : 0;
if (cut) {
c = mnode_delete(&x->root, c);
vnode_free(&c->key, x->type);
vnode_free(&c->value, c->type);
free(c);
}
return cmp;
} else c = (cmp < 0) ? c->left : c->right;
}
return -1;
}
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;
reverse = type&RBFOREACH_REVERSE;
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;
default:
case RBFOREACH_BREADTH_FIRST: if (reverse || flush) {
iter = miter_breadth_first(&x->root, type&RBFOREACH_REVERSE);
break;
} else return libcdsb_builtin_foreach(x, data, callback);
}
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(&n->value, x->type);
free(n);
}
}
if (flush) x->root = mnode_empty;
return r;
}

108
src/map/base.c Normal file
View File

@ -0,0 +1,108 @@
/* 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;
mnode_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 = { .prev = 0, .value = x->root };
size_t n = 0;
rbnode_t* c;
if (!mnode_is_empty(x->root)) {
while ((c = stack_pop(&z))) {
++n;
if (!rbnode_is_empty(c->left))
stack_push(&z, c->left);
if (!rbnode_is_empty(c->right))
stack_push(&z, c->right);
}
}
return n;
}
int map_compare(const map_t* s0, const map_t* s1) {
stack_t z = { .prev = 0, .value = 0 };
vtype t = s0->type;
int c = 0;
if (s0 == s1 || s0->root == s1->root) return 0;
if (s0->type != s1->type) return s0->type - s1->type;
stack_push(&z, s1->root);
stack_push(&z, s0->root);
for (mnode_t *c0, *c1;!is_null(z.value);) {
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 ((c = vnode_compare(c0->key, t, c1->key, t)) || (c = vnode_compare(c0->value, c0->type, c1->value, c1->type))) {
if (c0->left == c1->right) {
c = vnode_compare(c1->key, t, c0->right->key, t );
if (!c) c = vnode_compare(c1->value, c1->type, c0->right->value, c0->type);
if (!c) c = vnode_compare(c1->left->key, t, c0->key, t );
if (!c) c = vnode_compare(c1->left->value, c1->type, c0->value, c0->type);
} else if (c0->right == c1->left) {
c = vnode_compare(c0->key, t, c1->right->key, t );
if (!c) c = vnode_compare(c0->value, c0->type, c1->right->value, c1->type);
if (!c) c = vnode_compare(c0->left->key, t, c1->key, t );
if (!c) c = vnode_compare(c0->left->value, c0->type, c1->value, c1->type);
}
if (c) { stack_flush(&z); return c; }
} else {
stack_push(&z, c1->right);
stack_push(&z, c0->right);
stack_push(&z, c1->left);
stack_push(&z, c0->left);
}
}
return 0;
}

View File

@ -1,56 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "include.h"
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;
}
/*#####################################################################################################################*/
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 = libcdsb_builtin_compare(c0, c1, s0->type))) {
if (c0->left == c1->right) { // == mnode_empty
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 = libcdsb_builtin_compare(c0, c1->right, s0->type);
if (!cmp) cmp = libcdsb_builtin_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;
}

View File

@ -1,70 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "include.h"
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;
}
/*#####################################################################################################################*/
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 = libcdsb_builtin_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 += libcdsb_builtin_hash(c1, s->type);
return (hash ^ v) + VTYPE_MAP;
}

View File

@ -3,30 +3,14 @@
#include "include.h" #include "include.h"
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);
x->type = s->type;
x->value = vnode_duplicate(&s->value, s->type);
return x;
}
/*#####################################################################################################################*/
map_t map_copy(const map_t* s) { map_t map_copy(const map_t* s) {
map_t x; map_t x = { .type = s->type };
stack_t z; stack_t z = { .prev = 0, .value = s->root };
vtype t = s->type;
stack_init(&z);
stack_push(&z, s->root);
x.type = s->type;
if (!mnode_is_empty(s->root)) { if (!mnode_is_empty(s->root)) {
x.root = libcdsb_builtin_duplicate(s->root, mnode_empty, s->type); x.root = mnode_create(vnode_duplicate(&s->root->value, t), rbnode_empty, 0);
stack_push(&z, x.root); stack_push(&z, x.root);
do { do {
@ -34,13 +18,21 @@ map_t map_copy(const map_t* s) {
mnode_t *p1 = stack_pop(&z); mnode_t *p1 = stack_pop(&z);
if (!mnode_is_empty(p1->left)) { if (!mnode_is_empty(p1->left)) {
p0->left = libcdsb_builtin_duplicate(p1->left, p0, s->type); p0->left = mnode_create(vnode_duplicate(&p1->left->key, t), p0, p1->left->colored);
stack_push_many(&z, 2, p1->left, p0->left); p0->left->type = p1->left->type;
p0->left->value = vnode_duplicate(&p1->left->value, p1->left->type);
stack_push(&z, p1->left);
stack_push(&z, p0->left);
} }
if (!mnode_is_empty(p1->right)) { if (!mnode_is_empty(p1->right)) {
p0->right = libcdsb_builtin_duplicate(p1->right, p0, s->type); p0->right = mnode_create(vnode_duplicate(&p1->right->key, t), p0, p1->right->colored);
stack_push_many(&z, 2, p1->right, p0->right); p0->right->type = p1->right->type;
p0->right->value = vnode_duplicate(&p1->right->value, p1->right->type);
stack_push(&z, p1->right);
stack_push(&z, p0->right);
} }
} while (!is_null(z.value)); } while (!is_null(z.value));
@ -53,17 +45,12 @@ map_t map_copy(const map_t* s) {
map_t* map_duplicate(const map_t* s) { map_t* map_duplicate(const map_t* s) {
map_t* x; map_t* x = malloc(sizeof(*x));
stack_t z; stack_t z = { .prev = 0, .value = s->root };
vtype t = x->type = s->type;
stack_init(&z);
stack_push(&z, s->root);
x = malloc(sizeof(*x));
x->type = s->type;
if (!mnode_is_empty(s->root)) { if (!mnode_is_empty(s->root)) {
x->root = libcdsb_builtin_duplicate(s->root, mnode_empty, s->type); x->root = mnode_create(vnode_duplicate(&s->root->value, t), rbnode_empty, 0);
stack_push(&z, x->root); stack_push(&z, x->root);
do { do {
@ -71,13 +58,21 @@ map_t* map_duplicate(const map_t* s) {
mnode_t *p1 = stack_pop(&z); mnode_t *p1 = stack_pop(&z);
if (!mnode_is_empty(p1->left)) { if (!mnode_is_empty(p1->left)) {
p0->left = libcdsb_builtin_duplicate(p1->left, p0, s->type); p0->left = mnode_create(vnode_duplicate(&p1->left->key, t), p0, p1->left->colored);
stack_push_many(&z, 2, p1->left, p0->left); p0->left->type = p1->left->type;
p0->left->value = vnode_duplicate(&p1->left->value, p1->left->type);
stack_push(&z, p1->left);
stack_push(&z, p0->left);
} }
if (!mnode_is_empty(p1->right)) { if (!mnode_is_empty(p1->right)) {
p0->right = libcdsb_builtin_duplicate(p1->right, p0, s->type); p0->right = mnode_create(vnode_duplicate(&p1->right->key, t), p0, p1->right->colored);
stack_push_many(&z, 2, p1->right, p0->right); p0->right->type = p1->right->type;
p0->right->value = vnode_duplicate(&p1->right->value, p1->right->type);
stack_push(&z, p1->right);
stack_push(&z, p0->right);
} }
} while (!is_null(z.value)); } while (!is_null(z.value));
@ -90,15 +85,11 @@ map_t* map_duplicate(const map_t* s) {
void map_copy_init(map_t* x, const map_t* s) { void map_copy_init(map_t* x, const map_t* s) {
stack_t z; stack_t z = { .prev = 0, .value = s->root };
vtype t = x->type = s->type;
stack_init(&z);
stack_push(&z, s->root);
x->type = s->type;
if (!mnode_is_empty(s->root)) { if (!mnode_is_empty(s->root)) {
x->root = libcdsb_builtin_duplicate(s->root, mnode_empty, s->type); x->root = mnode_create(vnode_duplicate(&s->root->value, t), rbnode_empty, 0);
stack_push(&z, x->root); stack_push(&z, x->root);
do { do {
@ -106,13 +97,21 @@ void map_copy_init(map_t* x, const map_t* s) {
mnode_t *p1 = stack_pop(&z); mnode_t *p1 = stack_pop(&z);
if (!mnode_is_empty(p1->left)) { if (!mnode_is_empty(p1->left)) {
p0->left = libcdsb_builtin_duplicate(p1->left, p0, s->type); p0->left = mnode_create(vnode_duplicate(&p1->left->key, t), p0, p1->left->colored);
stack_push_many(&z, 2, p1->left, p0->left); p0->left->type = p1->left->type;
p0->left->value = vnode_duplicate(&p1->left->value, p1->left->type);
stack_push(&z, p1->left);
stack_push(&z, p0->left);
} }
if (!mnode_is_empty(p1->right)) { if (!mnode_is_empty(p1->right)) {
p0->right = libcdsb_builtin_duplicate(p1->right, p0, s->type); p0->right = mnode_create(vnode_duplicate(&p1->right->key, t), p0, p1->right->colored);
stack_push_many(&z, 2, p1->right, p0->right); p0->right->type = p1->right->type;
p0->right->value = vnode_duplicate(&p1->right->value, p1->right->type);
stack_push(&z, p1->right);
stack_push(&z, p0->right);
} }
} while (!is_null(z.value)); } while (!is_null(z.value));

121
src/map/extra.c Normal file
View File

@ -0,0 +1,121 @@
/* 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;
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, kt);
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;
int cmp;
c = x->root;
while (!mnode_is_empty(c)) {
key = vnode_peek(&c->key, x->type);
cmp = vtype_compare(k, t, key, x->type);
if (cmp == 0) {
cmp = (callback) ? callback(key, x->type, vnode_peek(&c->value, c->type), c->type, _) : 0;
if (cut) {
c = mnode_delete(&x->root, c);
vnode_free(&c->key, x->type);
vnode_free(&c->value, c->type);
free(c);
}
return cmp;
} else c = (cmp < 0) ? c->left : c->right;
}
return -1;
}
int libcdsb_map_foreach(map_t* x, void* dt, map_access_callback callback, bool flush) {
stack_t z = { .prev = 0, .value = x->root };
int r = 0;
mnode_t* c;
if (mnode_is_empty(x->root)) return 0;
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);
if (flush) {
vnode_free(&c->key, x->type);
vnode_free(&c->value, c->type);
free(c);
}
}
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);
return r;
}

404
src/map/generics.c Normal file
View File

@ -0,0 +1,404 @@
/* 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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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)); }

View File

@ -1,7 +1,7 @@
/* This software is licensed by the MIT License, see LICENSE file */ /* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "../../include/map.h" #include "../../include/extra/map.h"
#include "../__internal/assert.h" #include "../__internal/assert.h"
#include "../__internal/rbtree.h" #include "../__internal/rbtree.h"
@ -19,25 +19,22 @@ typedef struct libcdsb_map_node {
vnode_t value; vnode_t value;
} mnode_t; } 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, 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, 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, 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, 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_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*)rbnode_empty) static_assert(offsetof(struct libcdsb_set, root) == offsetof(struct libcdsb_map, root), "Implementation assert");
#define mnode_create(k, p, c) ((mnode_t*)libcdsb_builtin_rbtree_node_create(k, (rbnode_t*)p, c, sizeof(mnode_t))) static_assert(offsetof(struct libcdsb_set, type) == offsetof(struct libcdsb_map, type), "Implementation assert");
#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_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_is_empty(n) ((n) == mnode_empty) #define mnode_is_empty(n) ((n) == mnode_empty)
#define mnode_is_root(n) mnode_is_empty((n)->parent) #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_breadth_first(x, reverse) rbiter_breadth_first((void*)x, reverse)
#endif /* LIBCDSB_SRC_MAP_INCLUDE_H */ #endif /* LIBCDSB_SRC_MAP_INCLUDE_H */

View File

@ -1,43 +0,0 @@
/* 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;
if (is_null(x)) return;
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;
}

View File

@ -1,93 +0,0 @@
/* 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, void* dt, map_access_callback callback) {
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) {
if (callback) callback(vnode_peek(&n->key, x->type), x->type,
vnode_peek(&n->value, n->type), n->type, dt);
vnode_free(&n->value, n->type);
n->value = vnode_create(v, 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, void* dt, map_access_callback callback) {
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) {
if (callback) callback(vnode_peek(&n->key, x->type), x->type,
vnode_peek(&n->value, n->type), n->type, dt);
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;
}

View File

@ -1,95 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stdarg.h>
#include <stdlib.h>
#include "__internal/include.h"
#undef malloc
#undef free
void libcdsb_queue_init(queue_t* x) {
memset(x, 0, sizeof(*x));
}
void libcdsb_queue_push(queue_t* x, void* value) {
stack_t* n;
if (!(n = malloc(sizeof(*n))))
abort();
n->prev = 0;
if (!x->back) {
x->front = n;
x->back = n;
} else x->back->prev = n;
n->value = value;
}
void libcdsb_queue_push_many(queue_t* x, size_t c, ...) {
va_list args;
stack_t* n;
va_start(args, c);
if (c) {
if (!x->back) {
if (!(n = malloc(sizeof(*n))))
abort();
x->front = n;
x->back = n;
n->prev = 0;
n->value = va_arg(args, void*);
--c;
}
while (c--) {
if (!(n = malloc(sizeof(*n))))
abort();
x->back->prev = n;
n->prev = 0;
n->value = va_arg(args, void*);
}
}
va_end(args);
}
void* libcdsb_queue_pop(queue_t* x) {
stack_t* n;
void* v;
if (x->front) {
n = x->front;
v = n->value;
if (!(x->front = n->prev)) {
x->back = 0;
}
free(n);
} else v = 0;
return v;
}
void libcdsb_queue_flush(queue_t* x) {
stack_t* c;
c = x->front;
while (x->front) {
c = x->front;
x->front = c->prev;
free(c);
}
x->back = 0;
}

View File

@ -11,12 +11,19 @@ typedef enum libcdsb_rbtree_node_direction {
#define rbdir_dir(cur, d) (&((cur)->left))[(d)>>1] #define rbdir_dir(cur, d) (&((cur)->left))[(d)>>1]
#define rbdir_inv(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 void libcdsb_builtin_rotate(rbnode_t **x, rbnode_t *c, rbdir_t d) { /*#####################################################################################################################*/
static inline void rotate(rbnode_t **x, rbnode_t *c, rbdir_t d) {
rbnode_t* n = rbdir_inv(c, d); rbnode_t* n = rbdir_inv(c, d);
rbdir_inv(c, d) = rbdir_dir(n, d); rbdir_inv(c, d) = rbdir_dir(n, d);
@ -34,8 +41,7 @@ static void libcdsb_builtin_rotate(rbnode_t **x, rbnode_t *c, rbdir_t d) {
c->parent = n; 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 (!rbnode_is_root(c)) {
if (c->parent->left == c) { if (c->parent->left == c) {
c->parent->left = n; c->parent->left = n;
@ -45,7 +51,10 @@ static void libcdsb_builtin_replace(rbnode_t** x, rbnode_t* c, rbnode_t* n) {
} }
static void libcdsb_builtin_fixup(rbnode_t** x, rbnode_t* n) { /*#####################################################################################################################*/
static void delete_fixup(rbnode_t** x, rbnode_t* n) {
rbdir_t d; rbdir_t d;
rbnode_t *s, *p; rbnode_t *s, *p;
@ -89,16 +98,8 @@ static void libcdsb_builtin_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; rbnode_t *n, *t;
int s; int s;
@ -134,14 +135,14 @@ rbnode_t* libcdsb_builtin_rbtree_node_delete(rbnode_t** x, rbnode_t* c) {
t->left = c->left; t->left = c->left;
} }
if (!s) fixup(x, n); if (!s) delete_fixup(x, n);
return c; return c;
} }
void libcdsb_builtin_rbtree_node_fixup(rbnode_t** x, rbnode_t* n) { void libcdsb_rbtree_node_fixup(rbnode_t** x, rbnode_t* n) {
rbdir_t d[2]; rbdir_t d[2];
rbnode_t *u, *p, *gp; rbnode_t *u, *p, *gp;
@ -180,7 +181,7 @@ void libcdsb_builtin_rbtree_node_fixup(rbnode_t** x, rbnode_t* n) {
} }
void* libcdsb_builtin_rbtree_node_create(void* v, rbnode_t* p, int c, int n) { void* libcdsb_rbtree_node_create(void* v, rbnode_t* p, int c, int n) {
rbnode_t* x; rbnode_t* x;
x = malloc(n); x = malloc(n);
@ -193,144 +194,3 @@ void* libcdsb_builtin_rbtree_node_create(void* v, rbnode_t* p, int c, int n) {
return x; return x;
} }
stack_t libcdsb_builtin_rbtree_iter_inorder(rbnode_t** root, bool reverse) {
stack_t z, *cur;
rbnode_t *n;
memset(&z, 0, sizeof(z));
if (rbnode_is_empty(n = *root))
return z;
while (!rbnode_is_empty(n)) {
stack_insert(&z, n);
n = n->left;
}
cur = z.prev;
z.value = z.prev->value;
z.prev = z.prev->prev;
free(cur);
cur = &z;
while ((cur = cur->prev)) {
n = cur->value;
if (!rbnode_is_empty(n->right)) {
n = n->right;
while (!rbnode_is_empty(n)) {
stack_insert(cur, n);
n = n->left;
}
}
}
if (reverse)
stack_reverse(&z);
return z;
}
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_breadth_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;
}

View File

@ -1,114 +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 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;
int cmp;
c = x->root;
while (!rbnode_is_empty(c)) {
val = vnode_peek(&c->value, x->type);
cmp = vtype_compare(v, t, val, x->type);
if (cmp == 0) {
cmp = (callback) ? callback(val, x->type, _) : 0;
if (cut) {
c = rbnode_delete(&x->root, c);
vnode_free(&c->value, x->type);
free(c);
}
return cmp;
} else c = (cmp < 0) ? c->left : c->right;
}
return -1;
}
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;
reverse = type&RBFOREACH_REVERSE;
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_breadth_first(&x->root, type&RBFOREACH_REVERSE);
break;
} else return libcdsb_builtin_foreach(x, data, callback);
}
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(&n->value, x->type);
free(n);
}
}
if (flush) x->root = rbnode_empty;
return r;
}

103
src/set/base.c Normal file
View File

@ -0,0 +1,103 @@
/* 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;
rbnode_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 = { .prev = 0, .value = x->root };
size_t n = 0;
rbnode_t* c;
if (!rbnode_is_empty(x->root)) {
while ((c = stack_pop(&z))) {
++n;
if (!rbnode_is_empty(c->left))
stack_push(&z, c->left);
if (!rbnode_is_empty(c->right))
stack_push(&z, c->right);
}
}
return n;
}
int vset_compare(const set_t* s0, const set_t* s1) {
stack_t z = { .prev = 0, .value = 0 };
vtype t = s0->type;
int c = 0;
if (s0 == s1 || s0->root == s1->root) return 0;
if (s0->type != s1->type) return s0->type - s1->type;
stack_push(&z, s1->root);
stack_push(&z, s0->root);
for (rbnode_t *c0, *c1;!is_null(z.value);) {
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 ((c = vnode_compare(c0->value, t, c1->value, t))) {
if (c0->left == c1->right) {
c = vnode_compare(c1->value, t, c0->right->value, t);
if (!c) c = vnode_compare(c1->left->value, t, c0->value, t);
} else if (c0->right == c1->left) {
c = vnode_compare(c0->value, t, c1->right->value, t);
if (!c) c = vnode_compare(c0->left->value, t, c1->value, t);
}
if (c) { stack_flush(&z); return c; }
} else {
stack_push(&z, c1->right);
stack_push(&z, c0->right);
stack_push(&z, c1->left);
stack_push(&z, c0->left);
}
}
return 0;
}

View File

@ -1,55 +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 libcdsb_builtin_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 = libcdsb_builtin_compare(c0, c1, s0->type))) {
if (c0->left == c1->right) { // == rbnode_empty
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 = libcdsb_builtin_compare(c0, c1->right, s0->type);
if (!cmp) cmp = libcdsb_builtin_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;
}

View File

@ -1,71 +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 hash_t libcdsb_builtin_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 = libcdsb_builtin_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 += libcdsb_builtin_hash(c1, s->type);
return (hash ^ v) + VTYPE_SET;
}

View File

@ -6,16 +6,12 @@
set_t vset_copy(const set_t* s) { set_t vset_copy(const set_t* s) {
set_t x; set_t x = { .type = s->type };
stack_t z; stack_t z = { .prev = 0, .value = s->root };
vtype t = s->type;
stack_init(&z);
stack_push(&z, s->root);
x.type = s->type;
if (!rbnode_is_empty(s->root)) { if (!rbnode_is_empty(s->root)) {
x.root = rbnode_create(vnode_duplicate(&s->root->value, s->type), rbnode_empty, 0); x.root = rbnode_create(vnode_duplicate(&s->root->value, t), rbnode_empty, 0);
stack_push(&z, x.root); stack_push(&z, x.root);
do { do {
@ -23,13 +19,15 @@ set_t vset_copy(const set_t* s) {
rbnode_t *p1 = stack_pop(&z); rbnode_t *p1 = stack_pop(&z);
if (!rbnode_is_empty(p1->left)) { if (!rbnode_is_empty(p1->left)) {
p0->left = rbnode_create(vnode_duplicate(&p1->left->value, s->type), p0, p1->left->colored); p0->left = rbnode_create(vnode_duplicate(&p1->left->value, t), p0, p1->left->colored);
stack_push_many(&z, 2, p1->left, p0->left); stack_push(&z, p1->left);
stack_push(&z, p0->left);
} }
if (!rbnode_is_empty(p1->right)) { if (!rbnode_is_empty(p1->right)) {
p0->right = rbnode_create(vnode_duplicate(&p1->right->value, s->type), p0, p1->right->colored); p0->right = rbnode_create(vnode_duplicate(&p1->right->value, t), p0, p1->right->colored);
stack_push_many(&z, 2, p1->right, p0->right); stack_push(&z, p1->right);
stack_push(&z, p0->right);
} }
} while (!is_null(z.value)); } while (!is_null(z.value));
@ -42,17 +40,12 @@ set_t vset_copy(const set_t* s) {
set_t* vset_duplicate(const set_t* s) { set_t* vset_duplicate(const set_t* s) {
set_t* x; set_t* x = malloc(sizeof(*x));
stack_t z; stack_t z = { .prev = 0, .value = s->root };
vtype t = x->type = s->type;
stack_init(&z);
stack_push(&z, s->root);
x = malloc(sizeof(*x));
x->type = s->type;
if (!rbnode_is_empty(s->root)) { if (!rbnode_is_empty(s->root)) {
x->root = rbnode_create(vnode_duplicate(&s->root->value, s->type), rbnode_empty, 0); x->root = rbnode_create(vnode_duplicate(&s->root->value, t), rbnode_empty, 0);
stack_push(&z, x->root); stack_push(&z, x->root);
do { do {
@ -60,13 +53,15 @@ set_t* vset_duplicate(const set_t* s) {
rbnode_t *p1 = stack_pop(&z); rbnode_t *p1 = stack_pop(&z);
if (!rbnode_is_empty(p1->left)) { if (!rbnode_is_empty(p1->left)) {
p0->left = rbnode_create(vnode_duplicate(&p1->left->value, s->type), p0, p1->left->colored); p0->left = rbnode_create(vnode_duplicate(&p1->left->value, t), p0, p1->left->colored);
stack_push_many(&z, 2, p1->left, p0->left); stack_push(&z, p1->left);
stack_push(&z, p0->left);
} }
if (!rbnode_is_empty(p1->right)) { if (!rbnode_is_empty(p1->right)) {
p0->right = rbnode_create(vnode_duplicate(&p1->right->value, s->type), p0, p1->right->colored); p0->right = rbnode_create(vnode_duplicate(&p1->right->value, t), p0, p1->right->colored);
stack_push_many(&z, 2, p1->right, p0->right); stack_push(&z, p1->right);
stack_push(&z, p0->right);
} }
} while (!is_null(z.value)); } while (!is_null(z.value));
@ -79,15 +74,11 @@ set_t* vset_duplicate(const set_t* s) {
void vset_copy_init(set_t* x, const set_t* s) { void vset_copy_init(set_t* x, const set_t* s) {
stack_t z; stack_t z = { .prev = 0, .value = s->root };
vtype t = x->type = s->type;
stack_init(&z);
stack_push(&z, s->root);
x->type = s->type;
if (!rbnode_is_empty(s->root)) { if (!rbnode_is_empty(s->root)) {
x->root = rbnode_create(vnode_duplicate(&s->root->value, s->type), rbnode_empty, 0); x->root = rbnode_create(vnode_duplicate(&s->root->value, t), rbnode_empty, 0);
stack_push(&z, x->root); stack_push(&z, x->root);
do { do {
@ -95,13 +86,15 @@ void vset_copy_init(set_t* x, const set_t* s) {
rbnode_t *p1 = stack_pop(&z); rbnode_t *p1 = stack_pop(&z);
if (!rbnode_is_empty(p1->left)) { if (!rbnode_is_empty(p1->left)) {
p0->left = rbnode_create(vnode_duplicate(&p1->left->value, s->type), p0, p1->left->colored); p0->left = rbnode_create(vnode_duplicate(&p1->left->value, t), p0, p1->left->colored);
stack_push_many(&z, 2, p1->left, p0->left); stack_push(&z, p1->left);
stack_push(&z, p0->left);
} }
if (!rbnode_is_empty(p1->right)) { if (!rbnode_is_empty(p1->right)) {
p0->right = rbnode_create(vnode_duplicate(&p1->right->value, s->type), p0, p1->right->colored); p0->right = rbnode_create(vnode_duplicate(&p1->right->value, t), p0, p1->right->colored);
stack_push_many(&z, 2, p1->right, p0->right); stack_push(&z, p1->right);
stack_push(&z, p0->right);
} }
} while (!is_null(z.value)); } while (!is_null(z.value));

109
src/set/extra.c Normal file
View File

@ -0,0 +1,109 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "../../include/extra/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;
int cmp;
c = x->root;
while (!rbnode_is_empty(c)) {
val = vnode_peek(&c->value, x->type);
cmp = vtype_compare(v, t, val, x->type);
if (cmp == 0) {
cmp = (callback) ? callback(val, x->type, _) : 0;
if (cut) {
c = rbnode_delete(&x->root, c);
vnode_free(&c->value, x->type);
free(c);
}
return cmp;
} else c = (cmp < 0) ? c->left : c->right;
}
return -1;
}
int libcdsb_vset_foreach(set_t* x, void* data, vset_access_callback callback, bool flush) {
stack_t z = { .prev = 0, .value = x->root };
int r = 0;
rbnode_t* c;
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);
if (flush) {
vnode_free(&c->value, x->type);
free(c);
}
}
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);
return r;
}

45
src/set/generics.c Normal file
View File

@ -0,0 +1,45 @@
/* 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_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_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)); }

View File

@ -1,41 +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"
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;
if (is_null(x)) return;
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;
}

View File

@ -1,74 +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"
#include "../__internal/assert.h"
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;
vnode_tattach(&vn, x->type, v, t);
n = x->root;
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;
}

View File

@ -1,122 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stdarg.h>
#include <stdlib.h>
#include "__internal/include.h"
#undef malloc
#undef free
void libcdsb_stack_init(stack_t* x) {
memset(x, 0, sizeof(*x));
}
void libcdsb_stack_push(stack_t* x, void* value) {
stack_t* n;
if (x->value) {
if (!(n = malloc(sizeof(*n))))
abort();
n->prev = x->prev;
n->value = x->value;
x->prev = n;
}
x->value = value;
}
void libcdsb_stack_push_many(stack_t* x, size_t c, ...) {
va_list args;
stack_t* n;
va_start(args, c);
if (c) {
if (!x->value) {
x->value = va_arg(args, void*);
--c;
}
while (c--) {
if (!(n = malloc(sizeof(*n))))
abort();
n->prev = x->prev;
n->value = x->value;
x->prev = n;
x->value = va_arg(args, void*);
}
}
va_end(args);
}
void* libcdsb_stack_pop(stack_t* x) {
stack_t* n;
void* v;
v = x->value;
if (x->prev) {
n = x->prev;
x->prev = n->prev;
x->value = n->value;
free(n);
} else x->value = 0;
return v;
}
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 (x->prev) {
c = x->prev;
x->prev = c->prev;
free(c);
}
x->value = 0;
}

View File

@ -1,61 +0,0 @@
/* 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;
}

126
src/string/base.c Normal file
View File

@ -0,0 +1,126 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include "include.h"
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));
}

View File

@ -1,66 +0,0 @@
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <ctype.h>
#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;
}

View File

@ -1,60 +0,0 @@
/* 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;
}

View File

@ -1,78 +0,0 @@
/* 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;
}

142
src/string/extra-align.c Normal file
View File

@ -0,0 +1,142 @@
/* 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;
}

89
src/string/extra-split.c Normal file
View File

@ -0,0 +1,89 @@
/* 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;
}

View File

@ -1,59 +1,60 @@
/* This software is licensed by the MIT License, see LICENSE file */ /* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include <ctype.h>
#include "include.h" #include "include.h"
static void libcdsb_builtin_replace(str_t* x, char* p, size_t n, const char* v, size_t vn) { int string_compare_case_insensitive(const str_t* s0, const str_t* s1) {
if (n != vn) { const char *p0, *p1, *t0, *t1;
size_t l = strlen(x->buffer); ssize_t n0, n1;
u32_t uc0, uc1;
if (n < vn) { if (s0 == s1) return 0;
char* t = x->buffer;
x->buffer = realloc(x->buffer, l + (vn - n) + 1); p0 = s0->buffer;
p = x->buffer + (p - t); 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;
} }
memmove(p+vn, p+n, l - (p+n - x->buffer) + 1);
} }
memcpy(p, v, vn); n0 = *(unsigned char*)p0 - *(unsigned char*)p1;
return n0;
} }
/*#####################################################################################################################*/ /*#####################################################################################################################*/
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) { size_t string_to_lower(str_t* x) {
char ps[4]; char ps[4];
char *es, *p, *e; char *es, *p, *e;
u32_t uc0, uc1; u32_t uc0, uc1;
@ -75,7 +76,7 @@ size_t string_to_lower(str_t* x) {
es = tochar_unicode(ps, uc1); es = tochar_unicode(ps, uc1);
if (!is_null(es)) { if (!is_null(es)) {
libcdsb_builtin_replace(x, p, e-p, ps, es-ps); libcdsb_string_replace(x, p, e-p, ps, es-ps);
++n; ++n;
} }
} }
@ -111,7 +112,7 @@ size_t string_to_upper(str_t* x) {
es = tochar_unicode(ps, uc1); es = tochar_unicode(ps, uc1);
if (!is_null(es)) { if (!is_null(es)) {
libcdsb_builtin_replace(x, p, e-p, ps, es-ps); libcdsb_string_replace(x, p, e-p, ps, es-ps);
++n; ++n;
} }
} }
@ -145,7 +146,7 @@ size_t string_capitalize(str_t* x) {
es = tochar_unicode(ps, uc1); es = tochar_unicode(ps, uc1);
if (!is_null(es)) { if (!is_null(es)) {
libcdsb_builtin_replace(x, p, e-p, ps, es-ps); libcdsb_string_replace(x, p, e-p, ps, es-ps);
++n; ++n;
} }
} }
@ -163,7 +164,7 @@ size_t string_capitalize(str_t* x) {
es = tochar_unicode(ps, uc1); es = tochar_unicode(ps, uc1);
if (!is_null(es)) { if (!is_null(es)) {
libcdsb_builtin_replace(x, p, e-p, ps, es-ps); libcdsb_string_replace(x, p, e-p, ps, es-ps);
++n; ++n;
} }
} }
@ -174,3 +175,54 @@ size_t string_capitalize(str_t* x) {
return n; 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++);
}
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);
}

171
src/string/get.c Normal file
View File

@ -0,0 +1,171 @@
/* 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;
}
bool string_slice(str_t* x, str_t* s, ssize_t i, size_t c, bool cut) {
char *e, *p, *v;
memset(x, 0, sizeof(*x));
if (!c) return true;
p = string_at(s, i);
if (is_null(p) || (e = p + strlen(p)) > p + c)
return false;
v = p;
do { v = next_char(v); } while (--c && v < e);
if (!c) {
x->buffer = strndup(p, v - p);
if (cut) {
memmove(p, v, strlen(v) + 1);
}
return true;
} else return false;
}
/*#####################################################################################################################*/
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;
}

View File

@ -2,20 +2,20 @@
/* Copyright © 2022 Gregory Lirent */ /* Copyright © 2022 Gregory Lirent */
#include "../../modules/libunic/include.h" #include "../../modules/libunic/include.h"
#include "../../include/string.h" #include "../../include/extra/string.h"
#include "../__internal/include.h" #include "../__internal/include.h"
#ifndef LIBCDSB_SRC_STRING_INCLUDE_H #ifndef LIBCDSB_SRC_STRING_INCLUDE_H
#define LIBCDSB_SRC_STRING_INCLUDE_H #define LIBCDSB_SRC_STRING_INCLUDE_H
ainline(char* libcdsb_builtin_next_char(char* s)) { ainline(char* next_char(char* s)) {
int cs = charsize(s); int cs = charsize(s);
if (cs) return s + cs; if (cs) return s + cs;
return ++s; return ++s;
} }
ainline(char* libcdsb_builtin_prev_char(char* s)) { ainline(char* prev_char(char* s)) {
if (*(--s)&0x80) { if (*(--s)&0x80) {
char* p = s; char* p = s;
@ -29,7 +29,4 @@ ainline(char* libcdsb_builtin_prev_char(char* s)) {
return s; return s;
} }
#define next_char libcdsb_builtin_next_char
#define prev_char libcdsb_builtin_prev_char
#endif /* LIBCDSB_SRC_STRING_INCLUDE_H */ #endif /* LIBCDSB_SRC_STRING_INCLUDE_H */

View File

@ -1,275 +0,0 @@
/* 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;
}

223
src/string/replace.c Normal file
View File

@ -0,0 +1,223 @@
/* 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;
}

160
src/string/trim.c Normal file
View File

@ -0,0 +1,160 @@
/* 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;
}

Some files were not shown because too many files have changed in this diff Show More