Set_Map/Windows_Set_Map/Set.hpp

77 lines
1.7 KiB
C++
Raw Permalink Normal View History

#pragma once
#include "RBTree.hpp"
namespace Lenyiin
{
// Set <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD><DABA><EFBFBD><EFBFBD><EFBFBD>
template <class K>
class Set
{
// <20><><EFBFBD>ڴӽڵ<D3BD><DAB5>л<EFBFBD>ȡ<EFBFBD><C8A1>ֵ<EFBFBD>ķº<C4B7><C2BA><EFBFBD>
struct SetKeyOfT
{
const K& operator()(const K& k)
{
return k;
}
};
public:
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>֧<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>е<EFBFBD>Ԫ<EFBFBD><D4AA>
// <20><><EFBFBD><EFBFBD>RBTree<K, K, SetKeyOfT>::iterator<6F><72>û<EFBFBD><C3BB>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>, ϵͳ<CFB5>Ҳ<EFBFBD><D2B2><EFBFBD>, typename<6D><65><EFBFBD>߱<EFBFBD><DFB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȳ<EFBFBD><C8B2>ż<EFBFBD><C5BC><EFBFBD>
typedef typename RBTree<K, K, SetKeyOfT>::iterator iterator;
typedef typename RBTree<K, K, SetKeyOfT>::const_iterator const_iterator;
// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ԫ<EFBFBD>صĵ<D8B5><C4B5><EFBFBD><EFBFBD><EFBFBD>
iterator begin()
{
return _tree.begin();
}
// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>β<EFBFBD><CEB2>λ<EFBFBD>õĵ<C3B5><C4B5><EFBFBD><EFBFBD><EFBFBD>
iterator end()
{
return _tree.end();
}
// const <20><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>
const_iterator begin() const
{
return _tree.begin();
}
const_iterator end() const
{
return _tree.end();
}
// <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
std::pair<iterator, bool> Insert(const K& key)
{
return _tree.Insert(key);
}
// ɾ<><C9BE>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>ɹ<EFBFBD>
bool Erase(const K& key)
{
return _tree.Erase(key);
}
// <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ԫ<EFBFBD>صĵ<D8B5><C4B5><EFBFBD><EFBFBD><EFBFBD>
iterator Find(const K& key)
{
return _tree.Find(key);
}
// У<><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺϷ<C4BA><CFB7><EFBFBD>
bool IsRBTree()
{
return _tree.IsRBTree();
}
private:
// <20>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>
RBTree<K, K, SetKeyOfT> _tree;
};
}