some fixes
This commit is contained in:
parent
ce0f5f7ef0
commit
30babdb9dc
1 changed files with 23 additions and 9 deletions
32
Map.hpp
32
Map.hpp
|
@ -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{} {
|
||||
|
|
Loading…
Reference in a new issue