29#ifndef INCLUDED_MDDS_MULTI_TYPE_VECTOR_SOA_MAIN_HPP
30#define INCLUDED_MDDS_MULTI_TYPE_VECTOR_SOA_MAIN_HPP
32#include "../../global.hpp"
33#include "../types.hpp"
35#include "./block_util.hpp"
36#include "./iterator.hpp"
38#ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
42namespace mdds {
namespace mtv {
namespace soa {
71template<
typename Traits = mdds::mtv::default_traits>
75 using size_type = std::size_t;
78 using element_category_type = mdds::mtv::element_t;
79 using block_funcs =
typename Traits::block_funcs;
101 struct block_slot_type
109 block_slot_type(size_type _position, size_type _size) :
position(_position),
size(_size)
115 std::vector<size_type> positions;
116 std::vector<size_type> sizes;
117 std::vector<element_block_type*> element_blocks;
120 blocks_type(
const blocks_type& other);
121 blocks_type(blocks_type&& other);
125 positions.pop_back();
127 element_blocks.pop_back();
130 void push_back(size_type pos, size_type
size, element_block_type* data)
132 positions.push_back(pos);
133 sizes.push_back(
size);
134 element_blocks.push_back(data);
137 void push_back(
const block_slot_type& slot)
139 positions.push_back(slot.position);
140 sizes.push_back(slot.size);
141 element_blocks.push_back(slot.element_block);
144 void erase(size_type index);
145 void erase(size_type index, size_type
size);
147 void insert(size_type index, size_type pos, size_type
size, element_block_type* data);
148 void insert(size_type index,
const blocks_type& new_blocks);
156 void calc_block_position(size_type index);
158 size_type calc_next_block_position(size_type index);
160 void swap(size_type index1, size_type index2);
162 void swap(blocks_type& other);
164 void reserve(size_type n);
166 bool equals(
const blocks_type& other)
const;
170 void check_integrity()
const;
173 struct blocks_to_transfer
176 size_type insert_index = 0;
179 struct iterator_trait
182 using positions_type = std::vector<size_type>;
183 using sizes_type = std::vector<size_type>;
184 using element_blocks_type = std::vector<element_block_type*>;
186 using positions_iterator_type =
typename positions_type::iterator;
187 using sizes_iterator_type =
typename sizes_type::iterator;
188 using element_blocks_iterator_type =
typename element_blocks_type::iterator;
193 struct const_iterator_trait
196 using positions_type = std::vector<size_type>;
197 using sizes_type = std::vector<size_type>;
198 using element_blocks_type = std::vector<element_block_type*>;
200 using positions_iterator_type =
typename positions_type::const_iterator;
201 using sizes_iterator_type =
typename sizes_type::const_iterator;
202 using element_blocks_iterator_type =
typename element_blocks_type::const_iterator;
207 struct reverse_iterator_trait
210 using positions_type = std::vector<size_type>;
211 using sizes_type = std::vector<size_type>;
212 using element_blocks_type = std::vector<element_block_type*>;
214 using positions_iterator_type =
typename positions_type::reverse_iterator;
215 using sizes_iterator_type =
typename sizes_type::reverse_iterator;
216 using element_blocks_iterator_type =
typename element_blocks_type::reverse_iterator;
221 struct const_reverse_iterator_trait
224 using positions_type = std::vector<size_type>;
225 using sizes_type = std::vector<size_type>;
226 using element_blocks_type = std::vector<element_block_type*>;
228 using positions_iterator_type =
typename positions_type::const_reverse_iterator;
229 using sizes_iterator_type =
typename sizes_type::const_reverse_iterator;
230 using element_blocks_iterator_type =
typename element_blocks_type::const_reverse_iterator;
235 struct element_block_deleter
237 void operator()(
const element_block_type* p)
239 block_funcs::delete_block(p);
244 using iterator = detail::iterator_base<iterator_trait>;
245 using const_iterator = detail::const_iterator_base<const_iterator_trait, iterator>;
247 using reverse_iterator = detail::iterator_base<reverse_iterator_trait>;
248 using const_reverse_iterator = detail::const_iterator_base<const_reverse_iterator_trait, reverse_iterator>;
250 using position_type = std::pair<iterator, size_type>;
251 using const_position_type = std::pair<const_iterator, size_type>;
330 template<
typename _Blk>
331 static typename _Blk::value_type
get(
const const_position_type& pos);
827 void erase(size_type start_pos, size_type end_pos);
935 void get(size_type pos, T& value)
const;
949 T
get(size_type pos)
const;
1006 template<
typename T>
1124 template<
typename T>
1127#ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
1128 void dump_blocks(std::ostream& os)
const;
1130 void check_block_integrity()
const;
1134 void delete_element_block(size_type block_index);
1136 void delete_element_blocks(size_type start, size_type end);
1138 template<
typename T>
1139 void get_impl(size_type pos, T& value)
const;
1141 template<
typename T>
1142 bool set_cells_precheck(size_type row,
const T& it_begin,
const T& it_end, size_type& end_pos);
1144 template<
typename T>
1145 iterator set_impl(size_type pos, size_type block_index,
const T& value);
1147 template<
typename T>
1148 iterator release_impl(size_type pos, size_type block_index, T& value);
1151 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos, size_type block_index1,
1152 size_type block_index2, size_type dblock_index1, size_type dblock_index2);
1154 void swap_single_block(
1155 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos, size_type block_index,
1156 size_type other_block_index);
1158 void swap_single_to_multi_blocks(
1159 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos, size_type block_index,
1160 size_type dst_block_index1, size_type dst_block_index2);
1162 void swap_multi_to_multi_blocks(
1163 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos, size_type block_index1,
1164 size_type block_index2, size_type dblock_index1, size_type dblock_index2);
1166 template<
typename T>
1167 iterator insert_cells_impl(size_type row, size_type block_index,
const T& it_begin,
const T& it_end);
1169 void resize_impl(size_type new_size);
1176 size_type start_pos, size_type end_pos, size_type block_index1, size_type block_index2,
multi_type_vector& dest,
1177 size_type dest_pos);
1187 iterator set_empty_impl(size_type start_pos, size_type end_pos, size_type block_index1,
bool overwrite);
1189 iterator set_empty_in_single_block(size_type start_row, size_type end_row, size_type block_index,
bool overwrite);
1200 iterator set_empty_in_multi_blocks(
1201 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
bool overwrite);
1203 void erase_impl(size_type start_pos, size_type end_pos);
1204 void erase_in_single_block(size_type start_pos, size_type end_pos, size_type block_index);
1211 iterator insert_empty_impl(size_type pos, size_type block_index, size_type length);
1213 void insert_blocks_at(size_type
position, size_type insert_pos, blocks_type& new_blocks);
1215 void prepare_blocks_to_transfer(
1216 blocks_to_transfer& bucket, size_type block_index1, size_type offset1, size_type block_index2,
1219 iterator set_whole_block_empty(size_type block_index,
bool overwrite);
1221 template<
typename T>
1222 iterator push_back_impl(
const T& value);
1224 template<
typename T>
1226 size_type row, size_type end_row, size_type block_index1,
const T& it_begin,
const T& it_end);
1228 template<
typename T>
1229 iterator set_cells_to_single_block(
1230 size_type start_row, size_type end_row, size_type block_index,
const T& it_begin,
const T& it_end);
1232 template<
typename T>
1233 iterator set_cells_to_multi_blocks(
1234 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
const T& it_begin,
1237 template<
typename T>
1238 iterator set_cells_to_multi_blocks_block1_non_equal(
1239 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
const T& it_begin,
1242 template<
typename T>
1243 iterator set_cells_to_multi_blocks_block1_non_empty(
1244 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
const T& it_begin,
1247 template<
typename T>
1248 iterator set_cell_to_empty_block(size_type block_index, size_type pos_in_block,
const T& cell);
1250 template<
typename T>
1251 iterator set_cell_to_non_empty_block_of_size_one(size_type block_index,
const T& cell);
1262 size_type get_block_position(size_type row, size_type start_block_index = 0)
const;
1270 template<
typename T>
1271 void create_new_block_with_new_cell(size_type block_index,
const T& cell);
1273 template<
typename T>
1274 void append_cell_to_block(size_type block_index,
const T& cell);
1283 template<
typename T>
1284 bool append_to_prev_block(
1285 size_type block_index, element_category_type cat, size_type length,
const T& it_begin,
const T& it_end);
1287 template<
typename T>
1288 void insert_cells_to_middle(size_type row, size_type block_index,
const T& it_begin,
const T& it_end);
1290 template<
typename T>
1291 iterator set_cell_to_middle_of_block(size_type block_index, size_type pos_in_block,
const T& cell);
1298 template<
typename T>
1299 void set_cell_to_top_of_data_block(size_type block_index,
const T& cell);
1301 template<
typename T>
1302 void set_cell_to_bottom_of_data_block(size_type block_index,
const T& cell);
1305 size_type start_pos, size_type end_pos, size_type block_index1,
multi_type_vector& dest, size_type dest_pos);
1311 size_type start_pos, size_type end_pos, size_type block_index1,
multi_type_vector& dest, size_type dest_pos);
1321 size_type merge_with_adjacent_blocks(size_type block_index);
1330 bool merge_with_next_block(size_type block_index);
1345 size_type set_new_block_to_middle(
1346 size_type block_index, size_type offset, size_type new_block_size,
bool overwrite);
1357 bool is_previous_block_of_type(size_type block_index, element_category_type cat)
const;
1368 bool is_next_block_of_type(size_type block_index, element_category_type cat)
const;
1392 const element_block_type& src_data, size_type src_offset, size_type dst_index, size_type dst_offset,
1395 void exchange_elements(
1396 const element_block_type& src_blk, size_type src_offset, size_type dst_index1, size_type dst_offset1,
1397 size_type dst_index2, size_type dst_offset2, size_type len, blocks_type& new_blocks);
1399 bool append_empty(size_type len);
1401 inline iterator get_iterator(size_type block_index)
1403 auto iter_pos = m_block_store.positions.begin();
1404 std::advance(iter_pos, block_index);
1405 auto iter_size = m_block_store.sizes.begin();
1406 std::advance(iter_size, block_index);
1407 auto iter_elem = m_block_store.element_blocks.begin();
1408 std::advance(iter_elem, block_index);
1411 {iter_pos, iter_size, iter_elem},
1412 {m_block_store.positions.end(), m_block_store.sizes.end(), m_block_store.element_blocks.end()},
this,
1416 inline const_iterator get_const_iterator(size_type block_index)
const
1418 auto iter_pos = m_block_store.positions.cbegin();
1419 std::advance(iter_pos, block_index);
1420 auto iter_size = m_block_store.sizes.cbegin();
1421 std::advance(iter_size, block_index);
1422 auto iter_elem = m_block_store.element_blocks.cbegin();
1423 std::advance(iter_elem, block_index);
1425 return const_iterator(
1426 {iter_pos, iter_size, iter_elem},
1427 {m_block_store.positions.cend(), m_block_store.sizes.cend(), m_block_store.element_blocks.cend()},
this,
1432 using adjust_block_positions_func = detail::adjust_block_positions<blocks_type, Traits::loop_unrolling>;
1435 blocks_type m_block_store;
1436 size_type m_cur_size;
1438#ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
1439 mutable int m_trace_call_depth = 0;
1445#include "main_def.inl"
Definition: types.hpp:160
Definition: types.hpp:374
Definition: soa/iterator.hpp:310
Definition: soa/iterator.hpp:234
Definition: soa/main.hpp:73
size_type block_size() const
iterator set(size_type pos, const T &value)
iterator set(size_type pos, const T &it_begin, const T &it_end)
iterator set(const iterator &pos_hint, size_type pos, const T &value)
multi_type_vector(multi_type_vector &&other)
iterator release_range(size_type start_pos, size_type end_pos)
static const_position_type advance_position(const const_position_type &pos, int steps)
multi_type_vector(size_type init_size, const T &it_begin, const T &it_end)
static position_type advance_position(const position_type &pos, int steps)
const_position_type position(size_type pos) const
multi_type_vector(event_func &&hdl)
multi_type_vector(size_type init_size)
iterator insert_empty(size_type pos, size_type length)
iterator transfer(const iterator &pos_hint, size_type start_pos, size_type end_pos, multi_type_vector &dest, size_type dest_pos)
static const_position_type next_position(const const_position_type &pos)
position_type position(size_type pos)
iterator insert(const iterator &pos_hint, size_type pos, const T &it_begin, const T &it_end)
iterator push_back(const T &value)
void resize(size_type new_size)
static size_type logical_position(const const_position_type &pos)
iterator insert(size_type pos, const T &it_begin, const T &it_end)
T get(size_type pos) const
position_type position(const iterator &pos_hint, size_type pos)
multi_type_vector(const event_func &hdl)
void get(size_type pos, T &value) const
static _Blk::value_type get(const const_position_type &pos)
iterator insert_empty(const iterator &pos_hint, size_type pos, size_type length)
iterator release(const iterator &pos_hint, size_type pos, T &value)
typename Traits::event_func event_func
Definition: soa/main.hpp:98
iterator set_empty(const iterator &pos_hint, size_type start_pos, size_type end_pos)
iterator push_back_empty()
iterator transfer(size_type start_pos, size_type end_pos, multi_type_vector &dest, size_type dest_pos)
multi_type_vector(const multi_type_vector &other)
iterator release_range(const iterator &pos_hint, size_type start_pos, size_type end_pos)
void erase(size_type start_pos, size_type end_pos)
multi_type_vector(size_type init_size, const T &value)
const_position_type position(const const_iterator &pos_hint, size_type pos) const
void swap(size_type start_pos, size_type end_pos, multi_type_vector &other, size_type other_pos)
iterator set(const iterator &pos_hint, size_type pos, const T &it_begin, const T &it_end)
iterator release(size_type pos, T &value)
static position_type next_position(const position_type &pos)
mtv::element_t get_type(size_type pos) const
static mtv::element_t get_element_type(const T &elem)
iterator set_empty(size_type start_pos, size_type end_pos)
void swap(multi_type_vector &other)
bool is_empty(size_type pos) const
Definition: iterator_node.hpp:66
Definition: iterator_node.hpp:42
Definition: iterator_node.hpp:109
Definition: iterator_node.hpp:98