Minor fixes & modifications

This commit is contained in:
2022-08-19 20:00:10 +03:00
parent 7618294078
commit 08aebcc15b
11 changed files with 72 additions and 98 deletions
+2 -4
View File
@@ -4,14 +4,11 @@
#include "include.h"
#include "../__internal/assert.h"
size_t array_size (const arr_t* x) {
return x->size;
}
size_t array_nmemb(const arr_t* x) {
return x->size*vtype_size(x->type);
}
hash_t array_hash(const arr_t* s) {
hash_t hash = 0;
@@ -26,6 +23,7 @@ hash_t array_hash(const arr_t* s) {
return hash + VTYPE_ARRAY;
}
size_t libcdsb_array_count(const arr_t* s, const void* v, vtype t) {
void *p;
void *e;
-6
View File
@@ -23,12 +23,6 @@ static inline type_free get_type_free(vtype type) {
/*#####################################################################################################################*/
void array_init(arr_t* x, vtype t) {
x->type = t;
x->size = 0;
x->mem = nullptr;
}
void array_free(arr_t* x) {
if (x->size && x->type >= VTYPE_STRING) {
void* p = x->mem;
+5 -8
View File
@@ -20,16 +20,15 @@ ssize_t libcdsb_array_insert(arr_t* x, const void* v, vtype t) {
if (vtype_size(x->type) > sizeof(vnode_t))
vnode_free(&n, x->type);
} else if (x->type == t) {
} else {
type_assert(x->type, t);
get_type_initializer(t)(array_internal_at(x, i), v);
}
#ifndef NDEBUG
else abort();
#endif
return i;
}
ssize_t libcdsb_array_attach(arr_t* x, const void* v, vtype t) {
ssize_t i;
vnode_t n;
@@ -44,12 +43,10 @@ ssize_t libcdsb_array_attach(arr_t* x, const void* v, vtype t) {
if (vtype_size(x->type) > sizeof(vnode_t))
vnode_free(&n, x->type);
} else if (x->type == t) {
} else {
type_assert(x->type, t);
memcpy(array_internal_at(x, i), v, vtype_size(t));
}
#ifndef NDEBUG
else abort();
#endif
return i;
}
-4
View File
@@ -3,10 +3,6 @@
#include "include.h"
void dict_init(dict_t* x) {
memset(x, 0, sizeof(*x));
}
void dict_free(dict_t* x) {
while (x->capacity--) {
-5
View File
@@ -3,11 +3,6 @@
#include "include.h"
void list_init(list_t* x) {
memset(x, 0, sizeof(*x));
}
void list_free(list_t* x) {
lnode_t* c;
lnode_t* next;
+1 -10
View File
@@ -92,16 +92,7 @@ bool libcdsb_list_attach(list_t* x, ssize_t i, const void* v, vtype t, int ins)
} else vnode_free(&c->node, c->type);
if (t < VTYPE_STRING) {
c->node = vnode_create(v, t);
} else if (sizeof(str_t) == sizeof(void*) && t == VTYPE_STRING) {
c->node = *(char**)v;
} else {
c->node = malloc(vtype_size(t));
memcpy(c->node, v, vtype_size(t));
}
c->type = t;
vnode_attach(&c->node, v, c->type = t);
return true;
}
+35 -49
View File
@@ -9,12 +9,43 @@ bool libcdsb_vset_insert(set_t* x, const void* v, vtype t) {
int cmp;
rbnode_t* n;
rbnode_t* p;
if (!rbnode_is_empty(n = x->root)) {
do {
p = n;
cmp = vtype_compare(v, t, vnode_peek(&n->value, t), t);
if (cmp == 0) return false;
n = (cmp < 0) ? n->left : n->right;
} while (!rbnode_is_empty(n));
n = rbnode_create(nullptr, p, 1);
if (cmp < 0) p->left = n;
else p->right = n;
if (!rbnode_is_root(p))
rbnode_fixup(&x->root, n);
} else n = x->root = rbnode_create(nullptr, rbnode_empty, 0);
n->value = vnode_tcreate(x->type, v, t);
return true;
}
bool libcdsb_vset_attach(set_t* x, const void* v, vtype t) {
int cmp;
rbnode_t* n;
rbnode_t* p;
vnode_t vn;
n = x->root;
vn = vnode_tcreate(x->type, v, t);
t = x->type;
v = vnode_peek(&vn, t);
vnode_tattach(&vn, x->type, v, t);
n = x->root;
t = x->type;
v = vnode_peek(&vn, t);
if (!rbnode_is_empty(n)) {
do {
@@ -41,48 +72,3 @@ bool libcdsb_vset_insert(set_t* x, const void* v, vtype t) {
return true;
}
bool libcdsb_vset_attach(set_t* x, const void* v, vtype t) {
int cmp;
rbnode_t* n;
rbnode_t* p;
n = x->root;
t = x->type;
if (!rbnode_is_empty(n)) {
do {
p = n;
cmp = vtype_compare(v, t, vnode_peek(&n->value, t), t);
if (cmp == 0) return false;
n = (cmp < 0) ? n->left : n->right;
} while (!rbnode_is_empty(n));
n = rbnode_create(nullptr, p, 1);
if (cmp < 0) p->left = n;
else p->right = n;
if (!rbnode_is_root(p))
rbnode_fixup(&x->root, n);
} else n = x->root = rbnode_create(nullptr, rbnode_empty, 0);
if (t < VTYPE_STRING) {
n->value = vnode_tcreate(x->type, v, t);
} else {
type_assert(x->type, t);
if (sizeof(str_t) == sizeof(void*) && t == VTYPE_STRING) {
n->value = *(char**)v;
} else {
n->value = malloc(vtype_size(t));
memcpy(n->value, v, vtype_size(t));
}
}
return true;
}