Some initial boilerplate and obvious implementations
commit 1/10
This commit is contained in:
parent
49fa268a8d
commit
c4b0c7f5c9
1 changed files with 89 additions and 0 deletions
89
Map.hpp
Normal file
89
Map.hpp
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
// commenting everything out when I commit so all commits my code technically
|
||||||
|
// compiles
|
||||||
|
#if 0
|
||||||
|
#include <algorithm>
|
||||||
|
#include <initializer_list>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
namespace cs440 {
|
||||||
|
|
||||||
|
template <typename Key_T, typename Mapped_T> class Map {
|
||||||
|
private:
|
||||||
|
using ValueType = std::pair<const Key_T, Mapped_T>;
|
||||||
|
// idx 0 = root
|
||||||
|
// left = parent * 2 + 1
|
||||||
|
// right = parent * 2 + 2
|
||||||
|
std::vector<ValueType> store;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// TODO: Iterator functionality
|
||||||
|
class Iterator {
|
||||||
|
Iterator() = delete;
|
||||||
|
Iterator(Map &parent, const Key_T &key) {}
|
||||||
|
};
|
||||||
|
class ConstIterator {
|
||||||
|
ConstIterator() = delete;
|
||||||
|
ConstIterator(Map const &parent, const Key_T &key) {}
|
||||||
|
};
|
||||||
|
class ReverseIterator {
|
||||||
|
ReverseIterator() = delete;
|
||||||
|
ReverseIterator(Map &parent, const Key_T &key) {}
|
||||||
|
};
|
||||||
|
Map() : store{} {}
|
||||||
|
Map(const Map &rhs) : store{rhs.store} {}
|
||||||
|
Map &operator=(const Map &rhs) { this->store = rhs.store; }
|
||||||
|
Map(std::initializer_list<ValueType> elems) : store{} {
|
||||||
|
this->insert(elems.begin(), elems.end());
|
||||||
|
}
|
||||||
|
// who cares we're using vector
|
||||||
|
~Map() {}
|
||||||
|
|
||||||
|
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, ); }
|
||||||
|
ConstIterator begin() const { return ConstIterator(*this, ); }
|
||||||
|
ConstIterator end() const { return this->cbegin(); }
|
||||||
|
ConstIterator cbegin() const { return this->cend(); }
|
||||||
|
ConstIterator cend() const { return ConstIterator(*this, ); }
|
||||||
|
ReverseIterator rbegin() { return Iterator(*this, ); }
|
||||||
|
ReverseIterator rend() { return Iterator(*this, ); }
|
||||||
|
Iterator find(const Key_T &) {}
|
||||||
|
ConstIterator find(const Key_T &) const;
|
||||||
|
Mapped_T &at(const Key_T &key) {}
|
||||||
|
const Mapped_T &at(const Key_T &key) const {}
|
||||||
|
Mapped_T &operator[](const Key_T &) {}
|
||||||
|
std ::pair<Iterator, bool> insert(const ValueType &) {}
|
||||||
|
template <typename IT_T> void insert(IT_T range_beg, IT_T range_end) {
|
||||||
|
std::for_each(range_beg, range_end,
|
||||||
|
[&](ValueType &val) { this->insert(val); });
|
||||||
|
}
|
||||||
|
// TODO: erase via iterator
|
||||||
|
void erase(Iterator pos) {}
|
||||||
|
void erase(const Key_T &key) { this->erase(this->find(key)); }
|
||||||
|
void clear() { this->store = {}; }
|
||||||
|
friend bool operator==(const Map &lhs, const Map &rhs) {
|
||||||
|
if (lhs.store.size() != rhs.store.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto liter = lhs.cbegin();
|
||||||
|
auto riter = rhs.cbegin();
|
||||||
|
// both must be the same length so this is fine
|
||||||
|
while (liter != lhs.cend()) {
|
||||||
|
if (*liter != *riter) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
liter++;
|
||||||
|
riter++;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
friend bool operator!=(const Map &lhs, const Map &rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
// TODO < operator
|
||||||
|
friend bool operator<(const Map &lhs, const Map &rhs) {}
|
||||||
|
};
|
||||||
|
} // namespace cs440
|
||||||
|
#endif
|
Loading…
Reference in a new issue