remove revalidation std::list makes it redundant, also realized I can't have a reference in something I default construct

This commit is contained in:
Pagwin 2024-11-22 01:43:37 -05:00
parent 1bfe6e806a
commit 22bfd729e4
No known key found for this signature in database
GPG key ID: 81137023740CA260

10
Map.hpp
View file

@ -44,6 +44,7 @@ template <typename Key_T, typename Mapped_T> struct BookKeeping {
Self *right; Self *right;
Self *prev; Self *prev;
Self *next; Self *next;
BookKeeping(Map<Key_T, Mapped_T> &container) : container{container} {}
// reference to a pointer because the alternatives were worse // reference to a pointer because the alternatives were worse
inline Self *&child(Direction dir) { inline Self *&child(Direction dir) {
switch (dir) { switch (dir) {
@ -452,7 +453,7 @@ public:
if (!ret) { if (!ret) {
return std::make_pair(Iterator{parent->child(dir)}, ret); return std::make_pair(Iterator{parent->child(dir)}, ret);
} }
Node to_insert; Node to_insert{*this};
to_insert.value = val; to_insert.value = val;
this->nodes.push_back(std::move(to_insert)); this->nodes.push_back(std::move(to_insert));
insert_helper(&nodes.back(), parent, dir); insert_helper(&nodes.back(), parent, dir);
@ -560,9 +561,7 @@ 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; auto &container = pos.ref->container;
// simple cases // simple cases
Node *ref = pos.ref; Node *ref = pos.ref;
@ -608,11 +607,6 @@ 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() {