#ifndef MAP_H #define MAP_H #include "BinarySearchTree.h" #include //assert #include //pair template // default argument > class Map { private: using Pair_type = std::pair; class PairComp { private: Key_compare key; public: bool operator()(const Pair_type &pair1, const Pair_type &pair2) { return key(pair1.first, pair2.first); } }; public: using Iterator = typename BinarySearchTree::Iterator; bool empty() const { return bst.empty(); } size_t size() const { return bst.size(); } Iterator find(const Key_type& k) const { return bst.find(Pair_type(k, Value_type())); } Value_type& operator[](const Key_type& k) { Iterator found = this->find(k); if(found != bst.end()) { return found->second; } else { Pair_type p = {k, Value_type()}; std::pair p2; p2 = insert(p); Pair_type &pair_out = *(p2.first); return pair_out.second; } } std::pair insert(const Pair_type &val) { Iterator found = this->find(val.first); if(found != bst.end()) { return std::pair(found, false); } else { // Pair_type p1 = {val, Value_type()}; // std::pair p2; // p2 = insert(p); return std::pair(bst.insert(val), true); } } Iterator begin() const { return bst.begin(); } Iterator end() const { return bst.end(); } private: BinarySearchTree bst; }; #endif