3 #ifndef __CDSUNIT_STD_HASH_SET_VC_H
4 #define __CDSUNIT_STD_HASH_SET_VC_H
10 template <typename KeyVal, typename Hash, typename Less>
11 struct hash_less: public stdext::hash_compare< KeyVal, Less >
13 typedef stdext::hash_compare< KeyVal, Less> base_class;
14 size_t operator()(const KeyVal& kv) const
19 bool operator()(const KeyVal& kv1, const KeyVal& kv2) const
21 return base_class::operator()( kv1, kv2 );
25 template <typename Value, typename Hash, typename Less, typename EqualTo, typename Lock, class Alloc = CDS_DEFAULT_ALLOCATOR>
26 class StdHashSet: public stdext::hash_set<Value, hash_less<Value, Hash, Less >, Alloc>
30 typedef cds::lock::scoped_lock<Lock> AutoLock;
31 typedef stdext::hash_set<Value, hash_less<Value, Hash, Less >, Alloc> base_class;
34 typedef typename base_class::value_type pair_type;
36 StdHashSet( size_t nSetSize, size_t nLoadFactor )
39 template <typename Key>
40 bool find( const Key& key )
42 AutoLock al( m_lock );
43 return base_class::find( value_type(key) ) != base_class::end();
46 template <typename Key>
47 bool insert( Key const& key )
49 AutoLock al( m_lock );
50 std::pair<base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
54 template <typename Key, typename Func>
55 bool insert( Key const& key, Func func )
57 AutoLock al( m_lock );
58 std::pair<base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
66 template <typename T, typename Func>
67 std::pair<bool, bool> ensure( const T& key, Func func )
69 AutoLock al( m_lock );
70 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( value_type( key ));
72 func( true, *pRet.first, key );
73 return std::make_pair( true, true );
76 func( false, *pRet.first, key );
77 return std::make_pair( true, false );
81 template <typename Key>
82 bool erase( const Key& key )
84 AutoLock al( m_lock );
85 return base_class::erase( value_type(key) ) != 0;
88 template <typename T, typename Func>
89 bool erase( const T& key, Func func )
91 AutoLock al( m_lock );
92 base_class::iterator it = base_class::find( key );
93 if ( it != base_class::end() ) {
95 return base_class::erase( it ) != base_class::end();
101 std::ostream& dump( std::ostream& stm ) { return stm; }
105 #endif // #ifndef __CDSUNIT_STD_HASH_SET_VC_H