Set_Map/Windows_Set_Map/Map.hpp

66 lines
1.3 KiB
C++

#pragma once
#include "RBTree.hpp"
namespace Lenyiin
{
template <class K, class V>
class Map
{
struct MapKeyOfT
{
const K& operator()(const std::pair<K, V>& kv)
{
return kv.first;
}
};
public:
typedef typename RBTree<K, std::pair<K, V>, MapKeyOfT>::iterator iterator;
typedef typename RBTree<K, std::pair<K, V>, MapKeyOfT>::const_iterator const_iterator;
iterator begin()
{
return _tree.begin();
}
iterator end()
{
return _tree.end();
}
const_iterator begin() const
{
return _tree.begin();
}
const_iterator end() const
{
return _tree.end();
}
std::pair<iterator, bool> Insert(const std::pair<K, V>& kv)
{
return _tree.Insert(kv);
}
bool Erase(const K& key)
{
return _tree.Erase(key);
}
V& operator[](const K& key)
{
std::pair<iterator, bool> ret = _tree.Insert(std::make_pair(key, V()));
return ret.first->second;
}
bool IsRBTree()
{
return _tree.IsRBTree();
}
private:
RBTree<K, std::pair<K, V>, MapKeyOfT> _tree;
};
}