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
11 /** @ingroup cds_striped_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
41 /** @ingroup cds_striped_resizing_policy
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 )
67 load_factor_resizing( load_factor_resizing&& src )
68 : m_nLoadFactor( src.m_nLoadFactor )
71 /// Main policy operator returns \p true when resizing is needed
72 template <typename Container, typename Bucket>
74 size_t nSize, ///< Current item count of \p container
75 Container const& container, ///< Container
76 Bucket const& /*bucket*/ ///< reference to a container's bucket (not used)
79 return nSize > container.bucket_count() * m_nLoadFactor;
82 /// Resets internal state of the policy (does nothing)
88 /// Single bucket threshold resizing policy
89 /** @ingroup cds_striped_resizing_policy
90 If any single bucket size exceeds the global \p Threshold then resizing is needed.
92 This policy is stateless.
94 template <size_t Threshold>
95 struct single_bucket_size_threshold
97 /// Main policy operator returns \p true when resizing is needed
98 template <typename Container, typename Bucket>
100 size_t /*nSize*/, ///< Current item count of \p container (not used)
101 Container const& /*container*/, ///< Container (not used)
102 Bucket const& bucket ///< reference to a container's bucket
105 return bucket.size() > Threshold;
108 /// Resets internal state of the policy (does nothing)
114 /// Single bucket threshold resizing policy, stateful specialization
115 /** @ingroup cds_striped_resizing_policy
116 This specialization allows to specify and modify a threshold at runtime.
119 struct single_bucket_size_threshold<0>
121 size_t m_nThreshold ; ///< The bucket size threshold
123 /// Default ctor, the threshold is 4
124 single_bucket_size_threshold()
128 /// Ctor with explicitly defined \p nThreshold
129 explicit single_bucket_size_threshold( size_t nThreshold )
130 : m_nThreshold( nThreshold )
134 single_bucket_size_threshold( single_bucket_size_threshold const& src )
135 : m_nThreshold( src.m_nThreshold )
139 single_bucket_size_threshold( single_bucket_size_threshold&& src )
140 : m_nThreshold( src.m_nThreshold )
143 /// Main policy operator returns \p true when resizing is needed
144 template <typename Container, typename Bucket>
146 size_t /*nSize*/, ///< Current item count of \p container (not used)
147 Container const& /*container*/, ///< Container (not used)
148 Bucket const& bucket ///< reference to a container's bucket
151 return bucket.size() > m_nThreshold;
154 /// Resets internal state of the policy (does nothing)
159 /// Dummy resizing policy
160 /** @ingroup cds_striped_resizing_policy
161 This policy is dummy and always returns \p false that means no resizing is needed.
163 This policy is stateless.
167 /// Main policy operator always returns \p false
168 template <typename Container, typename Bucket>
170 size_t /*nSize*/, ///< Current item count of \p container (not used)
171 Container const& /*container*/, ///< Container (not used)
172 Bucket const& /*bucket*/ ///< reference to a container's bucket (not used)
178 /// Resets internal state of the policy (does nothing)
183 }}} // namespace cds::intrusive::striped_set
185 #endif // #define __CDS_INTRUSIVE_STRIPED_SET_RESIZING_POLICY_H