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> &set_child(Direction dir,
|
||||||
std::unique_ptr<Node> new_child) {
|
std::unique_ptr<Node> new_child) {
|
||||||
|
|
||||||
if (new_child) {
|
|
||||||
new_child->parent = this;
|
|
||||||
}
|
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
case Direction::Left:
|
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
|
// gotta pull outselves out of parent to avoid accidentally overwriting
|
||||||
// outselves
|
// 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
|
// make sure this is actually us
|
||||||
assert(self.get() == this);
|
assert(self.get() == this);
|
||||||
|
@ -437,7 +435,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueType &operator*() const {
|
ValueType &operator*() const {
|
||||||
ValueType *ret = (ValueType *)(&this->underlying->val);
|
ValueType *ret = (ValueType *)(this->underlying->val.get());
|
||||||
return *ret;
|
return *ret;
|
||||||
}
|
}
|
||||||
ValueType *operator->() const { return &this->operator*(); }
|
ValueType *operator->() const { return &this->operator*(); }
|
||||||
|
@ -537,8 +535,8 @@ public:
|
||||||
while (min->left) {
|
while (min->left) {
|
||||||
min = min->left.get();
|
min = min->left.get();
|
||||||
}
|
}
|
||||||
while (min->right) {
|
while (max->right) {
|
||||||
min = min->left.get();
|
max = max->right.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map(Map &&rhs) : root{std::move(rhs.root)}, _size{rhs._size} {
|
Map(Map &&rhs) : root{std::move(rhs.root)}, _size{rhs._size} {
|
||||||
|
@ -547,18 +545,34 @@ public:
|
||||||
while (min->left) {
|
while (min->left) {
|
||||||
min = min->left.get();
|
min = min->left.get();
|
||||||
}
|
}
|
||||||
while (min->right) {
|
while (max->right) {
|
||||||
min = min->left.get();
|
max = max->right.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map &operator=(const Map &rhs) {
|
Map &operator=(const Map &rhs) {
|
||||||
this->root = rhs.root;
|
this->root = rhs.root;
|
||||||
this->_size = rhs._size;
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
Map &operator=(Map &&rhs) {
|
Map &operator=(Map &&rhs) {
|
||||||
this->root = std::move(rhs.root);
|
this->root = std::move(rhs.root);
|
||||||
this->_size = rhs._size;
|
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;
|
return *this;
|
||||||
}
|
}
|
||||||
Map(std::initializer_list<std::pair<const Key_T, Mapped_T>> items) : Map{} {
|
Map(std::initializer_list<std::pair<const Key_T, Mapped_T>> items) : Map{} {
|
||||||
|
|
Loading…
Reference in a new issue