Refacor set

This commit is contained in:
Gregory Lirent 2022-06-08 09:58:49 +03:00
parent 2f0a3a3c8e
commit a95f3f18ea
2 changed files with 17 additions and 17 deletions

View File

@ -5,13 +5,13 @@
#include "../__internal/rbtree.h"
void vset_init(vtype_set* x, vtype t) {
void vset_init(set_t* x, vtype t) {
x->root = rbnode_empty;
x->type = t;
}
void vset_free(vtype_set* x) {
void vset_free(set_t* x) {
rbnode_t* t;
rbnode_t* c;
@ -42,11 +42,12 @@ void vset_free(vtype_set* x) {
}
size_t vset_size(const vtype_set* x) {
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))
@ -54,12 +55,13 @@ size_t vset_size(const vtype_set* x) {
if (!rbnode_is_empty(c->right))
stack_push(&z, c->right);
}
}
return n;
}
int vset_compare(const vtype_set* s0, const vtype_set* s1) {
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;

View File

@ -4,7 +4,7 @@
#include "../../include/set.h"
#include "../__internal/rbtree.h"
vtype_set vset_copy(const vtype_set* s) {
set_t vset_copy(const set_t* s) {
set_t x = { .type = s->type };
stack_t z = { .prev = 0, .value = s->root };
@ -15,10 +15,8 @@ vtype_set vset_copy(const vtype_set* s) {
stack_push(&z, x.root);
do {
rbnode_t *p0, *p1;
p0 = stack_pop(&z);
p1 = stack_pop(&z);
rbnode_t *p0 = stack_pop(&z);
rbnode_t *p1 = stack_pop(&z);
if (!rbnode_is_empty(p1->left)) {
p0->left = rbnode_create(vnode_duplicate(&p1->left->value, t), p0, p1->left->colored);
@ -40,7 +38,7 @@ vtype_set vset_copy(const vtype_set* s) {
}
vtype_set* vset_duplicate(const vtype_set* s) {
set_t* vset_duplicate(const set_t* s) {
set_t* x = malloc(sizeof(*x));
stack_t z = { .prev = 0, .value = s->root };
@ -74,7 +72,7 @@ vtype_set* vset_duplicate(const vtype_set* s) {
}
void vset_copy_init(vtype_set* x, const vtype_set* s) {
void vset_copy_init(set_t* x, const set_t* s) {
stack_t z = { .prev = 0, .value = s->root };
vtype t = x->type = s->type;