diff --git a/Map.hpp b/Map.hpp index aa7f83b..4db34ea 100644 --- a/Map.hpp +++ b/Map.hpp @@ -163,9 +163,6 @@ template class Map { std::unique_ptr &set_child(Direction dir, std::unique_ptr new_child) { - if (new_child) { - new_child->parent = this; - } switch (dir) { case Direction::Left: @@ -291,7 +288,8 @@ template class Map { // gotta pull outselves out of parent to avoid accidentally overwriting // outselves - std::unique_ptr self = this->parent->uchild(!dir); + std::unique_ptr 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> items) : Map{} {