1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
class hash_set {
private:
typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>, _EqualKey, _Alloc> _Ht;
_Ht _M_ht; // 底层容器的定义
public:
hash_set() : _M_ht(100, hasher(), key_equal(), allocator_type()) {} // 构造函数
iterator find(const key_type& __key) const { return _M_ht.find(__key); } // 查找
size_type count(const key_type& __key) const { return _M_ht.count(__key); } // 计数
size_type size() const { return _M_ht.size(); } // 表格大小
size_type max_size() const { return _M_ht.max_size(); }
bool empty() const { return _M_ht.empty(); } // 是否为空
void swap(hash_set& __hs) { _M_ht.swap(__hs._M_ht); } // 交换
iterator begin() const { return _M_ht.begin(); }
iterator end() const { return _M_ht.end(); }
pair<iterator, bool> insert(const value_type& __obj){ // 插入
pair<typename _Ht::iterator, bool> __p = _M_ht.insert_unique(__obj);
return pair<iterator,bool>(__p.first, __p.second);
}
size_type erase(const key_type& __key) {return _M_ht.erase(__key); } // 擦除
void erase(iterator __it) { _M_ht.erase(__it); }
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
void clear() { _M_ht.clear(); } // 清空
};
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
inline bool operator==(const hash_set<_Value,_HashFcn,_EqualKey,_Alloc>& __hs1,
const hash_set<_Value,_HashFcn,_EqualKey,_Alloc>& __hs2) {
return __hs1._M_ht == __hs2._M_ht;
}
|