3 #ifndef CDSUNIT_STD_HASH_SET_H
4 #define CDSUNIT_STD_HASH_SET_H
6 #include <unordered_set>
7 #include <mutex> //unique_lock
11 template <typename Value, typename Hash, typename Less, typename EqualTo, typename Lock,
12 class Alloc = typename CDS_DEFAULT_ALLOCATOR::template rebind<Value>::other
15 : public std::unordered_set<
24 typedef std::unique_lock<Lock> scoped_lock;
25 typedef std::unordered_set<
32 typedef typename base_class::value_type value_type;
34 StdHashSet( size_t /*nSetSize*/, size_t /*nLoadFactor*/ )
37 template <typename Key>
38 bool find( const Key& key )
40 scoped_lock al( m_lock );
41 return base_class::find( value_type(key) ) != base_class::end();
44 template <typename Key>
45 bool insert( Key const& key )
47 scoped_lock al( m_lock );
48 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
52 template <typename Key, typename Func>
53 bool insert( Key const& key, Func func )
55 scoped_lock al( m_lock );
56 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
64 template <typename T, typename Func>
65 std::pair<bool, bool> ensure( const T& key, Func func )
67 scoped_lock al( m_lock );
68 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
70 func( true, *pRet.first, key );
71 return std::make_pair( true, true );
74 func( false, *pRet.first, key );
75 return std::make_pair( true, false );
79 template <typename Key>
80 bool erase( const Key& key )
82 scoped_lock al( m_lock );
83 return base_class::erase( value_type(key) ) != 0;
86 template <typename T, typename Func>
87 bool erase( const T& key, Func func )
89 scoped_lock al( m_lock );
90 typename base_class::iterator it = base_class::find( value_type(key) );
91 if ( it != base_class::end() ) {
93 return base_class::erase( it ) != base_class::end();
98 std::ostream& dump( std::ostream& stm ) { return stm; }
102 #endif // #ifndef CDSUNIT_STD_HASH_SET_H