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;
38 template <class Config>
39 StdHashMap( Config const& )
42 bool contains( const Key& key )
44 scoped_lock al( m_lock );
45 return base_class::find( key ) != base_class::end();
48 bool insert( const Key& key, const Value& val )
50 scoped_lock al( m_lock );
51 return base_class::insert( typename base_class::value_type(key, val)).second;
54 template <typename T, typename Func>
55 bool insert( const Key& key, const T& val, Func func )
57 scoped_lock al( m_lock );
58 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( typename base_class::value_type(key, Value() ));
60 func( pRet.first->second, val );
66 template <typename T, typename Func>
67 std::pair<bool, bool> update( const T& key, Func func, bool /*bAllowInsert*/ = true )
69 scoped_lock al( m_lock );
70 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( typename base_class::value_type( key, Value() ));
72 func( true, *pRet.first );
73 return std::make_pair( true, true );
76 func( false, *pRet.first );
77 return std::make_pair( true, false );
81 bool erase( const Key& key )
83 scoped_lock al( m_lock );
84 return base_class::erase( key ) != 0;
87 template <typename T, typename Func>
88 bool erase( const T& key, Func func )
90 scoped_lock al( m_lock );
91 typename base_class::iterator it = base_class::find( key );
92 if ( it != base_class::end() ) {
94 return base_class::erase( key ) != 0;
99 std::ostream& dump( std::ostream& stm ) { return stm; }
103 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
104 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
108 #endif // #ifndef CDSUNIT_STD_HASH_MAP_GCC_H