Migrated intrusive StripedSet to gtest framework
authorkhizmax <libcds.dev@gmail.com>
Tue, 22 Mar 2016 19:57:59 +0000 (22:57 +0300)
committerkhizmax <libcds.dev@gmail.com>
Tue, 22 Mar 2016 19:57:59 +0000 (22:57 +0300)
projects/Win/vc14/gtest-striped-set.vcxproj
projects/Win/vc14/gtest-striped-set.vcxproj.filters
test/unit/striped-set/CMakeLists.txt
test/unit/striped-set/intrusive_boost_unordered_set.cpp [new file with mode: 0644]
test/unit/striped-set/test_intrusive_set.h

index 8b5384dca1a08173ded11eb3173386f06ed7ab3d..482b02e85cfc466d1e6f6080670e1c9b9d5baf25 100644 (file)
@@ -43,6 +43,7 @@
       <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='DebugVLD|x64'">_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
       <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\..\test\unit\striped-set\intrusive_boost_unordered_set.cpp" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\..\..\test\unit\striped-set\test_intrusive_striped_set.h" />\r
index 9683579a758fc4fd0bbd1fa1681c2786303973bf..dd452fec8fb287f0bc4177697d9f6660724838b6 100644 (file)
@@ -42,6 +42,9 @@
     <ClCompile Include="..\..\..\test\unit\striped-set\intrusive_boost_treap_set.cpp">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\..\test\unit\striped-set\intrusive_boost_unordered_set.cpp">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\..\..\test\unit\striped-set\test_intrusive_set.h">\r
index 3f2a1cabd4ff8c674dd9569264b62d993a98bb69..968c32d70d1fe5ce8c45d7b7e41981376373a1a5 100644 (file)
@@ -11,6 +11,7 @@ set(CDSGTEST_SET_SOURCES
     intrusive_boost_slist.cpp
     intrusive_boost_splay_set.cpp
     intrusive_boost_treap_set.cpp
+    intrusive_boost_unordered_set.cpp
     intrusive_cuckoo_set.cpp
 )
 
diff --git a/test/unit/striped-set/intrusive_boost_unordered_set.cpp b/test/unit/striped-set/intrusive_boost_unordered_set.cpp
new file mode 100644 (file)
index 0000000..84d4ca4
--- /dev/null
@@ -0,0 +1,326 @@
+/*
+    This file is a part of libcds - Concurrent Data Structures library
+
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+
+    Source code repo: http://github.com/khizmax/libcds/
+    Download: http://sourceforge.net/projects/libcds/files/
+    
+    Redistribution and use in source and binary forms, with or without
+    modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this
+      list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
+*/
+
+#ifndef CDSUNIT_SET_TEST_INTRUSIVE_BOOST_UNORDERED_SET_H
+#define CDSUNIT_SET_TEST_INTRUSIVE_BOOST_UNORDERED_SET_H
+
+#ifdef CDSUNIT_ENABLE_BOOST_CONTAINER
+
+#include "test_intrusive_set.h"
+
+#include <cds/intrusive/striped_set/boost_unordered_set.h>
+#include <cds/intrusive/striped_set.h>
+
+namespace {
+    namespace ci = cds::intrusive;
+    namespace bi = boost::intrusive;
+
+    class IntrusiveStripedBoostUnorderedSet: public cds_test::intrusive_set
+    {
+    public:
+        typedef base_int_item< bi::unordered_set_base_hook<>> base_item;
+        typedef member_int_item< bi::unordered_set_member_hook<>> member_item;
+    };
+
+    template <size_t Capacity, typename T, class Alloc = CDS_DEFAULT_ALLOCATOR>
+    struct dyn_buffer: public ci::opt::v::dynamic_buffer< T, Alloc >
+    {
+        typedef ci::opt::v::dynamic_buffer< T, Alloc >   base_class;
+    public:
+        template <typename Q>
+        struct rebind {
+            typedef dyn_buffer<Capacity, Q, Alloc> other;  ///< Rebinding result type
+        };
+
+        dyn_buffer()
+            : base_class( Capacity )
+        {}
+    };
+
+    TEST_F( IntrusiveStripedBoostUnorderedSet, basehook )
+    {
+        typedef ci::StripedSet<
+            bi::unordered_set< base_item
+                , bi::hash< hash1 >
+                , bi::equal< equal_to<base_item> >
+                , bi::power_2_buckets<true>
+                , bi::incremental<true>
+            >
+            ,cds::intrusive::opt::hash< hash2 >
+        > set_type;
+
+        std::vector< typename set_type::value_type > data;
+        {
+            set_type s;
+            this->test( s, data );
+        }
+    }
+
+    TEST_F( IntrusiveStripedBoostUnorderedSet, basehook_resize_bucket_threshold )
+    {
+        typedef ci::StripedSet<
+            bi::unordered_set< base_item
+                , bi::hash< hash1 >
+                , bi::equal< equal_to<base_item> >
+                , bi::power_2_buckets<true>
+                , bi::incremental<true>
+            >
+            ,cds::intrusive::opt::hash< hash2 >
+            ,cds::intrusive::opt::buffer< cds::intrusive::opt::v::static_buffer< cds::any_type, 64 > >
+            ,cds::intrusive::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
+        > set_type;
+
+        std::vector< typename set_type::value_type > data;
+        {
+            set_type s;
+            this->test( s, data );
+        }
+    }
+
+    TEST_F( IntrusiveStripedBoostUnorderedSet, basehook_resize_bucket_threshold_rt )
+    {
+        typedef ci::StripedSet<
+            bi::unordered_set< base_item
+                , bi::hash< hash1 >
+                , bi::equal< equal_to<base_item> >
+                , bi::power_2_buckets<true>
+                , bi::incremental<true>
+            >
+            ,ci::opt::hash< hash2 >
+            ,ci::opt::buffer< dyn_buffer<64, cds::any_type>>
+            ,ci::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
+        > set_type;
+
+        std::vector< typename set_type::value_type > data;
+        {
+            set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>( 128 ) );
+            this->test( s, data );
+        }
+    }
+
+    TEST_F( IntrusiveStripedBoostUnorderedSet, memberhook )
+    {
+        typedef ci::StripedSet<
+            bi::unordered_set< member_item
+                , bi::member_hook< member_item, bi::unordered_set_member_hook<>, &member_item::hMember>
+                , bi::hash< hash1 >
+                , bi::equal< equal_to<member_item> >
+                , bi::power_2_buckets<true>
+                , bi::incremental<true>
+            >
+            ,cds::intrusive::opt::hash< hash2 >
+        > set_type;
+
+        std::vector< typename set_type::value_type > data;
+        {
+            set_type s;
+            this->test( s, data );
+        }
+    }
+
+    TEST_F( IntrusiveStripedBoostUnorderedSet, memberhook_resize_bucket_threshold )
+    {
+        typedef ci::StripedSet<
+            bi::unordered_set< member_item
+                , bi::member_hook< member_item, bi::unordered_set_member_hook<>, &member_item::hMember>
+                , bi::hash< hash1 >
+                , bi::equal< equal_to<member_item> >
+                , bi::power_2_buckets<true>
+                , bi::incremental<true>
+            >
+            ,cds::intrusive::opt::hash< hash2 >
+            ,cds::intrusive::opt::buffer< cds::intrusive::opt::v::static_buffer< cds::any_type, 64 > >
+            ,cds::intrusive::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
+        > set_type;
+
+        std::vector< typename set_type::value_type > data;
+        {
+            set_type s;
+            this->test( s, data );
+        }
+    }
+
+    TEST_F( IntrusiveStripedBoostUnorderedSet, memberhook_resize_bucket_threshold_rt )
+    {
+        typedef ci::StripedSet< 
+            bi::unordered_set< member_item
+                , bi::member_hook< member_item, bi::unordered_set_member_hook<>, &member_item::hMember>
+                , bi::hash< hash1 >
+                , bi::equal< equal_to<member_item> >
+                , bi::power_2_buckets<true>
+                , bi::incremental<true>
+            >
+            ,ci::opt::hash< hash2 >
+            ,ci::opt::buffer< dyn_buffer<64, cds::any_type>>
+            ,ci::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
+        > set_type;
+
+        std::vector< typename set_type::value_type > data;
+        {
+            set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>( 128 ) );
+            this->test( s, data );
+        }
+    }
+
+    TEST_F( IntrusiveStripedBoostUnorderedSet, refinable_basehook )
+    {
+        typedef ci::StripedSet<
+            bi::unordered_set< base_item
+                , bi::hash< hash1 >
+                , bi::equal< equal_to<base_item> >
+                , bi::power_2_buckets<true>
+                , bi::incremental<true>
+            >
+            ,cds::intrusive::opt::hash< hash2 >
+            ,ci::opt::mutex_policy< ci::striped_set::refinable<> >
+        > set_type;
+
+        std::vector< typename set_type::value_type > data;
+        {
+            set_type s;
+            this->test( s, data );
+        }
+    }
+
+    TEST_F( IntrusiveStripedBoostUnorderedSet, refinable_basehook_resize_bucket_threshold )
+    {
+        typedef ci::StripedSet<
+            bi::unordered_set< base_item
+                , bi::hash< hash1 >
+                , bi::equal< equal_to<base_item> >
+                , bi::power_2_buckets<true>
+                , bi::incremental<true>
+            >
+            ,ci::opt::mutex_policy< ci::striped_set::refinable<> >
+            ,cds::intrusive::opt::hash< hash2 >
+            ,cds::intrusive::opt::buffer< cds::intrusive::opt::v::static_buffer< cds::any_type, 64 > >
+            ,cds::intrusive::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
+        > set_type;
+
+        std::vector< typename set_type::value_type > data;
+        {
+            set_type s;
+            this->test( s, data );
+        }
+    }
+
+    TEST_F( IntrusiveStripedBoostUnorderedSet, refinable_basehook_resize_bucket_threshold_rt )
+    {
+        typedef ci::StripedSet<
+            bi::unordered_set< base_item
+                , bi::hash< hash1 >
+                , bi::equal< equal_to<base_item> >
+                , bi::power_2_buckets<true>
+                , bi::incremental<true>
+            >
+            ,ci::opt::hash< hash2 >
+            ,ci::opt::mutex_policy< ci::striped_set::refinable<> >
+            ,ci::opt::buffer< dyn_buffer<64, cds::any_type>>
+            ,ci::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
+        > set_type;
+
+        std::vector< typename set_type::value_type > data;
+        {
+            set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>( 128 ) );
+            this->test( s, data );
+        }
+    }
+
+    TEST_F( IntrusiveStripedBoostUnorderedSet, refinable_memberhook )
+    {
+        typedef ci::StripedSet<
+            bi::unordered_set< member_item
+                , bi::member_hook< member_item, bi::unordered_set_member_hook<>, &member_item::hMember>
+                , bi::hash< hash1 >
+                , bi::equal< equal_to<member_item> >
+                , bi::power_2_buckets<true>
+                , bi::incremental<true>
+            >
+            ,cds::intrusive::opt::hash< hash2 >
+            ,ci::opt::mutex_policy< ci::striped_set::refinable<> >
+        > set_type;
+
+        std::vector< typename set_type::value_type > data;
+        {
+            set_type s;
+            this->test( s, data );
+        }
+    }
+
+    TEST_F( IntrusiveStripedBoostUnorderedSet, refinable_memberhook_resize_bucket_threshold )
+    {
+        typedef ci::StripedSet<
+            bi::unordered_set< member_item
+                , bi::member_hook< member_item, bi::unordered_set_member_hook<>, &member_item::hMember>
+                , bi::hash< hash1 >
+                , bi::equal< equal_to<member_item> >
+                , bi::power_2_buckets<true>
+                , bi::incremental<true>
+            >
+            ,cds::intrusive::opt::hash< hash2 >
+            ,ci::opt::mutex_policy< ci::striped_set::refinable<> >
+            ,cds::intrusive::opt::buffer< cds::intrusive::opt::v::static_buffer< cds::any_type, 64 > >
+            ,cds::intrusive::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
+        > set_type;
+
+        std::vector< typename set_type::value_type > data;
+        {
+            set_type s;
+            this->test( s, data );
+        }
+    }
+
+    TEST_F( IntrusiveStripedBoostUnorderedSet, refinable_memberhook_resize_bucket_threshold_rt )
+    {
+        typedef ci::StripedSet< 
+            bi::unordered_set< member_item
+                , bi::member_hook< member_item, bi::unordered_set_member_hook<>, &member_item::hMember>
+                , bi::hash< hash1 >
+                , bi::equal< equal_to<member_item> >
+                , bi::power_2_buckets<true>
+                , bi::incremental<true>
+            >
+            ,ci::opt::hash< hash2 >
+            ,ci::opt::mutex_policy< ci::striped_set::refinable<> >
+            ,ci::opt::buffer< dyn_buffer<64, cds::any_type>>
+            ,ci::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
+        > set_type;
+
+        std::vector< typename set_type::value_type > data;
+        {
+            set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>( 128 ) );
+            this->test( s, data );
+        }
+    }
+
+} // namespace
+
+#endif // #ifdef CDSUNIT_ENABLE_BOOST_CONTAINER
+#endif // CDSUNIT_SET_TEST_INTRUSIVE_BOOST_UNORDERED_SET_H
index 14f672e17e7474694d2a4ba2c957d75719b54dc0..6776f456569363ec7a760ab2ecb60d20666d9365 100644 (file)
@@ -256,14 +256,12 @@ namespace cds_test {
                 return v1.key() == v2.key();
             }
 
-            template <typename Q>
-            int operator ()( const T& v1, const Q& v2 ) const
+            int operator ()( const T& v1, int v2 ) const
             {
                 return v1.key() == v2;
             }
 
-            template <typename Q>
-            int operator ()( const Q& v1, const T& v2 ) const
+            int operator ()( int v1, const T& v2 ) const
             {
                 return v1 == v2.key();
             }