49class multi_type_vector
52 using size_type = std::size_t;
53 using block_funcs =
typename Traits::block_funcs;
75 struct block_slot_type
81 block_slot_type()
noexcept(std::is_fundamental_v<size_type>)
83 block_slot_type(size_type _position, size_type _size)
noexcept(std::is_fundamental_v<size_type>)
90 std::vector<size_type> positions;
91 std::vector<size_type> sizes;
92 std::vector<base_element_block*> element_blocks;
94 static constexpr bool nothrow_default_constructible_v =
95 std::is_nothrow_default_constructible_v<std::vector<size_type>> &&
96 std::is_nothrow_default_constructible_v<std::vector<base_element_block*>>;
98 static constexpr bool nothrow_move_constructible_v =
99 std::is_nothrow_move_constructible_v<std::vector<size_type>> &&
100 std::is_nothrow_move_constructible_v<std::vector<base_element_block*>>;
102 static constexpr bool nothrow_value_swappable_v =
103 noexcept(std::swap(std::declval<size_type&>(), std::declval<size_type&>())) &&
104 noexcept(std::swap(std::declval<base_element_block*&>(), std::declval<base_element_block*&>()));
106 static constexpr bool nothrow_swappable_v = std::is_nothrow_swappable_v<std::vector<size_type>> &&
107 std::is_nothrow_swappable_v<std::vector<base_element_block*>>;
109 blocks_type() noexcept(nothrow_default_constructible_v);
110 blocks_type(mtv::detail::clone_construction_type, const blocks_type& other);
111 blocks_type(const blocks_type& other);
112 blocks_type(blocks_type&& other) noexcept(nothrow_move_constructible_v);
116 positions.pop_back();
118 element_blocks.pop_back();
123 positions.push_back(pos);
124 sizes.push_back(
size);
125 element_blocks.push_back(data);
128 void push_back(
const block_slot_type& slot)
130 positions.push_back(slot.position);
131 sizes.push_back(slot.size);
132 element_blocks.push_back(slot.element_block);
135 void erase(size_type index);
136 void erase(size_type index, size_type
size);
137 void insert(size_type index, size_type
size);
138 void insert(size_type index, size_type pos, size_type
size, base_element_block* data);
139 void insert(size_type index,
const blocks_type& new_blocks);
147 void calc_block_position(size_type index);
149 size_type calc_next_block_position(size_type index);
151 void swap(size_type index1, size_type index2)
noexcept(nothrow_value_swappable_v);
153 void swap(blocks_type& other)
noexcept(nothrow_swappable_v);
155 void reserve(size_type n);
157 bool equals(
const blocks_type& other)
const;
161 void check_integrity()
const;
164 struct blocks_to_transfer
167 size_type insert_index = 0;
170 struct iterator_trait
172 using parent = multi_type_vector;
173 using positions_type = std::vector<size_type>;
174 using sizes_type = std::vector<size_type>;
175 using element_blocks_type = std::vector<base_element_block*>;
177 using positions_iterator_type =
typename positions_type::iterator;
178 using sizes_iterator_type =
typename sizes_type::iterator;
179 using element_blocks_iterator_type =
typename element_blocks_type::iterator;
181 using private_data_update = mdds::detail::mtv::private_data_forward_update<multi_type_vector, size_type>;
184 struct const_iterator_trait
186 using parent = multi_type_vector;
187 using positions_type = std::vector<size_type>;
188 using sizes_type = std::vector<size_type>;
189 using element_blocks_type = std::vector<base_element_block*>;
191 using positions_iterator_type =
typename positions_type::const_iterator;
192 using sizes_iterator_type =
typename sizes_type::const_iterator;
193 using element_blocks_iterator_type =
typename element_blocks_type::const_iterator;
195 using private_data_update = mdds::detail::mtv::private_data_forward_update<multi_type_vector, size_type>;
198 struct reverse_iterator_trait
200 using parent = multi_type_vector;
201 using positions_type = std::vector<size_type>;
202 using sizes_type = std::vector<size_type>;
203 using element_blocks_type = std::vector<base_element_block*>;
205 using positions_iterator_type =
typename positions_type::reverse_iterator;
206 using sizes_iterator_type =
typename sizes_type::reverse_iterator;
207 using element_blocks_iterator_type =
typename element_blocks_type::reverse_iterator;
209 using private_data_update = mdds::detail::mtv::private_data_no_update<multi_type_vector, size_type>;
212 struct const_reverse_iterator_trait
214 using parent = multi_type_vector;
215 using positions_type = std::vector<size_type>;
216 using sizes_type = std::vector<size_type>;
217 using element_blocks_type = std::vector<base_element_block*>;
219 using positions_iterator_type =
typename positions_type::const_reverse_iterator;
220 using sizes_iterator_type =
typename sizes_type::const_reverse_iterator;
221 using element_blocks_iterator_type =
typename element_blocks_type::const_reverse_iterator;
223 using private_data_update = mdds::detail::mtv::private_data_no_update<multi_type_vector, size_type>;
226 struct element_block_deleter
228 void operator()(
const base_element_block* p)
230 block_funcs::delete_block(p);
234 static constexpr bool nothrow_default_constructible_v = std::is_nothrow_default_constructible_v<event_func> &&
235 std::is_nothrow_default_constructible_v<blocks_type> &&
236 std::is_nothrow_default_constructible_v<size_type>;
238 static constexpr bool nothrow_move_constructible_v = std::is_nothrow_move_constructible_v<event_func> &&
239 std::is_nothrow_move_constructible_v<blocks_type> &&
240 std::is_nothrow_move_constructible_v<size_type>;
242 static constexpr bool nothrow_swappable_v = std::is_nothrow_swappable_v<event_func> &&
243 std::is_nothrow_swappable_v<size_type> &&
244 std::is_nothrow_swappable_v<blocks_type>;
246 static constexpr bool nothrow_move_assignable_v = nothrow_move_constructible_v && nothrow_swappable_v;
248 multi_type_vector(mtv::detail::clone_construction_type,
const multi_type_vector& other);
251 using iterator = detail::iterator_base<iterator_trait>;
252 using const_iterator = detail::const_iterator_base<const_iterator_trait, iterator>;
254 using reverse_iterator = detail::iterator_base<reverse_iterator_trait>;
255 using const_reverse_iterator = detail::const_iterator_base<const_reverse_iterator_trait, reverse_iterator>;
257 using position_type = std::pair<iterator, size_type>;
258 using const_position_type = std::pair<const_iterator, size_type>;
327 static size_type
logical_position(
const const_position_type& pos)
noexcept(std::is_fundamental_v<size_type>);
337 template<
typename _Blk>
338 static typename _Blk::value_type
get(
const const_position_type& pos);
371 multi_type_vector(size_type init_size);
383 multi_type_vector(size_type init_size, const T& value);
399 multi_type_vector(size_type init_size, const T& it_begin, const T& it_end);
406 multi_type_vector(const multi_type_vector& other);
413 multi_type_vector(multi_type_vector&& other) noexcept(nothrow_move_constructible_v);
418 ~multi_type_vector();
472 position_type
position(const iterator& pos_hint, size_type pos);
505 const_position_type
position(const const_iterator& pos_hint, size_type pos) const;
531 iterator
transfer(size_type start_pos, size_type end_pos, multi_type_vector& dest, size_type dest_pos);
561 const iterator& pos_hint, size_type start_pos, size_type end_pos, multi_type_vector& dest, size_type dest_pos);
580 iterator
set(size_type pos, const T& value);
615 iterator
set(const iterator& pos_hint, size_type pos, const T& value);
639 iterator
set(size_type pos, const T& it_begin, const T& it_end);
679 iterator
set(const iterator& pos_hint, size_type pos, const T& it_begin, const T& it_end);
726 template<typename T, typename... Args>
751 iterator
insert(size_type pos, const T& it_begin, const T& it_end);
791 iterator
insert(const iterator& pos_hint, size_type pos, const T& it_begin, const T& it_end);
828 iterator
set_empty(size_type start_pos, size_type end_pos);
859 iterator
set_empty(const iterator& pos_hint, size_type start_pos, size_type end_pos);
876 void erase(size_type start_pos, size_type end_pos);
932 iterator
insert_empty(const iterator& pos_hint, size_type pos, size_type length);
984 void get(size_type pos, T& value) const;
998 T
get(size_type pos) const;
1014 template<typename T>
1033 template<typename T>
1055 template<typename T>
1056 iterator
release(const iterator& pos_hint, size_type pos, T& value);
1109 iterator
release_range(const iterator& pos_hint, size_type start_pos, size_type end_pos);
1114 const_iterator begin() const;
1115 const_iterator end() const;
1117 const_iterator cbegin() const;
1118 const_iterator cend() const;
1120 reverse_iterator rbegin();
1121 reverse_iterator rend();
1123 const_reverse_iterator rbegin() const;
1124 const_reverse_iterator rend() const;
1126 const_reverse_iterator crbegin() const;
1127 const_reverse_iterator crend() const;
1143 void swap(multi_type_vector& other) noexcept(nothrow_swappable_v);
1153 void swap(size_type start_pos, size_type end_pos, multi_type_vector& other, size_type other_pos);
1160 bool operator==(const multi_type_vector& other) const;
1161 bool operator!=(const multi_type_vector& other) const;
1163 multi_type_vector& operator=(const multi_type_vector& other);
1164 multi_type_vector& operator=(multi_type_vector&& other) noexcept(nothrow_move_assignable_v);
1173 template<typename T>
1176#ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
1177 void dump_blocks(std::ostream& os)
const;
1179 void check_block_integrity()
const;
1183 void delete_element_block(size_type block_index);
1185 void delete_element_blocks(size_type start, size_type end);
1187 template<
typename T>
1188 void get_impl(size_type pos, T& value)
const;
1190 template<
typename T>
1191 bool set_cells_precheck(size_type row,
const T& it_begin,
const T& it_end, size_type& end_pos);
1193 template<
typename T>
1194 iterator set_impl(size_type pos, size_type block_index,
const T& value);
1196 template<
typename T>
1197 iterator release_impl(size_type pos, size_type block_index, T& value);
1200 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos, size_type block_index1,
1201 size_type block_index2, size_type dblock_index1, size_type dblock_index2);
1203 void swap_single_block(
1204 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos, size_type block_index,
1205 size_type other_block_index);
1207 void swap_single_to_multi_blocks(
1208 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos, size_type block_index,
1209 size_type dst_block_index1, size_type dst_block_index2);
1211 void swap_multi_to_multi_blocks(
1212 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos, size_type block_index1,
1213 size_type block_index2, size_type dblock_index1, size_type dblock_index2);
1215 template<
typename T>
1216 iterator insert_cells_impl(size_type row, size_type block_index,
const T& it_begin,
const T& it_end);
1218 void resize_impl(size_type new_size);
1224 iterator transfer_multi_blocks(
1225 size_type start_pos, size_type end_pos, size_type block_index1, size_type block_index2, multi_type_vector& dest,
1226 size_type dest_pos);
1236 iterator set_empty_impl(size_type start_pos, size_type end_pos, size_type block_index1,
bool overwrite);
1238 iterator set_empty_in_single_block(size_type start_row, size_type end_row, size_type block_index,
bool overwrite);
1249 iterator set_empty_in_multi_blocks(
1250 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
bool overwrite);
1252 void erase_impl(size_type start_pos, size_type end_pos);
1253 void erase_in_single_block(size_type start_pos, size_type end_pos, size_type block_index);
1260 iterator insert_empty_impl(size_type pos, size_type block_index, size_type length);
1262 void insert_blocks_at(size_type
position, size_type insert_pos, blocks_type& new_blocks);
1264 void prepare_blocks_to_transfer(
1265 blocks_to_transfer& bucket, size_type block_index1, size_type offset1, size_type block_index2,
1268 iterator set_whole_block_empty(size_type block_index,
bool overwrite);
1270 template<
typename T>
1271 iterator push_back_impl(T&& value);
1273 template<
typename T,
typename... Args>
1274 iterator emplace_back_impl(Args&&... args);
1276 template<
typename T>
1277 iterator set_cells_impl(
1278 size_type row, size_type end_row, size_type block_index1,
const T& it_begin,
const T& it_end);
1280 template<
typename T>
1281 iterator set_cells_to_single_block(
1282 size_type start_row, size_type end_row, size_type block_index,
const T& it_begin,
const T& it_end);
1284 template<
typename T>
1285 iterator set_cells_to_multi_blocks(
1286 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
const T& it_begin,
1289 template<
typename T>
1290 iterator set_cells_to_multi_blocks_block1_non_equal(
1291 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
const T& it_begin,
1294 template<
typename T>
1295 iterator set_cells_to_multi_blocks_block1_non_empty(
1296 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
const T& it_begin,
1299 template<
typename T>
1300 iterator set_cell_to_empty_block(size_type block_index, size_type pos_in_block,
const T& cell);
1302 template<
typename T>
1303 iterator set_cell_to_non_empty_block_of_size_one(size_type block_index,
const T& cell);
1314 size_type get_block_position(size_type row, size_type start_block_index = 0)
const;
1320 size_type get_block_position(
const typename value_type::private_data& pos_data, size_type row)
const;
1322 template<
typename T>
1323 void create_new_block_with_new_cell(size_type block_index, T&& cell);
1325 template<
typename T,
typename... Args>
1326 void create_new_block_with_emplace_back(size_type block_index,
const T& t, Args&&... args);
1328 template<
typename T>
1329 void append_cell_to_block(size_type block_index,
const T& cell);
1338 template<
typename T>
1339 bool append_to_prev_block(
1340 size_type block_index, element_t cat, size_type length,
const T& it_begin,
const T& it_end);
1342 template<
typename T>
1343 void insert_cells_to_middle(size_type row, size_type block_index,
const T& it_begin,
const T& it_end);
1345 template<
typename T>
1346 iterator set_cell_to_middle_of_block(size_type block_index, size_type pos_in_block,
const T& cell);
1353 template<
typename T>
1354 void set_cell_to_top_of_data_block(size_type block_index,
const T& cell);
1356 template<
typename T>
1357 void set_cell_to_bottom_of_data_block(size_type block_index,
const T& cell);
1359 iterator transfer_impl(
1360 size_type start_pos, size_type end_pos, size_type block_index1, multi_type_vector& dest, size_type dest_pos);
1365 iterator transfer_single_block(
1366 size_type start_pos, size_type end_pos, size_type block_index1, multi_type_vector& dest, size_type dest_pos);
1376 size_type merge_with_adjacent_blocks(size_type block_index);
1385 bool merge_with_next_block(size_type block_index);
1400 size_type set_new_block_to_middle(
1401 size_type block_index, size_type offset, size_type new_block_size,
bool overwrite);
1412 bool is_previous_block_of_type(size_type block_index, element_t cat)
const;
1423 bool is_next_block_of_type(size_type block_index, element_t cat)
const;
1447 const base_element_block& src_data, size_type src_offset, size_type dst_index, size_type dst_offset,
1450 void exchange_elements(
1451 const base_element_block& src_blk, size_type src_offset, size_type dst_index1, size_type dst_offset1,
1452 size_type dst_index2, size_type dst_offset2, size_type len, blocks_type& new_blocks);
1454 bool append_empty(size_type len);
1456 inline iterator get_iterator(size_type block_index)
1458 auto iter_pos = m_block_store.positions.begin();
1459 std::advance(iter_pos, block_index);
1460 auto iter_size = m_block_store.sizes.begin();
1461 std::advance(iter_size, block_index);
1462 auto iter_elem = m_block_store.element_blocks.begin();
1463 std::advance(iter_elem, block_index);
1466 {iter_pos, iter_size, iter_elem},
1467 {m_block_store.positions.end(), m_block_store.sizes.end(), m_block_store.element_blocks.end()},
this,
1471 inline const_iterator get_const_iterator(size_type block_index)
const
1473 auto iter_pos = m_block_store.positions.cbegin();
1474 std::advance(iter_pos, block_index);
1475 auto iter_size = m_block_store.sizes.cbegin();
1476 std::advance(iter_size, block_index);
1477 auto iter_elem = m_block_store.element_blocks.cbegin();
1478 std::advance(iter_elem, block_index);
1480 return const_iterator(
1481 {iter_pos, iter_size, iter_elem},
1482 {m_block_store.positions.cend(), m_block_store.sizes.cend(), m_block_store.element_blocks.cend()},
this,
1486#ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
1487 void debug_check_full(std::string_view location);
1491 using adjust_block_positions_func = detail::adjust_block_positions<blocks_type, Traits::loop_unrolling>;
1494 blocks_type m_block_store;
1495 size_type m_cur_size;
1497#ifdef MDDS_MULTI_TYPE_VECTOR_TRACE
1498 mutable int m_trace_call_depth = 0;