3 #include "set/hdr_striped_set.h"
4 #include <cds/container/striped_set/std_set.h>
5 #include <cds/container/striped_set.h>
6 #include <cds/sync/spinlock.h>
11 struct my_copy_policy {
12 typedef std::set<StripedSetHdrTest::item, StripedSetHdrTest::less<StripedSetHdrTest::item> > set_type;
13 typedef set_type::iterator iterator;
15 void operator()( set_type& set, iterator itWhat )
17 set.insert( std::make_pair(itWhat->key(), itWhat->val()) );
21 typedef std::set<StripedSetHdrTest::item, StripedSetHdrTest::less<StripedSetHdrTest::item> > set_t;
24 void StripedSetHdrTest::Striped_set()
26 CPPUNIT_MESSAGE( "cmp");
27 typedef cc::StripedSet< set_t
28 , co::hash< hash_int >
29 , co::compare< cmp<item> >
30 ,co::mutex_policy< cc::striped_set::striping<> >
32 test_striped< set_cmp >();
34 CPPUNIT_MESSAGE( "less");
35 typedef cc::StripedSet< set_t
36 , co::hash< hash_int >
37 , co::less< less<item> >
38 ,co::mutex_policy< cc::striped_set::striping<> >
40 test_striped< set_less >();
42 CPPUNIT_MESSAGE( "cmpmix");
43 typedef cc::StripedSet< set_t
44 , co::hash< hash_int >
45 , co::compare< cmp<item> >
46 , co::less< less<item> >
47 ,co::mutex_policy< cc::striped_set::striping<> >
49 test_striped< set_cmpmix >();
51 // Spinlock as lock policy
52 CPPUNIT_MESSAGE( "spinlock");
53 typedef cc::StripedSet< set_t
54 , co::hash< hash_int >
55 , co::less< less<item> >
56 , co::mutex_policy< cc::striped_set::striping< cds::sync::spin> >
58 test_striped< set_spin >();
61 CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
63 typedef cc::StripedSet< set_t
64 , co::hash< hash_int >
65 , co::less< less<item> >
66 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
67 > set_less_resizing_lf;
68 set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>( 1024 ));
69 test_striped_with( s );
72 CPPUNIT_MESSAGE( "load_factor_resizing<256>");
73 typedef cc::StripedSet< set_t
74 , co::hash< hash_int >
75 , co::less< less<item> >
76 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
77 > set_less_resizing_lf16;
78 test_striped< set_less_resizing_lf16 >();
80 CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024");
82 typedef cc::StripedSet< set_t
83 , co::hash< hash_int >
84 , co::less< less<item> >
85 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
86 > set_less_resizing_sbt;
87 set_less_resizing_sbt s( 30, cc::striped_set::single_bucket_size_threshold<0>(1024));
91 CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
92 typedef cc::StripedSet< set_t
93 , co::hash< hash_int >
94 , co::less< less<item> >
95 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
96 > set_less_resizing_sbt16;
97 test_striped< set_less_resizing_sbt16 >();
100 CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
101 typedef cc::StripedSet< set_t
102 , co::hash< hash_int >
103 , co::compare< cmp<item> >
104 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
105 , co::copy_policy< cc::striped_set::copy_item >
107 test_striped< set_copy_item >();
109 CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
110 typedef cc::StripedSet< set_t
111 , co::hash< hash_int >
112 , co::compare< cmp<item> >
113 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
114 , co::copy_policy< cc::striped_set::swap_item >
116 test_striped< set_swap_item >();
118 CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
119 typedef cc::StripedSet< set_t
120 , co::hash< hash_int >
121 , co::compare< cmp<item> >
122 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
123 , co::copy_policy< cc::striped_set::move_item >
125 test_striped< set_move_item >();
127 CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_item");
128 typedef cc::StripedSet< set_t
129 , co::hash< hash_int >
130 , co::compare< cmp<item> >
131 , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
132 , co::copy_policy< my_copy_policy >
133 > set_special_copy_item;
134 test_striped< set_special_copy_item >();