3 #ifndef __CDSUNIT_STD_HASH_MAP_GCC_H
4 #define __CDSUNIT_STD_HASH_MAP_GCC_H
6 #include <mutex> //unique_lock
7 #include <unordered_map>
11 template <typename Key, typename Value, typename Lock,
12 class Alloc = typename CDS_DEFAULT_ALLOCATOR::template rebind<std::pair<Key const, Value> >::other
15 : public std::unordered_map<
24 typedef std::unique_lock<Lock> scoped_lock;
25 typedef std::unordered_map<
32 typedef typename base_class::mapped_type value_type;
33 typedef size_t item_counter;
35 StdHashMap( size_t nMapSize, size_t nLoadFactor )
38 bool find( const Key& key )
40 scoped_lock al( m_lock );
41 return base_class::find( key ) != base_class::end();
44 bool insert( const Key& key, const Value& val )
46 scoped_lock al( m_lock );
47 return base_class::insert( typename base_class::value_type(key, val)).second;
50 template <typename T, typename Func>
51 bool insert( const Key& key, const T& val, Func func )
53 scoped_lock al( m_lock );
54 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( typename base_class::value_type(key, Value() ));
56 func( pRet.first->second, val );
62 template <typename T, typename Func>
63 std::pair<bool, bool> ensure( const T& key, Func func )
65 scoped_lock al( m_lock );
66 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( typename base_class::value_type( key, Value() ));
68 func( true, *pRet.first );
69 return std::make_pair( true, true );
72 func( false, *pRet.first );
73 return std::make_pair( true, false );
77 bool erase( const Key& key )
79 scoped_lock al( m_lock );
80 return base_class::erase( key ) != 0;
83 template <typename T, typename Func>
84 bool erase( const T& key, Func func )
86 scoped_lock al( m_lock );
87 typename base_class::iterator it = base_class::find( key );
88 if ( it != base_class::end() ) {
90 return base_class::erase( key ) != 0;
95 std::ostream& dump( std::ostream& stm ) { return stm; }
99 #endif // #ifndef __CDSUNIT_STD_HASH_MAP_GCC_H