made iterators have actually correct underlying data?
This commit is contained in:
parent
c4b0c7f5c9
commit
e3ba3ec09f
1 changed files with 35 additions and 8 deletions
43
Map.hpp
43
Map.hpp
|
@ -1,8 +1,10 @@
|
||||||
// commenting everything out when I commit so all commits my code technically
|
// commenting everything out when I commit so all commits my code technically
|
||||||
// compiles
|
// compiles
|
||||||
#if 0
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
#include <iterator>
|
||||||
|
#include <optional>
|
||||||
|
#include <stdexcept>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
namespace cs440 {
|
namespace cs440 {
|
||||||
|
@ -13,21 +15,34 @@ private:
|
||||||
// idx 0 = root
|
// idx 0 = root
|
||||||
// left = parent * 2 + 1
|
// left = parent * 2 + 1
|
||||||
// right = parent * 2 + 2
|
// right = parent * 2 + 2
|
||||||
std::vector<ValueType> store;
|
std::vector<std::optional<ValueType>> store;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// TODO: Iterator functionality
|
// TODO: Iterator functionality
|
||||||
class Iterator {
|
class Iterator {
|
||||||
|
using underlying = typename std::vector<std::optional<ValueType>>::iterator;
|
||||||
|
underlying store_iter;
|
||||||
|
|
||||||
|
public:
|
||||||
Iterator() = delete;
|
Iterator() = delete;
|
||||||
Iterator(Map &parent, const Key_T &key) {}
|
Iterator(underlying iter) : store_iter{iter} {}
|
||||||
};
|
};
|
||||||
class ConstIterator {
|
class ConstIterator {
|
||||||
|
using underlying =
|
||||||
|
typename std::vector<std::optional<ValueType>>::const_iterator;
|
||||||
|
underlying store_iter;
|
||||||
|
|
||||||
|
public:
|
||||||
ConstIterator() = delete;
|
ConstIterator() = delete;
|
||||||
ConstIterator(Map const &parent, const Key_T &key) {}
|
ConstIterator(underlying iter) : store_iter{iter} {}
|
||||||
};
|
};
|
||||||
class ReverseIterator {
|
class ReverseIterator {
|
||||||
|
using underlying = typename std::vector<std::optional<ValueType>>::iterator;
|
||||||
|
underlying store_iter;
|
||||||
|
|
||||||
|
public:
|
||||||
ReverseIterator() = delete;
|
ReverseIterator() = delete;
|
||||||
ReverseIterator(Map &parent, const Key_T &key) {}
|
ReverseIterator(underlying store_iter) : store_iter{store_iter} {}
|
||||||
};
|
};
|
||||||
Map() : store{} {}
|
Map() : store{} {}
|
||||||
Map(const Map &rhs) : store{rhs.store} {}
|
Map(const Map &rhs) : store{rhs.store} {}
|
||||||
|
@ -41,8 +56,21 @@ public:
|
||||||
size_t size() const { return this->store.size(); }
|
size_t size() const { return this->store.size(); }
|
||||||
bool empty() const { return this->store.empty(); }
|
bool empty() const { return this->store.empty(); }
|
||||||
// TODO: iterator creation
|
// TODO: iterator creation
|
||||||
Iterator begin() { return Iterator(*this, ); }
|
Iterator begin() {
|
||||||
Iterator end() { return Iterator(*this, ); }
|
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 begin() const { return ConstIterator(*this, ); }
|
||||||
ConstIterator end() const { return this->cbegin(); }
|
ConstIterator end() const { return this->cbegin(); }
|
||||||
ConstIterator cbegin() const { return this->cend(); }
|
ConstIterator cbegin() const { return this->cend(); }
|
||||||
|
@ -86,4 +114,3 @@ public:
|
||||||
friend bool operator<(const Map &lhs, const Map &rhs) {}
|
friend bool operator<(const Map &lhs, const Map &rhs) {}
|
||||||
};
|
};
|
||||||
} // namespace cs440
|
} // namespace cs440
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in a new issue