28 #ifndef INCLUDED_MDDS_MULTI_TYPE_VECTOR_HPP
29 #define INCLUDED_MDDS_MULTI_TYPE_VECTOR_HPP
32 #include "multi_type_vector_types.hpp"
33 #include "multi_type_vector_itr.hpp"
40 #if defined(MDDS_UNIT_TEST) || defined (MDDS_MULTI_TYPE_VECTOR_DEBUG)
49 namespace detail {
namespace mtv {
65 T advance_position(
const T& pos,
int steps);
94 template<
typename _ElemBlockFunc,
typename _EventFunc = detail::mtv::event_func>
98 typedef size_t size_type;
101 typedef mdds::mtv::element_t element_category_type;
102 typedef _ElemBlockFunc element_block_func;
127 size_type m_position;
132 block(size_type _position, size_type _size);
134 block(
const block& other);
135 block(block&& other);
137 void swap(block& other);
138 void clone_to(block& other)
const;
140 block& operator=(block);
143 struct element_block_deleter
145 void operator() (
const element_block_type* p)
147 element_block_func::delete_block(p);
151 typedef std::vector<block> blocks_type;
153 struct blocks_to_transfer
156 size_type insert_index;
158 blocks_to_transfer();
161 struct iterator_trait
164 typedef blocks_type blocks;
165 typedef typename blocks_type::iterator base_iterator;
168 struct reverse_iterator_trait
171 typedef blocks_type blocks;
172 typedef typename blocks_type::reverse_iterator base_iterator;
175 struct const_iterator_trait
178 typedef blocks_type blocks;
179 typedef typename blocks_type::const_iterator base_iterator;
182 struct const_reverse_iterator_trait
185 typedef blocks_type blocks;
186 typedef typename blocks_type::const_reverse_iterator base_iterator;
189 typedef detail::mtv::iterator_value_node<size_type, element_block_type> itr_node;
190 typedef detail::mtv::private_data_forward_update<itr_node> itr_forward_update;
191 typedef detail::mtv::private_data_no_update<itr_node> itr_no_update;
195 typedef detail::mtv::iterator_base<iterator_trait, itr_forward_update> iterator;
196 typedef detail::mtv::iterator_base<reverse_iterator_trait, itr_no_update> reverse_iterator;
198 typedef detail::mtv::const_iterator_base<const_iterator_trait, itr_forward_update, iterator> const_iterator;
199 typedef detail::mtv::const_iterator_base<const_reverse_iterator_trait, itr_no_update, reverse_iterator> const_reverse_iterator;
218 typedef std::pair<iterator, size_type> position_type;
219 typedef std::pair<const_iterator, size_type> const_position_type;
281 template<
typename _Blk>
282 static typename _Blk::value_type
get(
const const_position_type& pos);
344 template<
typename _T>
360 template<
typename _T>
391 template<
typename _T>
426 template<
typename _T>
450 template<
typename _T>
451 iterator set(size_type pos,
const _T& it_begin,
const _T& it_end);
490 template<
typename _T>
502 template<
typename _T>
535 template<
typename _T>
575 template<
typename _T>
588 template<
typename _T>
589 void get(size_type pos, _T& value)
const;
602 template<
typename _T>
603 _T
get(size_type pos)
const;
619 template<
typename _T>
638 template<
typename _T>
657 template<
typename _T>
923 void erase(size_type start_pos, size_type end_pos);
1063 template<
typename _T>
1066 #ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
1067 void dump_blocks(std::ostream& os)
const;
1069 bool check_block_integrity()
const;
1074 void adjust_block_positions(int64_t start_block_index, int64_t delta);
1082 void delete_element_block(block& blk);
1091 void delete_element_blocks(
typename blocks_type::iterator it,
typename blocks_type::iterator it_end);
1093 template<
typename _T>
1094 iterator set_impl(size_type pos, size_type block_index,
const _T& value);
1096 template<
typename _T>
1097 iterator release_impl(size_type pos, size_type block_index, _T& value);
1099 template<
typename _T>
1100 iterator push_back_impl(
const _T& value);
1110 size_type get_block_position(size_type row, size_type start_block_index=0)
const;
1116 size_type get_block_position(
const const_iterator& pos_hint, size_type row)
const;
1118 template<
typename _T>
1121 template<
typename _T>
1122 iterator set_cell_to_middle_of_block(
1123 size_type block_index, size_type pos_in_block,
const _T& cell);
1125 template<
typename _T>
1126 void append_cell_to_block(size_type block_index,
const _T& cell);
1128 template<
typename _T>
1129 iterator set_cell_to_empty_block(size_type block_index, size_type pos_in_block,
const _T& cell);
1131 template<
typename _T>
1132 iterator set_cell_to_block_of_size_one(
1133 size_type block_index,
const _T& cell);
1135 template<
typename _T>
1136 void set_cell_to_top_of_data_block(
1137 size_type block_index,
const _T& cell);
1139 template<
typename _T>
1140 void set_cell_to_bottom_of_data_block(
1141 size_type block_index,
const _T& cell);
1144 size_type start_pos, size_type end_pos, size_type block_index1,
1151 size_type start_pos, size_type end_pos, size_type block_index1,
1159 size_type start_pos, size_type end_pos, size_type block_index1, size_type block_index2,
1173 size_type start_pos, size_type end_pos, size_type block_index1,
bool overwrite);
1176 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos,
1177 size_type block_index1, size_type block_index2, size_type dblock_index1, size_type dblock_index2);
1179 void swap_single_block(
1180 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos,
1181 size_type block_index, size_type other_block_index);
1183 void swap_single_to_multi_blocks(
1184 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos,
1185 size_type block_index, size_type dst_block_index1, size_type dst_block_index2);
1187 void swap_multi_to_multi_blocks(
1188 multi_type_vector& other, size_type start_pos, size_type end_pos, size_type other_pos,
1189 size_type block_index1, size_type block_index2, size_type dblock_index1, size_type dblock_index2);
1191 void insert_blocks_at(size_type
position, size_type insert_pos, blocks_type& new_blocks);
1193 void prepare_blocks_to_transfer(blocks_to_transfer& bucket, size_type block_index1, size_type offset1, size_type block_index2, size_type offset2);
1195 iterator set_whole_block_empty(size_type block_index,
bool overwrite);
1197 iterator set_empty_in_single_block(
1198 size_type start_row, size_type end_row, size_type block_index,
bool overwrite);
1209 iterator set_empty_in_multi_blocks(
1210 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
1213 void erase_impl(size_type start_pos, size_type end_pos);
1214 void erase_in_single_block(size_type start_pos, size_type end_pos, size_type block_pos);
1221 iterator insert_empty_impl(size_type pos, size_type block_index, size_type length);
1223 template<
typename _T>
1224 bool set_cells_precheck(
1225 size_type row,
const _T& it_begin,
const _T& it_end, size_type& end_pos);
1227 template<
typename _T>
1229 size_type row, size_type end_row, size_type block_index1,
const _T& it_begin,
const _T& it_end);
1231 template<
typename _T>
1232 iterator insert_cells_impl(size_type row, size_type block_index,
const _T& it_begin,
const _T& it_end);
1234 template<
typename _T>
1235 iterator set_cells_to_single_block(
1236 size_type start_row, size_type end_row, size_type block_index,
1237 const _T& it_begin,
const _T& it_end);
1239 template<
typename _T>
1240 iterator set_cells_to_multi_blocks(
1241 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
1242 const _T& it_begin,
const _T& it_end);
1244 template<
typename _T>
1245 iterator set_cells_to_multi_blocks_block1_non_equal(
1246 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
1247 const _T& it_begin,
const _T& it_end);
1249 template<
typename _T>
1250 iterator set_cells_to_multi_blocks_block1_non_empty(
1251 size_type start_row, size_type end_row, size_type block_index1, size_type block_index2,
1252 const _T& it_begin,
const _T& it_end);
1262 size_type merge_with_adjacent_blocks(size_type block_index);
1271 bool merge_with_next_block(size_type block_index);
1273 template<
typename _T>
1274 bool append_to_prev_block(
1275 size_type block_index, element_category_type cat, size_type length,
1276 const _T& it_begin,
const _T& it_end);
1278 template<
typename _T>
1279 void insert_cells_to_middle(
1280 size_type row, size_type block_index,
const _T& it_begin,
const _T& it_end);
1295 block& set_new_block_to_middle(
1296 size_type block_index, size_type offset, size_type new_block_size,
bool overwrite);
1298 block* get_previous_block_of_type(size_type block_index, element_category_type cat);
1307 block* get_next_block_of_type(size_type block_index, element_category_type cat);
1327 const element_block_type& src_data, size_type src_offset, size_type dst_index, size_type dst_offset, size_type len);
1329 void exchange_elements(
1331 size_type dst_index1, size_type dst_offset1, size_type dst_index2, size_type dst_offset2,
1332 size_type len, blocks_type& new_blocks);
1334 bool append_empty(size_type len);
1336 inline iterator get_iterator(size_type block_index)
1338 typename blocks_type::iterator block_pos = m_blocks.begin();
1339 std::advance(block_pos, block_index);
1340 return iterator(block_pos, m_blocks.end(), block_index);
1343 inline const_iterator get_const_iterator(size_type block_index)
const
1345 typename blocks_type::const_iterator block_pos = m_blocks.begin();
1346 std::advance(block_pos, block_index);
1347 return const_iterator(block_pos, m_blocks.end(), block_index);
1352 blocks_type m_blocks;
1353 size_type m_cur_size;
1358 #include "multi_type_vector_def.inl"