some fixes

This commit is contained in:
Pagwin 2024-11-25 20:06:43 -05:00
parent ce0f5f7ef0
commit 30babdb9dc
No known key found for this signature in database
GPG key ID: 81137023740CA260

32
Map.hpp
View file

@ -163,9 +163,6 @@ template <typename Key_T, typename Mapped_T> class Map {
std::unique_ptr<Node> &set_child(Direction dir,
std::unique_ptr<Node> new_child) {
if (new_child) {
new_child->parent = this;
}
switch (dir) {
case Direction::Left:
@ -291,7 +288,8 @@ template <typename Key_T, typename Mapped_T> class Map {
// gotta pull outselves out of parent to avoid accidentally overwriting
// outselves
std::unique_ptr<Node> self = this->parent->uchild(!dir);
std::unique_ptr<Node> self =
this->parent->uchild(this->parent->which_child(this));
// make sure this is actually us
assert(self.get() == this);
@ -437,7 +435,7 @@ public:
}
ValueType &operator*() const {
ValueType *ret = (ValueType *)(&this->underlying->val);
ValueType *ret = (ValueType *)(this->underlying->val.get());
return *ret;
}
ValueType *operator->() const { return &this->operator*(); }
@ -537,8 +535,8 @@ public:
while (min->left) {
min = min->left.get();
}
while (min->right) {
min = min->left.get();
while (max->right) {
max = max->right.get();
}
}
Map(Map &&rhs) : root{std::move(rhs.root)}, _size{rhs._size} {
@ -547,18 +545,34 @@ public:
while (min->left) {
min = min->left.get();
}
while (min->right) {
min = min->left.get();
while (max->right) {
max = max->right.get();
}
}
Map &operator=(const Map &rhs) {
this->root = rhs.root;
this->_size = rhs._size;
this->min = &this->root.value();
this->max = &this->root.value();
while (min->left) {
min = min->left.get();
}
while (max->right) {
max = max->right.get();
}
return *this;
}
Map &operator=(Map &&rhs) {
this->root = std::move(rhs.root);
this->_size = rhs._size;
this->min = &this->root.value();
this->max = &this->root.value();
while (min->left) {
min = min->left.get();
}
while (max->right) {
max = max->right.get();
}
return *this;
}
Map(std::initializer_list<std::pair<const Key_T, Mapped_T>> items) : Map{} {