9 #ifndef LIBPMEMOBJ_SEGMENT_VECTOR_POLICIES_HPP
10 #define LIBPMEMOBJ_SEGMENT_VECTOR_POLICIES_HPP
21 namespace segment_vector_internal
26 template <
typename Container>
28 decltype(std::declval<Container>().resize(std::declval<size_t>()));
30 template <
typename Container>
31 using container_has_resize = detail::supports<Container, resize_method>;
33 template <typename Container, bool = container_has_resize<Container>::value>
34 struct segment_vector_resize {
35 using segment_vector_type = Container;
38 resize(segment_vector_type &c,
size_t n)
44 template <
typename Container>
45 struct segment_vector_resize<Container, false> {
46 using segment_vector_type = Container;
49 resize(segment_vector_type &c,
size_t n)
54 template <
template <
typename>
class SegmentVectorType,
55 template <
typename>
class SegmentType,
size_t SegmentSize>
56 class fixed_size_policy {
60 using segment_vector_type = SegmentVectorType<SegmentType<T>>;
63 using segment_type = SegmentType<T>;
66 using value_type =
typename segment_type<T>::value_type;
68 using size_type = std::size_t;
71 using segment_vector_resize_type =
72 segment_vector_resize<segment_vector_type<T>>;
74 static constexpr size_type Size = SegmentSize;
78 resize(segment_vector_type<T> &c, size_type n)
80 segment_vector_resize_type<T>::resize(c, n);
89 get_segment(size_type index)
99 segment_top(size_type segment_index)
101 return segment_index * Size;
109 segment_size(size_type segment_index)
119 index_in_segment(size_type index)
127 template <
typename T>
129 max_size(
const segment_vector_type<T> &seg_storage)
131 return seg_storage.max_size() * SegmentSize;
138 capacity(size_type segment_index)
140 return (segment_index + 1) * Size;
144 template <
template <
typename>
class SegmentVectorType,
145 template <
typename>
class SegmentType>
146 class exponential_size_policy {
149 template <
typename T>
150 using segment_vector_type = SegmentVectorType<SegmentType<T>>;
152 template <
typename T>
153 using segment_type = SegmentType<T>;
155 template <
typename T>
156 using value_type =
typename segment_type<T>::value_type;
158 using size_type = std::size_t;
160 template <
typename T>
161 using segment_vector_resize_type =
162 segment_vector_resize<segment_vector_type<T>>;
164 template <
typename T>
166 resize(segment_vector_type<T> &c, size_type n)
168 segment_vector_resize_type<T>::resize(c, n);
177 get_segment(size_type index)
179 return static_cast<size_type
>(detail::Log2(index | 1));
187 segment_top(size_type segment_index)
189 return (size_type(1) << segment_index) & ~size_type(1);
197 segment_size(size_type segment_index)
199 return (segment_index == 0) ? 2 : segment_top(segment_index);
207 index_in_segment(size_type index)
209 return index - segment_top(get_segment(index));
215 template <
typename T>
217 max_size(
const segment_vector_type<T> &)
219 return segment_size(get_segment(PMEMOBJ_MAX_ALLOC_SIZE /
220 sizeof(value_type<T>)) +
228 capacity(size_type segment_index)
230 if (segment_index == 0)
232 return segment_size(segment_index) * 2;
Array container with std::array compatible interface.
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Persistent container with std::array compatible interface.
Definition: array.hpp:57
Commonly used SFINAE helpers.
Vector container with std::vector compatible interface.