65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
/* This software is licensed by the MIT License, see LICENSE file */
|
|
/* Copyright © 2022 Gregory Lirent */
|
|
|
|
#include "../../include/set.h"
|
|
#include "../__internal/rbtree.h"
|
|
|
|
/*#####################################################################################################################*/
|
|
|
|
hash_t vset_hash(const set_t* s) {
|
|
return rbtree_hash(s->root, nullptr, (void*)&s->type) + VTYPE_SET;
|
|
}
|
|
|
|
void vset_init(set_t* x, vtype t) {
|
|
x->root = rbnode_empty;
|
|
x->type = t;
|
|
}
|
|
|
|
|
|
void vset_free(set_t* x) {
|
|
rbtree_free(x->root, nullptr, &x->type);
|
|
|
|
x->root = rbnode_empty;
|
|
x->type = 0;
|
|
}
|
|
|
|
/*#####################################################################################################################*/
|
|
|
|
size_t vset_size(const set_t* x) {
|
|
return rbtree_size(x->root);
|
|
}
|
|
|
|
/*#####################################################################################################################*/
|
|
|
|
int vset_compare(const set_t* s0, const set_t* s1) {
|
|
if (s0 == s1) return 0;
|
|
if (s0->type != s1->type) return s0->type - s1->type;
|
|
|
|
return rbtree_compare(s0->root, s1->root, nullptr, (void*)&s0->type);
|
|
}
|
|
|
|
/*#####################################################################################################################*/
|
|
|
|
set_t vset_copy(const set_t* s) {
|
|
set_t x;
|
|
|
|
x.type = s->type;
|
|
x.root = rbtree_duplicate(s->root, nullptr, &x.type);
|
|
|
|
return x;
|
|
}
|
|
|
|
set_t* vset_duplicate(const set_t* s) {
|
|
set_t *x = malloc(sizeof(*x));
|
|
|
|
x->type = s->type;
|
|
x->root = rbtree_duplicate(s->root, nullptr, &x->type);
|
|
|
|
return x;
|
|
}
|
|
|
|
void vset_copy_init(set_t* x, const set_t* s) {
|
|
x->type = s->type;
|
|
x->root = rbtree_duplicate(s->root, nullptr, &x->type);
|
|
}
|