From fef617b087290352f3247ad8dc09f9aa30e7ba5a Mon Sep 17 00:00:00 2001 From: khizmax Date: Sun, 6 Sep 2015 10:03:42 +0300 Subject: [PATCH] StripedSet: replace ensure() with update() Refactored Map_find_int MT-test --- cds/container/split_list_set.h | 1 - cds/container/striped_set.h | 82 ++++++++------ cds/container/striped_set/adapter.h | 17 ++- cds/container/striped_set/boost_list.h | 5 +- cds/container/striped_set/boost_slist.h | 5 +- .../striped_set/boost_stable_vector.h | 94 +--------------- cds/container/striped_set/boost_vector.h | 5 +- cds/container/striped_set/std_hash_set.h | 18 ++- cds/container/striped_set/std_list.h | 5 +- cds/container/striped_set/std_set.h | 17 ++- cds/container/striped_set/std_vector.h | 5 +- cds/intrusive/split_list.h | 2 +- cds/intrusive/striped_set.h | 58 +++++++--- cds/intrusive/striped_set/adapter.h | 25 +++-- cds/intrusive/striped_set/boost_list.h | 5 +- cds/intrusive/striped_set/boost_slist.h | 5 +- .../striped_set/boost_unordered_set.h | 17 ++- projects/Win/vc12/unit-map-find.vcxproj | 2 +- .../Win/vc12/unit-map-find.vcxproj.filters | 6 +- projects/source.unit.map.mk | 2 +- tests/unit/map2/CMakeLists.txt | 2 +- tests/unit/map2/map_defs.h | 8 ++ tests/unit/map2/map_find_int.cpp | 48 +++----- tests/unit/map2/map_find_int.h | 103 +++++++++--------- .../unit/map2/map_find_int_bronsonavltree.cpp | 10 +- tests/unit/map2/map_find_int_cuckoo.cpp | 10 +- tests/unit/map2/map_find_int_ellentree.cpp | 10 +- tests/unit/map2/map_find_int_michael.cpp | 13 +-- .../map2/map_find_int_multilevelhashmap.cpp | 12 ++ tests/unit/map2/map_find_int_refinable.cpp | 12 -- tests/unit/map2/map_find_int_skip.cpp | 13 +-- tests/unit/map2/map_find_int_split.cpp | 13 +-- tests/unit/map2/map_find_int_std.cpp | 11 +- tests/unit/map2/map_find_int_striped.cpp | 11 +- tests/unit/map2/map_insdel_func.h | 9 +- tests/unit/map2/map_insdel_string.h | 9 +- tests/unit/map2/std_hash_map.h | 2 +- tests/unit/map2/std_map.h | 2 +- 38 files changed, 338 insertions(+), 336 deletions(-) create mode 100644 tests/unit/map2/map_find_int_multilevelhashmap.cpp delete mode 100644 tests/unit/map2/map_find_int_refinable.cpp diff --git a/cds/container/split_list_set.h b/cds/container/split_list_set.h index c58ee026..640cc3d1 100644 --- a/cds/container/split_list_set.h +++ b/cds/container/split_list_set.h @@ -447,7 +447,6 @@ namespace cds { namespace container { void operator()( bool bNew, value_type& item, const Q& val ); }; \endcode - with arguments: - \p bNew - \p true if the item has been inserted, \p false otherwise - \p item - item of the set diff --git a/cds/container/striped_set.h b/cds/container/striped_set.h index c1828458..8396e042 100644 --- a/cds/container/striped_set.h +++ b/cds/container/striped_set.h @@ -605,36 +605,32 @@ namespace cds { namespace container { return bOk; } - /// Ensures that the \p val exists in the set + /// Updates the node /** - The operation performs inserting or changing data. + The operation performs inserting or changing data with lock-free manner. - If the \p val key not found in the set, then the new item created from \p val - is inserted into the set. Otherwise, the functor \p func is called with the item found. - The functor \p Func should be a function with signature: - \code - void func( bool bNew, value_type& item, const Q& val ); - \endcode - or a functor: + If \p key is not found in the set, then \p key is inserted iff \p bAllowInsert is \p true. + Otherwise, the functor \p func is called with item found. + + The functor signature is: \code struct my_functor { void operator()( bool bNew, value_type& item, const Q& val ); }; \endcode - with arguments: - \p bNew - \p true if the item has been inserted, \p false otherwise - - \p item - item of the list - - \p val - argument \p val passed into the \p ensure function + - \p item - item of the set + - \p val - argument \p val passed into the \p %update() function - The functor can change non-key fields of the \p item. + The functor may change non-key fields of the \p item. Returns std::pair where \p first is true if operation is successfull, - \p second is true if new item has been added or \p false if the item with \p val key - already exists. + \p second is true if new item has been added or \p false if the item with \p key + already is in the map. */ template - std::pair ensure( Q const& val, Func func ) + std::pair update( Q const& val, Func func, bool bAllowInsert = true ) { std::pair result; bool bResize; @@ -644,7 +640,7 @@ namespace cds { namespace container { scoped_cell_lock sl( base_class::m_MutexPolicy, nHash ); pBucket = base_class::bucket( nHash ); - result = pBucket->ensure( val, func ); + result = pBucket->update( val, func, bAllowInsert ); bResize = result.first && result.second && base_class::m_ResizingPolicy( ++base_class::m_ItemCounter, *this, *pBucket ); } @@ -652,6 +648,14 @@ namespace cds { namespace container { base_class::resize(); return result; } + //@cond + template + CDS_DEPRECATED("ensure() is deprecated, use update()") + std::pair ensure( Q const& val, Func func ) + { + return update( val, func, true ); + } + //@endcond /// Delete \p key from the set /** \anchor cds_nonintrusive_StripedSet_erase @@ -832,38 +836,50 @@ namespace cds { namespace container { return base_class::find_with( val, pred, f ); } - /// Find the key \p val - /** \anchor cds_nonintrusive_StripedSet_find_val - - The function searches the item with key equal to \p val + /// Checks whether the set contains \p key + /** + The function searches the item with key equal to \p key and returns \p true if it is found, and \p false otherwise. Note the hash functor specified for class \p Traits template parameter should accept a parameter of type \p Q that can be not the same as \p value_type. + Otherwise, you may use \p contains( Q const&, Less pred ) functions with explicit predicate for key comparing. */ template - bool find( Q const& val ) + bool contains( Q const& key ) { - return base_class::find( val ); + return base_class::contains( key ); } + //@cond + template + CDS_DEPRECATED("use contains()") + bool find( Q const& key ) + { + return contains( key ); + } + //@endcond - /// Find the key \p val using \p pred predicate + /// Checks whether the map contains \p key using \p pred predicate for searching /** - The function is an analog of \ref cds_nonintrusive_StripedSet_find_val "find(Q const&)" - but \p pred is used for key comparing - \p Less has the interface like \p std::less. - \p pred must imply the same element order as the comparator used for building the set. - - @note This function is enabled if the compiler supports C++11 - default template arguments for function template and the underlying container - supports \p %find_with feature. + The function is similar to contains( key ) but \p pred is used for key comparing. + \p Less functor has the interface like \p std::less. + \p Less must imply the same element order as the comparator used for building the map. */ template ::type > + bool contains( Q const& key, Less pred ) + { + return base_class::contains( key, pred ); + } + //@cond + template ::type > + CDS_DEPRECATED("use contains()") bool find_with( Q const& val, Less pred ) { - return base_class::find_with( val, pred ); + return contains( val, pred ); } + //@endcond /// Clears the set /** diff --git a/cds/container/striped_set/adapter.h b/cds/container/striped_set/adapter.h index ef60abe4..aeb4101e 100644 --- a/cds/container/striped_set/adapter.h +++ b/cds/container/striped_set/adapter.h @@ -292,11 +292,20 @@ namespace cds { namespace container { } template - std::pair ensure( const Q& val, Func func ) + std::pair update( const Q& val, Func func, bool bAllowInsert ) { - std::pair res = m_Set.insert( value_type(val) ); - func( res.second, const_cast(*res.first), val ); - return std::make_pair( true, res.second ); + if ( bAllowInsert ) { + std::pair res = m_Set.insert( value_type(val) ); + func( res.second, const_cast(*res.first), val ); + return std::make_pair( true, res.second ); + } + else { + auto it = m_Set.find( val ); + if ( it == m_Set.end() ) + return std::make_pair( false, false ); + func( false, *it, val ); + return std::make_pair( true, false ); + } } template diff --git a/cds/container/striped_set/boost_list.h b/cds/container/striped_set/boost_list.h index dc9c16b2..79f21754 100644 --- a/cds/container/striped_set/boost_list.h +++ b/cds/container/striped_set/boost_list.h @@ -156,11 +156,14 @@ namespace cds { namespace intrusive { namespace striped_set { } template - std::pair ensure( Q const& val, Func func ) + std::pair update( Q const& val, Func func, bool bAllowInsert ) { iterator it = std::lower_bound( m_List.begin(), m_List.end(), val, find_predicate() ); if ( it == m_List.end() || key_comparator()( val, *it ) != 0 ) { // insert new + if ( !bAllowInsert ) + return std::make_pair( false, false ); + value_type newItem( val ); it = m_List.insert( it, newItem ); func( true, *it, val ); diff --git a/cds/container/striped_set/boost_slist.h b/cds/container/striped_set/boost_slist.h index 9170e76f..da9d29e8 100644 --- a/cds/container/striped_set/boost_slist.h +++ b/cds/container/striped_set/boost_slist.h @@ -164,11 +164,14 @@ namespace cds { namespace intrusive { namespace striped_set { } template - std::pair ensure( const Q& val, Func func ) + std::pair update( const Q& val, Func func, bool bAllowInsert ) { std::pair< iterator, bool > pos = find_prev_item( val ); if ( !pos.second ) { // insert new + if ( !bAllowInsert ) + return std::make_pair( false, false ); + value_type newItem( val ); pos.first = m_List.insert_after( pos.first, newItem ); func( true, *pos.first, val ); diff --git a/cds/container/striped_set/boost_stable_vector.h b/cds/container/striped_set/boost_stable_vector.h index f77de64c..dda5c872 100644 --- a/cds/container/striped_set/boost_stable_vector.h +++ b/cds/container/striped_set/boost_stable_vector.h @@ -125,25 +125,6 @@ namespace cds { namespace intrusive { namespace striped_set { //@endcond public: - - /// Insert value \p val of type \p Q into the container - /** - The function allows to split creating of new item into two part: - - create item with key only from \p val - - try to insert new item into the container - - if inserting is success, calls \p f functor to initialize value-field of the new item. - - The functor signature is: - \code - void func( value_type& item ); - \endcode - where \p item is the item inserted. - - The type \p Q may differ from \ref value_type of items storing in the container. - Therefore, the \p value_type should be comparable with type \p Q and constructible from type \p Q, - - The user-defined functor is called only if the inserting is success. - */ template bool insert( const Q& val, Func f ) { @@ -169,43 +150,15 @@ namespace cds { namespace intrusive { namespace striped_set { return false; } - /// Ensures that the \p item exists in the container - /** - The operation performs inserting or changing data. - - If the \p val key not found in the container, then the new item created from \p val - is inserted. Otherwise, the functor \p func is called with the item found. - The \p Func functor has interface: - \code - void func( bool bNew, value_type& item, const Q& val ); - \endcode - or like a functor: - \code - struct my_functor { - void operator()( bool bNew, value_type& item, const Q& val ); - }; - \endcode - - where arguments are: - - \p bNew - \p true if the item has been inserted, \p false otherwise - - \p item - container's item - - \p val - argument \p val passed into the \p ensure function - - The functor may change non-key fields of the \p item. - - The type \p Q may differ from \ref value_type of items storing in the container. - Therefore, the \p value_type should be comparable with type \p Q and constructible from type \p Q, - - Returns std::pair where \p first is true if operation is successfull, - \p second is true if new item has been added or \p false if the item with \p val key - already exists. - */ template - std::pair ensure( const Q& val, Func func ) + std::pair update( const Q& val, Func func, bool bAllowInsert ) { iterator it = std::lower_bound( m_Vector.begin(), m_Vector.end(), val, find_predicate() ); if ( it == m_Vector.end() || key_comparator()( val, *it ) != 0 ) { // insert new + if ( !bAllowInsert ) + return std::make_pair( false, false ); + value_type newItem( val ); it = m_Vector.insert( it, newItem ); func( true, *it, val ); @@ -218,23 +171,6 @@ namespace cds { namespace intrusive { namespace striped_set { } } - /// Delete \p key - /** - The function searches an item with key \p key, calls \p f functor - and deletes the item. If \p key is not found, the functor is not called. - - The functor \p Func interface is: - \code - struct extractor { - void operator()(value_type const& val); - }; - \endcode - - The type \p Q may differ from \ref value_type of items storing in the container. - Therefore, the \p value_type should be comparable with type \p Q. - - Return \p true if key is found and deleted, \p false otherwise - */ template bool erase( const Q& key, Func f ) { @@ -261,26 +197,6 @@ namespace cds { namespace intrusive { namespace striped_set { return true; } - /// Find the key \p val - /** - The function searches the item with key equal to \p val and calls the functor \p f for item found. - The interface of \p Func functor is: - \code - struct functor { - void operator()( value_type& item, Q& val ); - }; - \endcode - where \p item is the item found, \p val is the find function argument. - - The functor may change non-key fields of \p item. - The \p val argument is non-const since it can be used as \p f functor destination i.e., the functor - may modify both arguments. - - The type \p Q may differ from \ref value_type of items storing in the container. - Therefore, the \p value_type should be comparable with type \p Q. - - The function returns \p true if \p val is found, \p false otherwise. - */ template bool find( Q& val, Func f ) { @@ -335,8 +251,6 @@ namespace cds { namespace intrusive { namespace striped_set { }; }}} // namespace cds::intrusive::striped_set - - //@endcond #endif // #ifndef CDSLIB_CONTAINER_STRIPED_SET_BOOST_STABLE_VECTOR_ADAPTER_H diff --git a/cds/container/striped_set/boost_vector.h b/cds/container/striped_set/boost_vector.h index 67b108f1..616f6f12 100644 --- a/cds/container/striped_set/boost_vector.h +++ b/cds/container/striped_set/boost_vector.h @@ -151,11 +151,14 @@ namespace cds { namespace intrusive { namespace striped_set { } template - std::pair ensure( const Q& val, Func func ) + std::pair update( const Q& val, Func func, bool bAllowInsert ) { iterator it = std::lower_bound( m_Vector.begin(), m_Vector.end(), val, find_predicate() ); if ( it == m_Vector.end() || key_comparator()( val, *it ) != 0 ) { // insert new + if ( !bAllowInsert ) + return std::make_pair( false, false ); + value_type newItem( val ); it = m_Vector.insert( it, newItem ); func( true, *it, val ); diff --git a/cds/container/striped_set/std_hash_set.h b/cds/container/striped_set/std_hash_set.h index 18362470..3ab581b4 100644 --- a/cds/container/striped_set/std_hash_set.h +++ b/cds/container/striped_set/std_hash_set.h @@ -101,11 +101,21 @@ namespace cds { namespace intrusive { namespace striped_set { } template - std::pair ensure( const Q& val, Func func ) + std::pair update( const Q& val, Func func, bool bAllowInsert ) { - std::pair res = m_Set.insert( value_type(val) ); - func( res.second, const_cast(*res.first), val ); - return std::make_pair( true, res.second ); + if ( bAllowInsert ) { + std::pair res = m_Set.insert( value_type(val) ); + func( res.second, const_cast(*res.first), val ); + return std::make_pair( true, res.second ); + } + else { + auto it = m_Set.find( value_type(val)); + if ( it = m_Set.end() ) + return std::make_pair( false, false ); + + func( false, *it, val ); + return std::make_pair( true, false ); + } } template diff --git a/cds/container/striped_set/std_list.h b/cds/container/striped_set/std_list.h index b0788c3b..4f8d22af 100644 --- a/cds/container/striped_set/std_list.h +++ b/cds/container/striped_set/std_list.h @@ -173,11 +173,14 @@ namespace cds { namespace intrusive { namespace striped_set { } template - std::pair ensure( const Q& val, Func func ) + std::pair update( const Q& val, Func func, bool bAllowInsert ) { iterator it = std::lower_bound( m_List.begin(), m_List.end(), val, find_predicate() ); if ( it == m_List.end() || key_comparator()( val, *it ) != 0 ) { // insert new + if ( !bAllowInsert ) + return std::make_pair( false, false ); + value_type newItem( val ); it = m_List.insert( it, newItem ); func( true, *it, val ); diff --git a/cds/container/striped_set/std_set.h b/cds/container/striped_set/std_set.h index a132aaee..821c2471 100644 --- a/cds/container/striped_set/std_set.h +++ b/cds/container/striped_set/std_set.h @@ -102,11 +102,20 @@ namespace cds { namespace intrusive { namespace striped_set { } template - std::pair ensure( const Q& val, Func func ) + std::pair update( const Q& val, Func func, bool bAllowInsert ) { - std::pair res = m_Set.insert( value_type(val) ); - func( res.second, const_cast(*res.first), val ); - return std::make_pair( true, res.second ); + if ( bAllowInsert ) { + std::pair res = m_Set.insert( value_type(val) ); + func( res.second, const_cast(*res.first), val ); + return std::make_pair( true, res.second ); + } + else { + auto it = m_Set.find(value_type(val)); + if ( it == m_Set.end() ) + return std::make_pair( false, false ); + func( false, *it, val ); + return std::make_pair( true, false ); + } } template diff --git a/cds/container/striped_set/std_vector.h b/cds/container/striped_set/std_vector.h index 278bc566..039618bb 100644 --- a/cds/container/striped_set/std_vector.h +++ b/cds/container/striped_set/std_vector.h @@ -154,11 +154,14 @@ namespace cds { namespace intrusive { namespace striped_set { } template - std::pair ensure( const Q& val, Func func ) + std::pair update( const Q& val, Func func, bool bAllowInsert ) { iterator it = std::lower_bound( m_Vector.begin(), m_Vector.end(), val, find_predicate() ); if ( it == m_Vector.end() || key_comparator()( val, *it ) != 0 ) { // insert new + if ( !bAllowInsert ) + return std::make_pair( false, false ); + value_type newItem( val ); it = m_Vector.insert( it, newItem ); func( true, *it, val ); diff --git a/cds/intrusive/split_list.h b/cds/intrusive/split_list.h index fb385ad6..01db9ad2 100644 --- a/cds/intrusive/split_list.h +++ b/cds/intrusive/split_list.h @@ -708,7 +708,7 @@ namespace cds { namespace intrusive { The functor may change non-key fields of the \p item. Returns std::pair where \p first is \p true if operation is successfull, - \p second is \p true if new item has been added or \p false if the item with \p key + \p second is \p true if new item has been added or \p false if the item with \p val already is in the list. @warning For \ref cds_intrusive_MichaelList_hp "MichaelList" as the bucket see \ref cds_intrusive_item_creating "insert item troubleshooting". diff --git a/cds/intrusive/striped_set.h b/cds/intrusive/striped_set.h index 62c0799d..ed33e83f 100644 --- a/cds/intrusive/striped_set.h +++ b/cds/intrusive/striped_set.h @@ -517,11 +517,12 @@ namespace cds { namespace intrusive { return bOk; } - /// Ensures that the \p val exists in the set + /// Updates the node /** The operation performs inserting or changing data with lock-free manner. - If the item \p val not found in the set, then \p val is inserted into the set. + If the item \p val is not found in the set, then \p val is inserted + iff \p bAllowInsert is \p true. Otherwise, the functor \p func is called with item found. The functor signature is: \code @@ -530,18 +531,18 @@ namespace cds { namespace intrusive { with arguments: - \p bNew - \p true if the item has been inserted, \p false otherwise - \p item - item of the set - - \p val - argument \p val passed into the \p ensure function + - \p val - argument \p val passed into the \p update() function If new item has been inserted (i.e. \p bNew is \p true) then \p item and \p val arguments refers to the same thing. The functor may change non-key fields of the \p item. - Returns std::pair where \p first is \p true if operation is successful, - \p second is \p true if new item has been added or \p false if the item with \p key + Returns std::pair where \p first is \p true if operation is successfull, + \p second is \p true if new item has been added or \p false if the item with \p val already is in the set. */ template - std::pair ensure( value_type& val, Func func ) + std::pair update( value_type& val, Func func, bool bAllowInsert = true ) { std::pair result; bool bResize; @@ -551,7 +552,7 @@ namespace cds { namespace intrusive { scoped_cell_lock sl( m_MutexPolicy, nHash ); pBucket = bucket( nHash ); - result = pBucket->ensure( val, func ); + result = pBucket->update( val, func, bAllowInsert ); bResize = result.first && result.second && m_ResizingPolicy( ++m_ItemCounter, *this, *pBucket ); } @@ -559,6 +560,13 @@ namespace cds { namespace intrusive { resize(); return result; } + //@cond + template + std::pair ensure( value_type& val, Func func ) + { + return update( val, func, true ); + } + //@endcond /// Unlink the item \p val from the set /** @@ -742,32 +750,48 @@ namespace cds { namespace intrusive { return find_with_( val, pred, f ); } - /// Find the key \p val - /** \anchor cds_intrusive_StripedSet_find_val - The function searches the item with key equal to \p val + /// Checks whether the set contains \p key + /** + The function searches the item with key equal to \p key and returns \p true if it is found, and \p false otherwise. Note the hash functor specified for class \p Traits template parameter should accept a parameter of type \p Q that can be not the same as \p value_type. + Otherwise, you may use \p contains( Q const&, Less pred ) functions with explicit predicate for key comparing. */ template + bool contains( Q const& key ) + { + return find( key, [](value_type&, Q const& ) {} ); + } + //@cond + template + CDS_DEPRECATED("use contains()") bool find( Q const& val ) { - return find( val, [](value_type&, Q const& ) {} ); + return contains( val ;) } + //@endcond - /// Find the key \p val using \p pred predicate + /// Checks whether the set contains \p key using \p pred predicate for searching /** - The function is an analog of \ref cds_intrusive_StripedSet_find_val "find(Q const&)" - but \p pred is used for key comparing - \p Less has the interface like \p std::less. - \p pred must imply the same element order as the comparator used for building the set. + The function is an analog of contains( key ) but \p pred is used for key comparing. + \p Less functor has the interface like \p std::less. + \p Less must imply the same element order as the comparator used for building the set. */ template + bool contains( Q const& key, Less pred ) + { + return find_with( key, pred, [](value_type& , Q const& ) {} ); + } + //@cond + template + CDS_DEPRECATED("use contains()") bool find_with( Q const& val, Less pred ) { - return find_with( val, pred, [](value_type& , Q const& ) {} ); + return contains( val, pred ); } + //@endcond /// Clears the set /** diff --git a/cds/intrusive/striped_set/adapter.h b/cds/intrusive/striped_set/adapter.h index a34ab4f4..3125bec6 100644 --- a/cds/intrusive/striped_set/adapter.h +++ b/cds/intrusive/striped_set/adapter.h @@ -52,11 +52,11 @@ namespace cds { namespace intrusive { The user-defined functor \p f is called only if the inserting is success.
- Ensures that the \p item exists in the container - \code template std::pair ensure( value_type& val, Func f ) \endcode + Updates the item in the container + \code template std::pair update( value_type& val, Func f, bool bAllowInsert = true ) \endcode The operation performs inserting or changing data. - If the \p val key not found in the container, then \p val is inserted. + If the \p val key not found in the container, then \p val is inserted iff \p bAllowInsert is \p true. Otherwise, the functor \p f is called with the item found. The \p Func functor has the following interface: @@ -73,7 +73,7 @@ namespace cds { namespace intrusive { where arguments are: - \p bNew - \p true if the item has been inserted, \p false otherwise - \p item - container's item - - \p val - argument \p val passed into the \p ensure function + - \p val - argument \p val passed into the \p update() function If \p val has been inserted (i.e. bNew == true) then \p item and \p val are the same element: &item == &val. Otherwise, they are different. @@ -223,11 +223,20 @@ namespace cds { namespace intrusive { } template - std::pair ensure( value_type& val, Func f ) + std::pair update( value_type& val, Func f, bool bAllowInsert ) { - std::pair res = m_Set.insert( val ); - f( res.second, *res.first, val ); - return std::make_pair( true, res.second ); + if ( bAllowInsert ) { + std::pair res = m_Set.insert( val ); + f( res.second, *res.first, val ); + return std::make_pair( true, res.second ); + } + else { + auto it = m_Set.find( val ); + if ( it == m_Set.end() ) + return std::make_pair( false, false ); + f( false, *it, val ); + return std::make_pair( true, false ); + } } bool unlink( value_type& val ) diff --git a/cds/intrusive/striped_set/boost_list.h b/cds/intrusive/striped_set/boost_list.h index 588873cd..e8e7b8d3 100644 --- a/cds/intrusive/striped_set/boost_list.h +++ b/cds/intrusive/striped_set/boost_list.h @@ -87,11 +87,14 @@ namespace cds { namespace intrusive { namespace striped_set { } template - std::pair ensure( value_type& val, Func f ) + std::pair update( value_type& val, Func f, bool bAllowInsert ) { iterator it = find_key( val, find_predicate() ); if ( it == m_List.end() || key_comparator()(val, *it) != 0 ) { // insert new + if ( !bAllowInsert ) + return std::make_pair( false, false ); + m_List.insert( it, val ); f( true, val, val ); return std::make_pair( true, true ); diff --git a/cds/intrusive/striped_set/boost_slist.h b/cds/intrusive/striped_set/boost_slist.h index 871ab5e0..fa17643a 100644 --- a/cds/intrusive/striped_set/boost_slist.h +++ b/cds/intrusive/striped_set/boost_slist.h @@ -111,11 +111,14 @@ namespace cds { namespace intrusive { namespace striped_set { } template - std::pair ensure( value_type& val, Func f ) + std::pair update( value_type& val, Func f, bool bAllowInsert ) { std::pair< iterator, bool > pos = find_prev_item( val ); if ( !pos.second ) { // insert new + if ( !bAllowInsert ) + return std::make_pair( false, false ); + m_List.insert_after( pos.first, val ); f( true, val, val ); return std::make_pair( true, true ); diff --git a/cds/intrusive/striped_set/boost_unordered_set.h b/cds/intrusive/striped_set/boost_unordered_set.h index a6b37445..b80ee9e5 100644 --- a/cds/intrusive/striped_set/boost_unordered_set.h +++ b/cds/intrusive/striped_set/boost_unordered_set.h @@ -83,11 +83,20 @@ namespace cds { namespace intrusive { namespace striped_set { } template - std::pair ensure( value_type& val, Func f ) + std::pair update( value_type& val, Func f, bool bAllowInsert ) { - std::pair res = m_Set.insert( val ); - f( res.second, *res.first, val ); - return std::make_pair( true, res.second ); + if ( bAllowInsert ) { + std::pair res = m_Set.insert( val ); + f( res.second, *res.first, val ); + return std::make_pair( true, res.second ); + } + else { + auto it = m_Set.find( val ); + if ( it == m_Set.end() ) + return std::make_pair( false, false ); + f( false, *it, val ); + return std::make_pair( true, false ); + } } bool unlink( value_type& val ) diff --git a/projects/Win/vc12/unit-map-find.vcxproj b/projects/Win/vc12/unit-map-find.vcxproj index 04e203c1..ec8ae23c 100644 --- a/projects/Win/vc12/unit-map-find.vcxproj +++ b/projects/Win/vc12/unit-map-find.vcxproj @@ -48,7 +48,7 @@ - + diff --git a/projects/Win/vc12/unit-map-find.vcxproj.filters b/projects/Win/vc12/unit-map-find.vcxproj.filters index 7bdd4a8f..ff0be0d8 100644 --- a/projects/Win/vc12/unit-map-find.vcxproj.filters +++ b/projects/Win/vc12/unit-map-find.vcxproj.filters @@ -16,9 +16,6 @@ map_find_int - - map_find_int - map_find_int @@ -91,6 +88,9 @@ map_insfind_int + + map_find_int + diff --git a/projects/source.unit.map.mk b/projects/source.unit.map.mk index 93749f10..953e74ee 100644 --- a/projects/source.unit.map.mk +++ b/projects/source.unit.map.mk @@ -5,10 +5,10 @@ CDSUNIT_MAP_SOURCES := \ tests/unit/map2/map_find_int_cuckoo.cpp \ tests/unit/map2/map_find_int_ellentree.cpp \ tests/unit/map2/map_find_int_michael.cpp \ + tests/unit/map2/map_find_int_multilevelhashmap.cpp \ tests/unit/map2/map_find_int_skip.cpp \ tests/unit/map2/map_find_int_split.cpp \ tests/unit/map2/map_find_int_striped.cpp \ - tests/unit/map2/map_find_int_refinable.cpp \ tests/unit/map2/map_find_int_std.cpp \ tests/unit/map2/map_find_string.cpp \ tests/unit/map2/map_find_string_bronsonavltree.cpp \ diff --git a/tests/unit/map2/CMakeLists.txt b/tests/unit/map2/CMakeLists.txt index 98194774..1e87f1ac 100644 --- a/tests/unit/map2/CMakeLists.txt +++ b/tests/unit/map2/CMakeLists.txt @@ -6,10 +6,10 @@ set(CDSUNIT_MAP_SOURCES map_find_int_cuckoo.cpp map_find_int_ellentree.cpp map_find_int_michael.cpp + map_find_int_multilevelhashmap.cpp map_find_int_skip.cpp map_find_int_split.cpp map_find_int_striped.cpp - map_find_int_refinable.cpp map_find_int_std.cpp map_find_string.cpp map_find_string_bronsonavltree.cpp diff --git a/tests/unit/map2/map_defs.h b/tests/unit/map2/map_defs.h index 644f9cb6..e4cabfec 100644 --- a/tests/unit/map2/map_defs.h +++ b/tests/unit/map2/map_defs.h @@ -12,6 +12,14 @@ CPPUNIT_TEST(StdMap_Mutex) \ CPPUNIT_TEST(StdHashMap_Mutex) \ +#define CDSUNIT_DECLARE_StdMap_NoLock \ + TEST_CASE(tag_StdMap, StdMap_NoLock) \ + TEST_CASE(tag_StdMap, StdHashMap_NoLock) \ + +#define CDSUNIT_TEST_StdMap_NoLock \ + CPPUNIT_TEST(StdMap_NoLock) \ + CPPUNIT_TEST(StdHashMap_NoLock) \ + // ************************************************************************************** // MichaelMap diff --git a/tests/unit/map2/map_find_int.cpp b/tests/unit/map2/map_find_int.cpp index 7eddd466..23dced06 100644 --- a/tests/unit/map2/map_find_int.cpp +++ b/tests/unit/map2/map_find_int.cpp @@ -8,13 +8,6 @@ namespace map2 { CPPUNIT_TEST_SUITE_REGISTRATION( Map_find_int ); - size_t Map_find_int::c_nThreadCount = 8 ; // thread count - size_t Map_find_int::c_nMapSize = 20000000 ; // map size (count of searching item) - size_t Map_find_int::c_nPercentExists = 50 ; // percent of existing keys in searching sequence - size_t Map_find_int::c_nPassCount = 2; - size_t Map_find_int::c_nMaxLoadFactor = 8 ; // maximum load factor - bool Map_find_int::c_bPrintGCState = true; - void Map_find_int::generateSequence() { size_t nPercent = c_nPercentExists; @@ -36,18 +29,6 @@ namespace map2 { shuffle( m_Arr.begin(), m_Arr.end() ); } - void Map_find_int::initTestSequence() - { - CPPUNIT_MSG( "Generating test data..."); - cds::OS::Timer timer; - generateSequence(); - CPPUNIT_MSG( " Duration=" << timer.duration() ); - CPPUNIT_MSG( "Map size=" << m_nRealMapSize << " find key loop=" << m_Arr.size() << " (" << c_nPercentExists << "% success)" ); - CPPUNIT_MSG( "Thread count=" << c_nThreadCount << " Pass count=" << c_nPassCount ); - - m_bSequenceInitialized = true; - } - void Map_find_int::setUpParams( const CppUnitMini::TestCfg& cfg ) { c_nThreadCount = cfg.getSizeT("ThreadCount", c_nThreadCount ); @@ -56,23 +37,22 @@ namespace map2 { c_nPassCount = cfg.getSizeT("PassCount", c_nPassCount); c_nMaxLoadFactor = cfg.getSizeT("MaxLoadFactor", c_nMaxLoadFactor); c_bPrintGCState = cfg.getBool("PrintGCStateFlag", c_bPrintGCState ); - } - void Map_find_int::myRun(const char *in_name, bool invert /*= false*/) - { - setUpParams( m_Cfg.get( "Map_find_int" )); + c_nCuckooInitialSize = cfg.getSizeT("CuckooInitialSize", c_nCuckooInitialSize); + c_nCuckooProbesetSize = cfg.getSizeT("CuckooProbesetSize", c_nCuckooProbesetSize); + c_nCuckooProbesetThreshold = cfg.getSizeT("CuckooProbesetThreshold", c_nCuckooProbesetThreshold); - run_MichaelMap(in_name, invert); - run_SplitList(in_name, invert); - run_SkipListMap(in_name, invert); - run_EllenBinTreeMap(in_name, invert); - run_BronsonAVLTreeMap(in_name, invert); - run_StripedMap(in_name, invert); - run_RefinableMap(in_name, invert); - run_CuckooMap(in_name, invert); - run_StdMap(in_name, invert); + c_nMultiLevelMap_HeadBits = cfg.getSizeT("MultiLevelMapHeadBits", c_nMultiLevelMap_HeadBits); + c_nMultiLevelMap_ArrayBits = cfg.getSizeT("MultiLevelMapArrayBits", c_nMultiLevelMap_ArrayBits); - endTestCase(); - } + if ( c_nThreadCount == 0 ) + c_nThreadCount = std::thread::hardware_concurrency(); + CPPUNIT_MSG( "Generating test data..."); + cds::OS::Timer timer; + generateSequence(); + CPPUNIT_MSG( " Duration=" << timer.duration() ); + CPPUNIT_MSG( "Map size=" << m_nRealMapSize << " find key loop=" << m_Arr.size() << " (" << c_nPercentExists << "% success)" ); + CPPUNIT_MSG( "Thread count=" << c_nThreadCount << " Pass count=" << c_nPassCount ); + } } // namespace map diff --git a/tests/unit/map2/map_find_int.h b/tests/unit/map2/map_find_int.h index b7f54789..b4cde503 100644 --- a/tests/unit/map2/map_find_int.h +++ b/tests/unit/map2/map_find_int.h @@ -10,20 +10,28 @@ // find int test in map in mutithreaded mode namespace map2 { -# define TEST_MAP(IMPL, C, X) void C::X() { test::X >(); } -# define TEST_MAP_NOLF(IMPL, C, X) void C::X() { test_nolf::X >(); } -# define TEST_MAP_EXTRACT(IMPL, C, X) TEST_MAP(IMPL, C, X) -# define TEST_MAP_NOLF_EXTRACT(IMPL, C, X) TEST_MAP_NOLF(IMPL, C, X) +#define TEST_CASE(TAG, X) void X(); class Map_find_int: public CppUnitMini::TestCase { - static size_t c_nThreadCount; // thread count - static size_t c_nMapSize; // map size (count of searching item) - static size_t c_nPercentExists; // percent of existing keys in searching sequence - static size_t c_nPassCount; - static size_t c_nMaxLoadFactor; // maximum load factor - static bool c_bPrintGCState; + public: + size_t c_nThreadCount = 8; // thread count + size_t c_nMapSize = 10000000; // map size (count of searching item) + size_t c_nPercentExists = 50; // percent of existing keys in searching sequence + size_t c_nPassCount = 2; + size_t c_nMaxLoadFactor = 8; // maximum load factor + bool c_bPrintGCState = true; + + size_t c_nCuckooInitialSize = 1024;// initial size for CuckooMap + size_t c_nCuckooProbesetSize = 16; // CuckooMap probeset size (only for list-based probeset) + size_t c_nCuckooProbesetThreshold = 0; // CUckooMap probeset threshold (o - use default) + + size_t c_nMultiLevelMap_HeadBits = 10; + size_t c_nMultiLevelMap_ArrayBits = 4; + + size_t c_nLoadFactor; // current load factor + private: typedef CppUnitMini::TestCase Base; typedef size_t key_type; struct value_type { @@ -34,7 +42,6 @@ namespace map2 { typedef std::vector ValueVector; ValueVector m_Arr; size_t m_nRealMapSize; - bool m_bSequenceInitialized; void generateSequence(); @@ -93,14 +100,14 @@ namespace map2 { virtual void test() { ValueVector& arr = getTest().m_Arr; - //size_t nSize = arr.size(); + size_t const nPassCount = getTest().c_nPassCount; Map& rMap = m_Map; - for ( size_t nPass = 0; nPass < c_nPassCount; ++nPass ) { + for ( size_t nPass = 0; nPass < nPassCount; ++nPass ) { if ( m_nThreadNo & 1 ) { ValueVector::const_iterator itEnd = arr.end(); for ( ValueVector::const_iterator it = arr.begin(); it != itEnd; ++it ) { - auto bFound = rMap.find( it->nKey ); + auto bFound = rMap.contains( it->nKey ); if ( it->bExists ) { if ( check_result( bFound, rMap )) ++m_KeyExists.nSuccess; @@ -122,7 +129,7 @@ namespace map2 { else { ValueVector::const_reverse_iterator itEnd = arr.rend(); for ( ValueVector::const_reverse_iterator it = arr.rbegin(); it != itEnd; ++it ) { - auto bFound = rMap.find( it->nKey ); + auto bFound = rMap.contains( it->nKey ); if ( it->bExists ) { if ( check_result( bFound, rMap )) ++m_KeyExists.nSuccess; @@ -185,52 +192,31 @@ namespace map2 { additional_cleanup( testMap ); } - void initTestSequence(); - template - void test() + void run_test() { - if ( !m_bSequenceInitialized ) - initTestSequence(); - - for ( size_t nLoadFactor = 1; nLoadFactor <= c_nMaxLoadFactor; nLoadFactor *= 2 ) { - CPPUNIT_MSG( "Load factor=" << nLoadFactor ); - Map testMap( c_nMapSize, nLoadFactor ); + if ( Map::c_bLoadFactorDepended ) { + for ( c_nLoadFactor = 1; c_nLoadFactor <= c_nMaxLoadFactor; c_nLoadFactor *= 2 ) { + CPPUNIT_MSG( "Load factor=" << c_nLoadFactor ); + Map testMap( *this ); + find_int_test( testMap ); + if ( c_bPrintGCState ) + print_gc_state(); + } + } + else { + Map testMap( *this ); find_int_test( testMap ); if ( c_bPrintGCState ) print_gc_state(); } } - template - void test_nolf() - { - if ( !m_bSequenceInitialized ) - initTestSequence(); - - Map testMap; - find_int_test( testMap ); - if ( c_bPrintGCState ) - print_gc_state(); - } - void setUpParams( const CppUnitMini::TestCfg& cfg ); - void run_MichaelMap(const char *in_name, bool invert = false); - void run_SplitList(const char *in_name, bool invert = false); - void run_StripedMap(const char *in_name, bool invert = false); - void run_RefinableMap(const char *in_name, bool invert = false); - void run_CuckooMap(const char *in_name, bool invert = false); - void run_SkipListMap(const char *in_name, bool invert = false); - void run_EllenBinTreeMap(const char *in_name, bool invert = false); - void run_BronsonAVLTreeMap(const char *in_name, bool invert = false); - void run_StdMap(const char *in_name, bool invert = false); - - virtual void myRun(const char *in_name, bool invert = false); - public: Map_find_int() - : m_bSequenceInitialized( false ) + : c_nLoadFactor(2) {} # include "map2/map_defs.h" @@ -242,9 +228,28 @@ namespace map2 { CDSUNIT_DECLARE_SkipListMap_nogc CDSUNIT_DECLARE_EllenBinTreeMap CDSUNIT_DECLARE_BronsonAVLTreeMap + CDSUNIT_DECLARE_MultiLevelHashMap CDSUNIT_DECLARE_StripedMap CDSUNIT_DECLARE_RefinableMap CDSUNIT_DECLARE_CuckooMap CDSUNIT_DECLARE_StdMap + CDSUNIT_DECLARE_StdMap_NoLock + + CPPUNIT_TEST_SUITE(Map_find_int) + CDSUNIT_TEST_MichaelMap + CDSUNIT_TEST_MichaelMap_nogc + CDSUNIT_TEST_SplitList + CDSUNIT_TEST_SplitList_nogc + CDSUNIT_TEST_SkipListMap + CDSUNIT_TEST_SkipListMap_nogc + CDSUNIT_TEST_EllenBinTreeMap + CDSUNIT_TEST_BronsonAVLTreeMap + CDSUNIT_TEST_MultiLevelHashMap + CDSUNIT_TEST_CuckooMap + CDSUNIT_TEST_StripedMap + CDSUNIT_TEST_RefinableMap + CDSUNIT_TEST_StdMap + CDSUNIT_TEST_StdMap_NoLock + CPPUNIT_TEST_SUITE_END(); }; } // namespace map diff --git a/tests/unit/map2/map_find_int_bronsonavltree.cpp b/tests/unit/map2/map_find_int_bronsonavltree.cpp index 6cd051c0..11e78f30 100644 --- a/tests/unit/map2/map_find_int_bronsonavltree.cpp +++ b/tests/unit/map2/map_find_int_bronsonavltree.cpp @@ -3,10 +3,10 @@ #include "map2/map_find_int.h" #include "map2/map_type_bronson_avltree.h" -namespace map2 { - CDSUNIT_DEFINE_BronsonAVLTreeMap( cc::bronson_avltree::implementation_tag, Map_find_int) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Map_find_int::X() { run_test::X>(); } +#include "map2/map_defs.h" - CPPUNIT_TEST_SUITE_PART( Map_find_int, run_BronsonAVLTreeMap ) - CDSUNIT_TEST_BronsonAVLTreeMap - CPPUNIT_TEST_SUITE_END_PART() +namespace map2 { + CDSUNIT_DECLARE_BronsonAVLTreeMap } // namespace map2 diff --git a/tests/unit/map2/map_find_int_cuckoo.cpp b/tests/unit/map2/map_find_int_cuckoo.cpp index 3bdc562e..02b2adb5 100644 --- a/tests/unit/map2/map_find_int_cuckoo.cpp +++ b/tests/unit/map2/map_find_int_cuckoo.cpp @@ -3,10 +3,10 @@ #include "map2/map_find_int.h" #include "map2/map_type_cuckoo.h" -namespace map2 { - CDSUNIT_DEFINE_CuckooMap(cds::intrusive::cuckoo::implementation_tag, Map_find_int) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Map_find_int::X() { run_test::X>(); } +#include "map2/map_defs.h" - CPPUNIT_TEST_SUITE_PART( Map_find_int, run_CuckooMap ) - CDSUNIT_TEST_CuckooMap - CPPUNIT_TEST_SUITE_END_PART() +namespace map2 { + CDSUNIT_DECLARE_CuckooMap } // namespace map2 diff --git a/tests/unit/map2/map_find_int_ellentree.cpp b/tests/unit/map2/map_find_int_ellentree.cpp index 6d930f83..905b5b9b 100644 --- a/tests/unit/map2/map_find_int_ellentree.cpp +++ b/tests/unit/map2/map_find_int_ellentree.cpp @@ -3,10 +3,10 @@ #include "map2/map_find_int.h" #include "map2/map_type_ellen_bintree.h" -namespace map2 { - CDSUNIT_DEFINE_EllenBinTreeMap( cc::ellen_bintree::implementation_tag, Map_find_int) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Map_find_int::X() { run_test::X>(); } +#include "map2/map_defs.h" - CPPUNIT_TEST_SUITE_PART( Map_find_int, run_EllenBinTreeMap ) - CDSUNIT_TEST_EllenBinTreeMap - CPPUNIT_TEST_SUITE_END_PART() +namespace map2 { + CDSUNIT_DECLARE_EllenBinTreeMap } // namespace map2 diff --git a/tests/unit/map2/map_find_int_michael.cpp b/tests/unit/map2/map_find_int_michael.cpp index 137951a5..00bea765 100644 --- a/tests/unit/map2/map_find_int_michael.cpp +++ b/tests/unit/map2/map_find_int_michael.cpp @@ -3,12 +3,11 @@ #include "map2/map_find_int.h" #include "map2/map_type_michael.h" -namespace map2 { - CDSUNIT_DEFINE_MichaelMap( cc::michael_map::implementation_tag, Map_find_int ) - CDSUNIT_DEFINE_MichaelMap_nogc( cc::michael_map::implementation_tag, Map_find_int ) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Map_find_int::X() { run_test::X>(); } +#include "map2/map_defs.h" - CPPUNIT_TEST_SUITE_PART( Map_find_int, run_MichaelMap ) - CDSUNIT_TEST_MichaelMap - CDSUNIT_TEST_MichaelMap_nogc - CPPUNIT_TEST_SUITE_END_PART() +namespace map2 { + CDSUNIT_DECLARE_MichaelMap + CDSUNIT_DECLARE_MichaelMap_nogc } // namespace map2 diff --git a/tests/unit/map2/map_find_int_multilevelhashmap.cpp b/tests/unit/map2/map_find_int_multilevelhashmap.cpp new file mode 100644 index 00000000..e606fe01 --- /dev/null +++ b/tests/unit/map2/map_find_int_multilevelhashmap.cpp @@ -0,0 +1,12 @@ +//$$CDS-header$$ + +#include "map2/map_find_int.h" +#include "map2/map_type_multilevel_hashmap.h" + +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Map_find_int::X() { run_test::X>(); } +#include "map2/map_defs.h" + +namespace map2 { + CDSUNIT_DECLARE_MultiLevelHashMap +} // namespace map2 diff --git a/tests/unit/map2/map_find_int_refinable.cpp b/tests/unit/map2/map_find_int_refinable.cpp deleted file mode 100644 index 710576c5..00000000 --- a/tests/unit/map2/map_find_int_refinable.cpp +++ /dev/null @@ -1,12 +0,0 @@ -//$$CDS-header$$ - -#include "map2/map_find_int.h" -#include "map2/map_type_striped.h" - -namespace map2 { - CDSUNIT_DEFINE_RefinableMap(cc::striped_set::implementation_tag, Map_find_int) - - CPPUNIT_TEST_SUITE_PART( Map_find_int, run_RefinableMap ) - CDSUNIT_TEST_RefinableMap - CPPUNIT_TEST_SUITE_END_PART() -} // namespace map2 diff --git a/tests/unit/map2/map_find_int_skip.cpp b/tests/unit/map2/map_find_int_skip.cpp index 6ede5c51..717a85fd 100644 --- a/tests/unit/map2/map_find_int_skip.cpp +++ b/tests/unit/map2/map_find_int_skip.cpp @@ -3,12 +3,11 @@ #include "map2/map_find_int.h" #include "map2/map_type_skip_list.h" -namespace map2 { - CDSUNIT_DEFINE_SkipListMap( cc::skip_list::implementation_tag, Map_find_int) - CDSUNIT_DEFINE_SkipListMap_nogc( cc::skip_list::implementation_tag, Map_find_int) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Map_find_int::X() { run_test::X>(); } +#include "map2/map_defs.h" - CPPUNIT_TEST_SUITE_PART( Map_find_int, run_SkipListMap ) - CDSUNIT_TEST_SkipListMap - CDSUNIT_TEST_SkipListMap_nogc - CPPUNIT_TEST_SUITE_END_PART() +namespace map2 { + CDSUNIT_DECLARE_SkipListMap + CDSUNIT_DECLARE_SkipListMap_nogc } // namespace map2 diff --git a/tests/unit/map2/map_find_int_split.cpp b/tests/unit/map2/map_find_int_split.cpp index 08b71fa2..78b55ea2 100644 --- a/tests/unit/map2/map_find_int_split.cpp +++ b/tests/unit/map2/map_find_int_split.cpp @@ -3,12 +3,11 @@ #include "map2/map_find_int.h" #include "map2/map_type_split_list.h" -namespace map2 { - CDSUNIT_DEFINE_SplitList( cc::split_list::implementation_tag, Map_find_int ) - CDSUNIT_DEFINE_SplitList_nogc( cc::split_list::implementation_tag, Map_find_int ) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Map_find_int::X() { run_test::X>(); } +#include "map2/map_defs.h" - CPPUNIT_TEST_SUITE_PART( Map_find_int, run_SplitList ) - CDSUNIT_TEST_SplitList - CDSUNIT_TEST_SplitList_nogc - CPPUNIT_TEST_SUITE_END_PART() +namespace map2 { + CDSUNIT_DECLARE_SplitList + CDSUNIT_DECLARE_SplitList_nogc } // namespace map2 diff --git a/tests/unit/map2/map_find_int_std.cpp b/tests/unit/map2/map_find_int_std.cpp index c310c474..1ced0c28 100644 --- a/tests/unit/map2/map_find_int_std.cpp +++ b/tests/unit/map2/map_find_int_std.cpp @@ -3,10 +3,11 @@ #include "map2/map_find_int.h" #include "map2/map_type_std.h" -namespace map2 { - CDSUNIT_DEFINE_StdMap( map2::std_implementation_tag, Map_find_int) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Map_find_int::X() { run_test::X>(); } +#include "map2/map_defs.h" - CPPUNIT_TEST_SUITE_PART( Map_find_int, run_StdMap ) - CDSUNIT_TEST_StdMap - CPPUNIT_TEST_SUITE_END_PART() +namespace map2 { + CDSUNIT_DECLARE_StdMap + CDSUNIT_DECLARE_StdMap_NoLock } // namespace map2 diff --git a/tests/unit/map2/map_find_int_striped.cpp b/tests/unit/map2/map_find_int_striped.cpp index 23b1c393..d73f6c66 100644 --- a/tests/unit/map2/map_find_int_striped.cpp +++ b/tests/unit/map2/map_find_int_striped.cpp @@ -3,10 +3,11 @@ #include "map2/map_find_int.h" #include "map2/map_type_striped.h" -namespace map2 { - CDSUNIT_DEFINE_StripedMap(cc::striped_set::implementation_tag, Map_find_int) +#undef TEST_CASE +#define TEST_CASE(TAG, X) void Map_find_int::X() { run_test::X>(); } +#include "map2/map_defs.h" - CPPUNIT_TEST_SUITE_PART( Map_find_int, run_StripedMap ) - CDSUNIT_TEST_StripedMap - CPPUNIT_TEST_SUITE_END_PART() +namespace map2 { + CDSUNIT_DECLARE_StripedMap + CDSUNIT_DECLARE_RefinableMap } // namespace map2 diff --git a/tests/unit/map2/map_insdel_func.h b/tests/unit/map2/map_insdel_func.h index 9294fae6..24021abd 100644 --- a/tests/unit/map2/map_insdel_func.h +++ b/tests/unit/map2/map_insdel_func.h @@ -10,12 +10,7 @@ namespace map2 { -# define TEST_CASE(TAG, X) void X(); - -//# define TEST_MAP(IMPL, C, X) void C::X() { test::X >() ; } -//# define TEST_MAP_EXTRACT(IMPL, C, X) TEST_MAP(IMPL, C, X) -//# define TEST_MAP_NOLF(IMPL, C, X) void C::X() { test_nolf::X >() ; } -//# define TEST_MAP_NOLF_EXTRACT(IMPL, C, X) TEST_MAP_NOLF(IMPL, C, X) +#define TEST_CASE(TAG, X) void X(); class Map_InsDel_func: public CppUnitMini::TestCase { @@ -531,7 +526,7 @@ namespace map2 { ); if ( Map::c_bLoadFactorDepended ) { - for ( size_t c_nLoadFactor = 1; c_nLoadFactor <= c_nMaxLoadFactor; c_nLoadFactor *= 2 ) { + for ( c_nLoadFactor = 1; c_nLoadFactor <= c_nMaxLoadFactor; c_nLoadFactor *= 2 ) { CPPUNIT_MSG( "Load factor=" << c_nLoadFactor ); Map testMap( *this ); do_test( testMap ); diff --git a/tests/unit/map2/map_insdel_string.h b/tests/unit/map2/map_insdel_string.h index b56eaf19..372bbd6b 100644 --- a/tests/unit/map2/map_insdel_string.h +++ b/tests/unit/map2/map_insdel_string.h @@ -9,11 +9,6 @@ namespace map2 { #define TEST_CASE(TAG, X) void X(); -//# define TEST_MAP(IMPL, C, X) void C::X() { test::X >(); } -//# define TEST_MAP_NOLF(IMPL, C, X) void C::X() { test_nolf::X >(); } -//# define TEST_MAP_EXTRACT(IMPL, C, X) TEST_MAP(IMPL, C, X) -//# define TEST_MAP_NOLF_EXTRACT(IMPL, C, X) TEST_MAP_NOLF(IMPL, C, X) - class Map_InsDel_string: public CppUnitMini::TestCase { public: @@ -238,8 +233,8 @@ namespace map2 { ); if ( Map::c_bLoadFactorDepended ) { - for ( size_t nLoadFactor = 1; nLoadFactor <= c_nMaxLoadFactor; nLoadFactor *= 2 ) { - CPPUNIT_MSG( "Load factor=" << nLoadFactor ); + for ( c_nLoadFactor = 1; c_nLoadFactor <= c_nMaxLoadFactor; c_nLoadFactor *= 2 ) { + CPPUNIT_MSG( "Load factor=" << c_nLoadFactor ); Map testMap( *this ); do_test( testMap ); if ( c_bPrintGCState ) diff --git a/tests/unit/map2/std_hash_map.h b/tests/unit/map2/std_hash_map.h index 904b5e5e..312f5357 100644 --- a/tests/unit/map2/std_hash_map.h +++ b/tests/unit/map2/std_hash_map.h @@ -39,7 +39,7 @@ namespace map2 { StdHashMap( Config const& ) {} - bool find( const Key& key ) + bool contains( const Key& key ) { scoped_lock al( m_lock ); return base_class::find( key ) != base_class::end(); diff --git a/tests/unit/map2/std_map.h b/tests/unit/map2/std_map.h index 3551071f..cbcbc6df 100644 --- a/tests/unit/map2/std_map.h +++ b/tests/unit/map2/std_map.h @@ -28,7 +28,7 @@ namespace map2 { StdMap( Config const& ) {} - bool find( const Key& key ) + bool contains( const Key& key ) { scoped_lock al( m_lock ); return base_class::find( key ) != base_class::end(); -- 2.34.1