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:
Pagwin 2024-11-21 19:04:54 -05:00
parent f83d3f70b5
commit 61a710f938
No known key found for this signature in database
GPG key ID: 81137023740CA260

View file

@ -36,6 +36,7 @@ template <typename Key_T, typename Mapped_T> struct BookKeeping {
friend class Map<Key_T, Mapped_T>;
Map<Key_T, Mapped_T> &container;
ValueType value;
typename std::vector<Self>::iterator self;
Color color;
// nullptr indicates empty
Self *parent;
@ -559,7 +560,10 @@ private:
public:
// TODO: check that the way of reconnecting next and prev works
// TODO: need to revalidate
void erase(Iterator pos) {
auto revalidate_begin = pos.ref->container.begin() - pos.ref->self;
auto &container = pos.ref->container;
// simple cases
Node *ref = pos.ref;
// 2 children
@ -604,6 +608,11 @@ public:
else {
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 clear() {