3 #include "set/hdr_striped_set.h"
4 #include <cds/container/striped_set/std_hash_set.h>
5 #include <cds/container/striped_set.h>
6 #include <cds/sync/spinlock.h>
14 bool operator ()( T const& i1, T const& i2) const
16 return i1.key() == i2.key();
20 typedef std::unordered_set< StripedSetHdrTest::item, StripedSetHdrTest::hash_int, equal_item > set_t;
22 struct my_copy_policy {
23 typedef set_t::iterator iterator;
25 void operator()( set_t& set, iterator itWhat )
27 set.insert( std::make_pair(itWhat->key(), itWhat->val()) );
32 void StripedSetHdrTest::Striped_hashset()
34 CPPUNIT_MESSAGE( "cmp");
35 typedef cc::StripedSet< set_t
36 , co::hash< hash_int >
37 , co::compare< cmp<item> >
38 ,co::mutex_policy< cc::striped_set::striping<> >
40 test_striped< set_cmp >();
42 CPPUNIT_MESSAGE( "less");
43 typedef cc::StripedSet< set_t
44 , co::hash< hash_int >
45 , co::less< less<item> >
46 ,co::mutex_policy< cc::striped_set::striping<> >
48 test_striped< set_less >();
50 CPPUNIT_MESSAGE( "cmpmix");
51 typedef cc::StripedSet< set_t
52 , co::hash< hash_int >
53 , co::compare< cmp<item> >
54 , co::less< less<item> >
55 ,co::mutex_policy< cc::striped_set::striping<> >
57 test_striped< set_cmpmix >();
59 // Spinlock as lock policy
60 CPPUNIT_MESSAGE( "spinlock");
61 typedef cc::StripedSet< set_t
62 , co::hash< hash_int >
63 , co::less< less<item> >
64 , co::mutex_policy< cc::striped_set::striping< cds::sync::spin> >
66 test_striped< set_spin >();
69 CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
71 typedef cc::StripedSet< set_t
72 , co::hash< hash_int >
73 , co::less< less<item> >
74 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
75 > set_less_resizing_lf;
76 set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>( 1024 ));
77 test_striped_with( s );
80 CPPUNIT_MESSAGE( "load_factor_resizing<256>");
81 typedef cc::StripedSet< set_t
82 , co::hash< hash_int >
83 , co::less< less<item> >
84 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
85 > set_less_resizing_lf16;
86 test_striped< set_less_resizing_lf16 >();
88 CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024");
90 typedef cc::StripedSet< set_t
91 , co::hash< hash_int >
92 , co::less< less<item> >
93 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
94 > set_less_resizing_sbt;
95 set_less_resizing_sbt s( 30, cc::striped_set::single_bucket_size_threshold<0>(1024));
99 CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
100 typedef cc::StripedSet< set_t
101 , co::hash< hash_int >
102 , co::less< less<item> >
103 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
104 > set_less_resizing_sbt16;
105 test_striped< set_less_resizing_sbt16 >();
108 CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
109 typedef cc::StripedSet< set_t
110 , co::hash< hash_int >
111 , co::compare< cmp<item> >
112 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
113 , co::copy_policy< cc::striped_set::copy_item >
115 test_striped< set_copy_item >();
117 CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
118 typedef cc::StripedSet< set_t
119 , co::hash< hash_int >
120 , co::compare< cmp<item> >
121 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
122 , co::copy_policy< cc::striped_set::swap_item >
124 test_striped< set_swap_item >();
126 CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
127 typedef cc::StripedSet< set_t
128 , co::hash< hash_int >
129 , co::compare< cmp<item> >
130 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
131 , co::copy_policy< cc::striped_set::move_item >
133 test_striped< set_move_item >();
135 CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_item");
136 typedef cc::StripedSet< set_t
137 , co::hash< hash_int >
138 , co::compare< cmp<item> >
139 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
140 , co::copy_policy< my_copy_policy >
141 > set_special_copy_item;
142 test_striped< set_special_copy_item >();