have self iterator for easier erasure and revalidate them all after erasure but realizing that that isn't good enough for performance so might need to shift to using unique_ptr to do proper pointers
This commit is contained in:
parent
f83d3f70b5
commit
61a710f938
1 changed files with 9 additions and 0 deletions
9
Map.hpp
9
Map.hpp
|
@ -36,6 +36,7 @@ template <typename Key_T, typename Mapped_T> struct BookKeeping {
|
||||||
friend class Map<Key_T, Mapped_T>;
|
friend class Map<Key_T, Mapped_T>;
|
||||||
Map<Key_T, Mapped_T> &container;
|
Map<Key_T, Mapped_T> &container;
|
||||||
ValueType value;
|
ValueType value;
|
||||||
|
typename std::vector<Self>::iterator self;
|
||||||
Color color;
|
Color color;
|
||||||
// nullptr indicates empty
|
// nullptr indicates empty
|
||||||
Self *parent;
|
Self *parent;
|
||||||
|
@ -559,7 +560,10 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// TODO: check that the way of reconnecting next and prev works
|
// TODO: check that the way of reconnecting next and prev works
|
||||||
|
// TODO: need to revalidate
|
||||||
void erase(Iterator pos) {
|
void erase(Iterator pos) {
|
||||||
|
auto revalidate_begin = pos.ref->container.begin() - pos.ref->self;
|
||||||
|
auto &container = pos.ref->container;
|
||||||
// simple cases
|
// simple cases
|
||||||
Node *ref = pos.ref;
|
Node *ref = pos.ref;
|
||||||
// 2 children
|
// 2 children
|
||||||
|
@ -604,6 +608,11 @@ public:
|
||||||
else {
|
else {
|
||||||
this->complex_erase(pos);
|
this->complex_erase(pos);
|
||||||
}
|
}
|
||||||
|
// need to revalidate iterators now so future erasures aren't fucked
|
||||||
|
for (auto iter = container.begin() + revalidate_begin;
|
||||||
|
iter != container.end(); ++iter) {
|
||||||
|
iter->self = iter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void erase(const Key_T &key) { this->erase(this->find(key)); }
|
void erase(const Key_T &key) { this->erase(this->find(key)); }
|
||||||
void clear() {
|
void clear() {
|
||||||
|
|
Loading…
Reference in a new issue