3 #ifndef __CDSUNIT_STD_HASH_SET_STD_H
4 #define __CDSUNIT_STD_HASH_SET_STD_H
6 #include <unordered_set>
7 #include <functional> // ref
8 #include <mutex> //unique_lock
12 template <typename Value, typename Hash, typename Less, typename EqualTo, typename Lock,
13 class Alloc = typename CDS_DEFAULT_ALLOCATOR::template rebind<Value>::other
16 : public std::unordered_set<
25 typedef std::unique_lock<Lock> AutoLock;
26 typedef std::unordered_set<
33 typedef typename base_class::value_type value_type;
35 StdHashSet( size_t nSetSize, size_t nLoadFactor )
38 template <typename Key>
39 bool find( const Key& key )
41 AutoLock al( m_lock );
42 return base_class::find( value_type(key) ) != base_class::end();
45 template <typename Key>
46 bool insert( Key const& key )
48 AutoLock al( m_lock );
49 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
53 template <typename Key, typename Func>
54 bool insert( Key const& key, Func func )
56 AutoLock al( m_lock );
57 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
65 template <typename T, typename Func>
66 std::pair<bool, bool> ensure( const T& key, Func func )
68 AutoLock al( m_lock );
69 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
71 func( true, *pRet.first, key );
72 return std::make_pair( true, true );
75 func( false, *pRet.first, key );
76 return std::make_pair( true, false );
80 template <typename Key>
81 bool erase( const Key& key )
83 AutoLock al( m_lock );
84 return base_class::erase( value_type(key) ) != 0;
87 template <typename T, typename Func>
88 bool erase( const T& key, Func func )
90 AutoLock al( m_lock );
91 typename base_class::iterator it = base_class::find( value_type(key) );
92 if ( it != base_class::end() ) {
94 return base_class::erase( it ) != base_class::end();
99 std::ostream& dump( std::ostream& stm ) { return stm; }
103 #endif // #ifndef __CDSUNIT_STD_HASH_SET_STD_H