9 #include "../../global.hpp"
10 #include "../types.hpp"
11 #include "../util.hpp"
12 #include "./iterator.hpp"
13 #include "./block_util.hpp"
15 #ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
19 namespace mdds {
namespace mtv {
namespace aos {
48 template<
typename Traits = mdds::mtv::default_traits>
52 using size_type = std::size_t;
53 using block_funcs =
typename Traits::block_funcs;
81 block() noexcept(std::is_fundamental_v<size_type>);
82 block(size_type _position, size_type _size) noexcept(std::is_fundamental_v<size_type>);
84 std::is_fundamental_v<size_type>);
85 block(
const block& other) =
default;
86 block(block&& other) =
default;
89 block& operator=(
const block&) =
default;
90 block& operator=(block&&) =
default;
92 void swap(block& other) noexcept(std::is_fundamental_v<size_type>);
95 struct element_block_deleter
99 block_funcs::delete_block(p);
103 typedef std::vector<block> blocks_type;
105 struct blocks_to_transfer
108 size_type insert_index;
110 blocks_to_transfer();
113 struct iterator_trait
116 typedef blocks_type blocks;
117 typedef typename blocks_type::iterator base_iterator;
120 struct reverse_iterator_trait
123 typedef blocks_type blocks;
124 typedef typename blocks_type::reverse_iterator base_iterator;
127 struct const_iterator_trait
130 typedef blocks_type blocks;
131 typedef typename blocks_type::const_iterator base_iterator;
134 struct const_reverse_iterator_trait
137 typedef blocks_type blocks;
138 typedef typename blocks_type::const_reverse_iterator base_iterator;
145 static constexpr
bool nothrow_default_constructible_v = std::is_nothrow_default_constructible_v<event_func> &&
146 std::is_nothrow_default_constructible_v<blocks_type> &&
147 std::is_nothrow_default_constructible_v<size_type>;
149 static constexpr
bool nothrow_move_constructible_v = std::is_nothrow_move_constructible_v<event_func> &&
150 std::is_nothrow_move_constructible_v<blocks_type> &&
151 std::is_nothrow_move_constructible_v<size_type>;
153 static constexpr
bool nothrow_swappable_v = std::is_nothrow_swappable_v<event_func> &&
154 std::is_nothrow_swappable_v<size_type> &&
155 std::is_nothrow_swappable_v<blocks_type>;
157 static constexpr
bool nothrow_move_assignable_v = nothrow_move_constructible_v && nothrow_swappable_v;
162 typedef detail::iterator_base<iterator_trait, itr_forward_update> iterator;
163 typedef detail::iterator_base<reverse_iterator_trait, itr_no_update> reverse_iterator;
165 typedef detail::const_iterator_base<const_iterator_trait, itr_forward_update, iterator> const_iterator;
166 typedef detail::const_iterator_base<const_reverse_iterator_trait, itr_no_update, reverse_iterator>
167 const_reverse_iterator;
186 typedef std::pair<iterator, size_type> position_type;
187 typedef std::pair<const_iterator, size_type> const_position_type;
197 static position_type
next_position(
const position_type& pos);
218 static const_position_type
next_position(
const const_position_type& pos);
229 static const_position_type
advance_position(
const const_position_type& pos,
int steps);
239 static size_type
logical_position(
const const_position_type& pos) noexcept(std::is_fundamental_v<size_type>);
249 template<
typename Blk>
250 static typename Blk::value_type
get(
const const_position_type& pos);
255 const_iterator begin()
const;
256 const_iterator end()
const;
258 const_iterator cbegin()
const;
259 const_iterator cend()
const;
261 reverse_iterator rbegin();
262 reverse_iterator rend();
264 const_reverse_iterator rbegin()
const;
265 const_reverse_iterator rend()
const;
267 const_reverse_iterator crbegin()
const;
268 const_reverse_iterator crend()
const;
382 iterator
set(size_type pos, const T& value);
417 iterator
set(const iterator& pos_hint, size_type pos, const T& value);
441 iterator
set(size_type pos, const T& it_begin, const T& it_end);
481 iterator
set(const iterator& pos_hint, size_type pos, const T& it_begin, const T& it_end);
528 template<typename T, typename... Args>
553 iterator
insert(size_type pos, const T& it_begin, const T& it_end);
593 iterator
insert(const iterator& pos_hint, size_type pos, const T& it_begin, const T& it_end);
606 void get(size_type pos, T& value) const;
620 T
get(size_type pos) const;
656 iterator
release(size_type pos, T& value);
678 iterator
release(const iterator& pos_hint, size_type pos, T& value);
705 iterator
release_range(size_type start_pos, size_type end_pos);
731 iterator
release_range(const iterator& pos_hint, size_type start_pos, size_type end_pos);
749 position_type
position(size_type pos);
770 position_type
position(const iterator& pos_hint, size_type pos);
785 const_position_type
position(size_type pos) const;
803 const_position_type
position(const const_iterator& pos_hint, size_type pos) const;
859 const iterator& pos_hint, size_type start_pos, size_type end_pos,
multi_type_vector& dest, size_type dest_pos);
868 mtv::element_t
get_type(size_type pos) const;
896 iterator
set_empty(size_type start_pos, size_type end_pos);
927 iterator
set_empty(const iterator& pos_hint, size_type start_pos, size_type end_pos);
944 void erase(size_type start_pos, size_type end_pos);
1000 iterator
insert_empty(const iterator& pos_hint, size_type pos, size_type length);
1013 size_type
size() const noexcept(std::is_nothrow_copy_constructible_v<size_type>);
1039 bool empty() const noexcept;
1048 void resize(size_type new_size);
1085 template<typename T>
1088 #ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
1089 void dump_blocks(std::ostream& os)
const;
1091 void check_block_integrity()
const;
1101 void delete_element_block(block& blk);
1110 void delete_element_blocks(
typename blocks_type::iterator it,
typename blocks_type::iterator it_end);
1112 template<
typename T>
1113 iterator set_impl(size_type pos, size_type block_index,
const T& value);
1115 template<
typename T>
1116 iterator release_impl(size_type pos, size_type block_index, T& value);
1118 template<
typename T>
1119 iterator push_back_impl(T&& value);
1121 template<
typename T,
typename... Args>
1122 iterator emplace_back_impl(Args&&... args);
1133 size_type get_block_position(size_type row, size_type start_block_index = 0)
const;
1141 void resize_impl(size_type new_size);
1143 template<
typename T>
1146 template<
typename T,
typename... Args>
1147 void create_new_block_with_emplace_back(
base_element_block*& data,
const T& t, Args&&... args);
1149 template<
typename T>
1150 iterator set_cell_to_middle_of_block(size_type block_index, size_type pos_in_block,
const T& cell);
1152 template<
typename T>
1153 void append_cell_to_block(size_type block_index,
const T& cell);
1155 template<
typename T>
1156 iterator set_cell_to_empty_block(size_type block_index, size_type pos_in_block,
const T& cell);
1158 template<
typename T>
1159 iterator set_cell_to_block_of_size_one(size_type block_index,
const T& cell);
1161 template<
typename T>
1162 void set_cell_to_top_of_data_block(size_type block_index,
const T& cell);
1164 template<
typename T>
1165 void set_cell_to_bottom_of_data_block(size_type block_index,
const T& cell);
1167 iterator transfer_impl(
1168 size_type start_pos, size_type end_pos, size_type block_index1,
multi_type_vector& dest, size_type dest_pos);
1173 iterator transfer_single_block(
1174 size_type start_pos, size_type end_pos, size_type block_index1,
multi_type_vector& dest, size_type dest_pos);
1180 iterator transfer_multi_blocks(
1181 size_type start_pos, size_type end_pos, size_type block_index1, size_type block_index2,
multi_type_vector& dest,
1182 size_type dest_pos);
1192 iterator set_empty_impl(size_type start_pos, size_type end_pos, size_type block_index1,
bool overwrite);
1195 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos, size_type block_index1,
1196 size_type block_index2, size_type dblock_index1, size_type dblock_index2);
1198 void swap_single_block(
1199 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos, size_type block_index,
1200 size_type other_block_index);
1202 void swap_single_to_multi_blocks(
1203 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos, size_type block_index,
1204 size_type dst_block_index1, size_type dst_block_index2);
1206 void swap_multi_to_multi_blocks(
1207 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos, size_type block_index1,
1208 size_type block_index2, size_type dblock_index1, size_type dblock_index2);
1210 void insert_blocks_at(size_type
position, size_type insert_pos, blocks_type& new_blocks);
1212 void prepare_blocks_to_transfer(
1213 blocks_to_transfer& bucket, size_type block_index1, size_type offset1, size_type block_index2,
1216 iterator set_whole_block_empty(size_type block_index,
bool overwrite);
1218 iterator set_empty_in_single_block(size_type start_row, size_type end_row, size_type block_index,
bool overwrite);
1229 iterator set_empty_in_multi_blocks(
1230 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
bool overwrite);
1232 void erase_impl(size_type start_pos, size_type end_pos);
1233 void erase_in_single_block(size_type start_pos, size_type end_pos, size_type block_pos);
1240 iterator insert_empty_impl(size_type pos, size_type block_index, size_type length);
1242 template<
typename T>
1243 iterator set_cells_impl(
1244 size_type row, size_type end_row, size_type block_index1,
const T& it_begin,
const T& it_end);
1246 template<
typename T>
1247 iterator insert_cells_impl(size_type row, size_type block_index,
const T& it_begin,
const T& it_end);
1249 template<
typename T>
1250 iterator set_cells_to_single_block(
1251 size_type start_row, size_type end_row, size_type block_index,
const T& it_begin,
const T& it_end);
1253 template<
typename T>
1254 iterator set_cells_to_multi_blocks(
1255 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
const T& it_begin,
1258 template<
typename T>
1259 iterator set_cells_to_multi_blocks_block1_non_equal(
1260 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
const T& it_begin,
1263 template<
typename T>
1264 iterator set_cells_to_multi_blocks_block1_non_empty(
1265 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
const T& it_begin,
1276 size_type merge_with_adjacent_blocks(size_type block_index);
1285 bool merge_with_next_block(size_type block_index);
1287 template<
typename T>
1288 bool append_to_prev_block(
1289 size_type block_index, element_t cat, size_type length,
const T& it_begin,
const T& it_end);
1291 template<
typename T>
1292 void insert_cells_to_middle(size_type row, size_type block_index,
const T& it_begin,
const T& it_end);
1307 block& set_new_block_to_middle(size_type block_index, size_type offset, size_type new_block_size,
bool overwrite);
1309 block* get_previous_block_of_type(size_type block_index, element_t cat);
1318 block* get_next_block_of_type(size_type block_index, element_t cat);
1338 const base_element_block& src_data, size_type src_offset, size_type dst_index, size_type dst_offset,
1341 void exchange_elements(
1342 const base_element_block& src_data, size_type src_offset, size_type dst_index1, size_type dst_offset1,
1343 size_type dst_index2, size_type dst_offset2, size_type len, blocks_type& new_blocks);
1345 bool append_empty(size_type len);
1347 inline iterator get_iterator(size_type block_index)
1349 typename blocks_type::iterator block_pos = m_blocks.begin();
1350 std::advance(block_pos, block_index);
1351 return iterator(block_pos, m_blocks.end(),
this, block_index);
1354 inline const_iterator get_const_iterator(size_type block_index)
const
1356 typename blocks_type::const_iterator block_pos = m_blocks.begin();
1357 std::advance(block_pos, block_index);
1358 return const_iterator(block_pos, m_blocks.end(),
this, block_index);
1361 #ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
1362 void debug_check_full(std::string_view location);
1366 using adjust_block_positions_func = detail::adjust_block_positions<blocks_type, Traits::loop_unrolling>;
1369 blocks_type m_blocks;
1370 size_type m_cur_size;
1375 #include "main_def.inl"
static mtv::element_t get_element_type(const T &elem)
Definition: iterator_node.hpp:18
size_type block_size() const noexcept
static position_type next_position(const position_type &pos)
static size_type logical_position(const const_position_type &pos) noexcept(std::is_fundamental_v< size_type >)
iterator insert_empty(size_type pos, size_type length)
iterator emplace_back(Args &&...args)
typename Traits::event_func event_func
Definition: main.hpp:72
Definition: iterator_node.hpp:85
iterator insert(size_type pos, const T &it_begin, const T &it_end)
void resize(size_type new_size)
static Blk::value_type get(const const_position_type &pos)
iterator push_back_empty()
multi_type_vector() noexcept(nothrow_default_constructible_v)
void swap(multi_type_vector &other) noexcept(nothrow_swappable_v)
iterator release_range(size_type start_pos, size_type end_pos)
Definition: iterator_node.hpp:74
size_type size() const noexcept(std::is_nothrow_copy_constructible_v< size_type >)
position_type position(size_type pos)
iterator transfer(size_type start_pos, size_type end_pos, multi_type_vector &dest, size_type dest_pos)
static position_type advance_position(const position_type &pos, int steps)
Definition: cref_wrapper.hpp:12
multi_type_vector clone() const
iterator set(size_type pos, const T &value)
Definition: types.hpp:134
void erase(size_type start_pos, size_type end_pos)
bool empty() const noexcept
itr_node value_type
Definition: main.hpp:184
iterator set_empty(size_type start_pos, size_type end_pos)
iterator push_back(T &&value)
bool is_empty(size_type pos) const
mtv::element_t get_type(size_type pos) const
Definition: iterator_node.hpp:42