diff --git a/Map.hpp b/Map.hpp index 3c8fa81..ba366fb 100644 --- a/Map.hpp +++ b/Map.hpp @@ -1,8 +1,10 @@ // commenting everything out when I commit so all commits my code technically // compiles -#if 0 #include #include +#include +#include +#include #include #include namespace cs440 { @@ -13,21 +15,34 @@ private: // idx 0 = root // left = parent * 2 + 1 // right = parent * 2 + 2 - std::vector store; + std::vector> store; public: // TODO: Iterator functionality class Iterator { + using underlying = typename std::vector>::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>::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>::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 const &lhs, + std::optional 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