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>
8 #include <functional> // ref
12 template <typename Key, typename Value, typename Lock,
13 class Alloc = typename CDS_DEFAULT_ALLOCATOR::template rebind<std::pair<Key const, Value> >::other
16 : public std::unordered_map<
25 typedef std::unique_lock<Lock> AutoLock;
26 typedef std::unordered_map<
33 typedef typename base_class::mapped_type value_type;
34 typedef size_t item_counter;
36 StdHashMap( size_t nMapSize, size_t nLoadFactor )
39 bool find( const Key& key )
41 AutoLock al( m_lock );
42 return base_class::find( key ) != base_class::end();
45 bool insert( const Key& key, const Value& val )
47 AutoLock al( m_lock );
48 return base_class::insert( typename base_class::value_type(key, val)).second;
51 template <typename T, typename Func>
52 bool insert( const Key& key, const T& val, Func func )
54 AutoLock al( m_lock );
55 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( typename base_class::value_type(key, Value() ));
57 func( pRet.first->second, val );
63 template <typename T, typename Func>
64 std::pair<bool, bool> ensure( const T& key, Func func )
66 AutoLock al( m_lock );
67 std::pair<typename base_class::iterator, bool> pRet = base_class::insert( typename base_class::value_type( key, Value() ));
69 func( true, *pRet.first );
70 return std::make_pair( true, true );
73 func( false, *pRet.first );
74 return std::make_pair( true, false );
78 bool erase( const Key& key )
80 AutoLock al( m_lock );
81 return base_class::erase( key ) != 0;
84 template <typename T, typename Func>
85 bool erase( const T& key, Func func )
87 AutoLock al( m_lock );
88 typename base_class::iterator it = base_class::find( key );
89 if ( it != base_class::end() ) {
91 return base_class::erase( key ) != 0;
96 std::ostream& dump( std::ostream& stm ) { return stm; }
100 #endif // #ifndef __CDSUNIT_STD_HASH_MAP_GCC_H