3 #ifndef __CDS_INTRUSIVE_STRIPED_SET_RESIZING_POLICY_H
4 #define __CDS_INTRUSIVE_STRIPED_SET_RESIZING_POLICY_H
6 #include <cds/opt/options.h>
8 namespace cds { namespace intrusive { namespace striped_set {
10 /// Load factor based resizing policy
12 When total item count in a container exceeds
13 <tt>container.bucket_count() * LoadFactor</tt>
14 then resizing is needed.
16 This policy is stateless.
18 The <tt>reset()</tt> function is called after the resizing is done.
19 The function is intended for resetting internal state of the policy.
21 template <size_t LoadFactor>
22 struct load_factor_resizing
24 /// Main policy operator returns \p true when resizing is needed
25 template <typename Container, typename Bucket>
27 size_t nSize, ///< Current item count of \p container
28 Container const& container, ///< Container
29 Bucket const& /*bucket*/ ///< reference to a container's bucket (not used)
32 return nSize > container.bucket_count() * LoadFactor;
35 /// Resets internal state of the policy (does nothing)
40 /// Load factor based resizing policy, stateful specialization
42 This specialization allows to specify a load factor at runtime.
45 struct load_factor_resizing<0>
48 const size_t m_nLoadFactor;
51 /// Default ctor, load factor is 4
52 load_factor_resizing()
56 /// Ctor with explicitly defined \p nLoadFactor
57 explicit load_factor_resizing( size_t nLoadFactor )
58 : m_nLoadFactor( nLoadFactor )
62 load_factor_resizing( load_factor_resizing const& src )
63 : m_nLoadFactor( src.m_nLoadFactor )
66 # ifdef CDS_RVALUE_SUPPORT
67 /// Move ctor (for the compilers supporting rvalue reference)
68 load_factor_resizing( load_factor_resizing&& src )
69 : m_nLoadFactor( src.m_nLoadFactor )
73 /// Main policy operator returns \p true when resizing is needed
74 template <typename Container, typename Bucket>
76 size_t nSize, ///< Current item count of \p container
77 Container const& container, ///< Container
78 Bucket const& /*bucket*/ ///< reference to a container's bucket (not used)
81 return nSize > container.bucket_count() * m_nLoadFactor;
84 /// Resets internal state of the policy (does nothing)
90 /// Single bucket threshold resizing policy
92 If any single bucket size exceeds the global \p Threshold then resizing is needed.
94 This policy is stateless.
96 template <size_t Threshold>
97 struct single_bucket_size_threshold
99 /// Main policy operator returns \p true when resizing is needed
100 template <typename Container, typename Bucket>
102 size_t /*nSize*/, ///< Current item count of \p container (not used)
103 Container const& /*container*/, ///< Container (not used)
104 Bucket const& bucket ///< reference to a container's bucket
107 return bucket.size() > Threshold;
110 /// Resets internal state of the policy (does nothing)
116 /// Single bucket threshold resizing policy, stateful specialization
118 This specialization allows to specify and modify a threshold at runtime.
121 struct single_bucket_size_threshold<0>
123 size_t m_nThreshold ; ///< The bucket size threshold
125 /// Default ctor, the threshold is 4
126 single_bucket_size_threshold()
130 /// Ctor with explicitly defined \p nThreshold
131 explicit single_bucket_size_threshold( size_t nThreshold )
132 : m_nThreshold( nThreshold )
136 single_bucket_size_threshold( single_bucket_size_threshold const& src )
137 : m_nThreshold( src.m_nThreshold )
140 # ifdef CDS_RVALUE_SUPPORT
141 /// Move ctor (for the compilers supporting rvalue reference)
142 single_bucket_size_threshold( single_bucket_size_threshold&& src )
143 : m_nThreshold( src.m_nThreshold )
147 /// Main policy operator returns \p true when resizing is needed
148 template <typename Container, typename Bucket>
150 size_t /*nSize*/, ///< Current item count of \p container (not used)
151 Container const& /*container*/, ///< Container (not used)
152 Bucket const& bucket ///< reference to a container's bucket
155 return bucket.size() > m_nThreshold;
158 /// Resets internal state of the policy (does nothing)
163 /// Dummy resizing policy
165 This policy is dummy and always returns \p false that means no resizing is needed.
167 This policy is stateless.
171 /// Main policy operator always returns \p false
172 template <typename Container, typename Bucket>
174 size_t /*nSize*/, ///< Current item count of \p container (not used)
175 Container const& /*container*/, ///< Container (not used)
176 Bucket const& /*bucket*/ ///< reference to a container's bucket (not used)
182 /// Resets internal state of the policy (does nothing)
187 }}} // namespace cds::intrusive::striped_set
189 #endif // #define __CDS_INTRUSIVE_STRIPED_SET_RESIZING_POLICY_H