2024-09-24 00:01:11 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "RBTree.hpp"
|
|
|
|
|
|
|
|
|
|
namespace Lenyiin
|
|
|
|
|
{
|
2024-09-24 04:43:00 +08:00
|
|
|
|
// Set <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD><DABA><EFBFBD><EFBFBD><EFBFBD>
|
2024-09-24 00:01:11 +08:00
|
|
|
|
template <class K>
|
|
|
|
|
class Set
|
|
|
|
|
{
|
2024-09-24 04:43:00 +08:00
|
|
|
|
// <20><><EFBFBD>ڴӽڵ<D3BD><DAB5>л<EFBFBD>ȡ<EFBFBD><C8A1>ֵ<EFBFBD>ķº<C4B7><C2BA><EFBFBD>
|
2024-09-24 00:01:11 +08:00
|
|
|
|
struct SetKeyOfT
|
|
|
|
|
{
|
|
|
|
|
const K& operator()(const K& k)
|
|
|
|
|
{
|
|
|
|
|
return k;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
2024-09-24 04:43:00 +08:00
|
|
|
|
// <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>
|
2024-09-24 00:01:11 +08:00
|
|
|
|
// <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;
|
|
|
|
|
|
2024-09-24 04:43:00 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ԫ<EFBFBD>صĵ<D8B5><C4B5><EFBFBD><EFBFBD><EFBFBD>
|
2024-09-24 00:01:11 +08:00
|
|
|
|
iterator begin()
|
|
|
|
|
{
|
|
|
|
|
return _tree.begin();
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-24 04:43:00 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>β<EFBFBD><CEB2>λ<EFBFBD>õĵ<C3B5><C4B5><EFBFBD><EFBFBD><EFBFBD>
|
2024-09-24 00:01:11 +08:00
|
|
|
|
iterator end()
|
|
|
|
|
{
|
|
|
|
|
return _tree.end();
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-24 04:43:00 +08:00
|
|
|
|
// const <20>汾<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>
|
2024-09-24 00:01:11 +08:00
|
|
|
|
const_iterator begin() const
|
|
|
|
|
{
|
|
|
|
|
return _tree.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const_iterator end() const
|
|
|
|
|
{
|
|
|
|
|
return _tree.end();
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-24 04:43:00 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-09-24 00:01:11 +08:00
|
|
|
|
std::pair<iterator, bool> Insert(const K& key)
|
|
|
|
|
{
|
|
|
|
|
return _tree.Insert(key);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-24 04:43:00 +08:00
|
|
|
|
// ɾ<><C9BE>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>ɹ<EFBFBD>
|
2024-09-24 00:01:11 +08:00
|
|
|
|
bool Erase(const K& key)
|
|
|
|
|
{
|
|
|
|
|
return _tree.Erase(key);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-24 04:43:00 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ԫ<EFBFBD>صĵ<D8B5><C4B5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
iterator Find(const K& key)
|
2024-09-24 00:01:11 +08:00
|
|
|
|
{
|
|
|
|
|
return _tree.Find(key);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-24 04:43:00 +08:00
|
|
|
|
// У<><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺϷ<C4BA><CFB7><EFBFBD>
|
2024-09-24 00:01:11 +08:00
|
|
|
|
bool IsRBTree()
|
|
|
|
|
{
|
|
|
|
|
return _tree.IsRBTree();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2024-09-24 04:43:00 +08:00
|
|
|
|
// <20>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>
|
2024-09-24 00:01:11 +08:00
|
|
|
|
RBTree<K, K, SetKeyOfT> _tree;
|
|
|
|
|
};
|
|
|
|
|
}
|