made iterators have actually correct underlying data?

This commit is contained in:
Pagwin 2024-11-18 17:08:25 -05:00
parent c4b0c7f5c9
commit e3ba3ec09f
No known key found for this signature in database
GPG key ID: 81137023740CA260

43
Map.hpp
View file

@ -1,8 +1,10 @@
// commenting everything out when I commit so all commits my code technically
// compiles
#if 0
#include <algorithm>
#include <initializer_list>
#include <iterator>
#include <optional>
#include <stdexcept>
#include <utility>
#include <vector>
namespace cs440 {
@ -13,21 +15,34 @@ private:
// idx 0 = root
// left = parent * 2 + 1
// right = parent * 2 + 2
std::vector<ValueType> store;
std::vector<std::optional<ValueType>> store;
public:
// TODO: Iterator functionality
class Iterator {
using underlying = typename std::vector<std::optional<ValueType>>::iterator;
underlying store_iter;
public:
Iterator() = delete;
Iterator(Map &parent, const Key_T &key) {}
Iterator(underlying iter) : store_iter{iter} {}
};
class ConstIterator {
using underlying =
typename std::vector<std::optional<ValueType>>::const_iterator;
underlying store_iter;
public:
ConstIterator() = delete;
ConstIterator(Map const &parent, const Key_T &key) {}
ConstIterator(underlying iter) : store_iter{iter} {}
};
class ReverseIterator {
using underlying = typename std::vector<std::optional<ValueType>>::iterator;
underlying store_iter;
public:
ReverseIterator() = delete;
ReverseIterator(Map &parent, const Key_T &key) {}
ReverseIterator(underlying store_iter) : store_iter{store_iter} {}
};
Map() : store{} {}
Map(const Map &rhs) : store{rhs.store} {}
@ -41,8 +56,21 @@ public:
size_t size() const { return this->store.size(); }
bool empty() const { return this->store.empty(); }
// TODO: iterator creation
Iterator begin() { return Iterator(*this, ); }
Iterator end() { return Iterator(*this, ); }
Iterator begin() {
Key_T const &start =
std::min_element(store.begin(), store.end(),
[](std::optional<ValueType> const &lhs,
std::optional<ValueType> const &rhs) {
if (lhs.has_value() != rhs.has_value()) {
return lhs.has_value();
}
return lhs.value().first < rhs.value().first;
})
->first;
return Iterator(*this, start);
}
Iterator end() { std::optional return Iterator(*this, ); }
ConstIterator begin() const { return ConstIterator(*this, ); }
ConstIterator end() const { return this->cbegin(); }
ConstIterator cbegin() const { return this->cend(); }
@ -86,4 +114,3 @@ public:
friend bool operator<(const Map &lhs, const Map &rhs) {}
};
} // namespace cs440
#endif