29 #ifndef INCLUDED_MDDS_MULTI_TYPE_VECTOR_TYPES_2_HPP
30 #define INCLUDED_MDDS_MULTI_TYPE_VECTOR_TYPES_2_HPP
32 #include "../global.hpp"
39 #ifdef MDDS_MULTI_TYPE_VECTOR_USE_DEQUE
45 #if defined(MDDS_UNIT_TEST) || defined (MDDS_MULTI_TYPE_VECTOR_DEBUG)
53 namespace mdds {
namespace mtv {
55 using element_t = int;
57 constexpr element_t element_type_empty = -1;
59 constexpr element_t element_type_boolean = 0;
60 constexpr element_t element_type_int8 = 1;
61 constexpr element_t element_type_uint8 = 2;
62 constexpr element_t element_type_int16 = 3;
63 constexpr element_t element_type_uint16 = 4;
64 constexpr element_t element_type_int32 = 5;
65 constexpr element_t element_type_uint32 = 6;
66 constexpr element_t element_type_int64 = 7;
67 constexpr element_t element_type_uint64 = 8;
68 constexpr element_t element_type_float = 9;
69 constexpr element_t element_type_double = 10;
70 constexpr element_t element_type_string = 11;
72 constexpr element_t element_type_user_start = 50;
80 enum class lu_factor_t : int
88 sse2_x64_lu4 = 1 << 8 | 4,
89 sse2_x64_lu8 = 1 << 8 | 8,
90 sse2_x64_lu16 = 1 << 8 | 16,
92 avx2_x64_lu4 = 2 << 8 | 4,
93 avx2_x64_lu8 = 2 << 8 | 8,
115 enum class trace_method_t : int
119 accessor_with_pos_hint = 1 << 8 | 1,
121 mutator_with_pos_hint = 1 << 8 | 2,
131 trace_method_t type = trace_method_t::unspecified;
180 template<
typename _Self, element_t _TypeId,
typename _Data>
183 #ifdef MDDS_UNIT_TEST
184 struct print_block_array
186 void operator() (
const _Data& val)
const
188 std::cout << val <<
" ";
194 #ifdef MDDS_MULTI_TYPE_VECTOR_USE_DEQUE
195 typedef std::deque<_Data> store_type;
197 typedef std::vector<_Data> store_type;
205 template<
typename _Iter>
209 static const element_t block_type = _TypeId;
211 typedef typename store_type::iterator iterator;
212 typedef typename store_type::reverse_iterator reverse_iterator;
213 typedef typename store_type::const_iterator const_iterator;
214 typedef typename store_type::const_reverse_iterator const_reverse_iterator;
215 typedef _Data value_type;
217 bool operator== (
const _Self& r)
const
219 return m_array == r.m_array;
222 bool operator!= (
const _Self& r)
const
224 return !operator==(r);
227 static const value_type& at(
const base_element_block& block,
typename store_type::size_type pos)
229 return get(block).m_array.at(pos);
234 return get(block).m_array.at(pos);
239 return get(block).m_array.data();
244 return get(block).m_array.size();
249 return get(block).m_array.begin();
254 return get(block).m_array.end();
259 return get(block).m_array.begin();
264 return get(block).m_array.end();
269 return get(block).m_array.begin();
274 return get(block).m_array.end();
279 return get(block).m_array.rbegin();
284 return get(block).m_array.rend();
289 return get(block).m_array.rbegin();
294 return get(block).m_array.rend();
299 return get(block).m_array.rbegin();
304 return get(block).m_array.rend();
309 #ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
312 std::ostringstream os;
313 os <<
"incorrect block type: expected block type=" << _TypeId <<
", passed block type=" <<
get_block_type(block);
317 return static_cast<_Self&
>(block);
322 #ifdef MDDS_MULTI_TYPE_VECTOR_DEBUG
325 std::ostringstream os;
326 os <<
"incorrect block type: expected block type=" << _TypeId <<
", passed block type=" <<
get_block_type(block);
330 return static_cast<const _Self&
>(block);
335 get(blk).m_array[pos] = val;
340 val = get(blk).m_array[pos];
345 return get(blk).m_array[pos];
350 get(blk).m_array.push_back(val);
355 store_type& blk2 = get(blk).m_array;
356 blk2.insert(blk2.begin(), val);
359 static _Self* create_block(
size_t init_size)
361 return new _Self(init_size);
366 delete static_cast<const _Self*
>(p);
371 store_type& st = get(blk).m_array;
376 if (new_size < (st.capacity() / 2))
380 #ifdef MDDS_UNIT_TEST
383 const store_type& blk2 = get(blk).m_array;
384 std::for_each(blk2.begin(), blk2.end(), print_block_array());
385 std::cout << std::endl;
393 store_type& blk2 = get(blk).m_array;
394 blk2.erase(blk2.begin()+pos);
399 store_type& blk2 = get(blk).m_array;
400 blk2.erase(blk2.begin()+pos, blk2.begin()+pos+size);
405 store_type& d = get(dest).m_array;
406 const store_type& s = get(src).m_array;
407 d.insert(d.end(), s.begin(), s.end());
410 static void append_values_from_block(
413 store_type& d = get(dest).m_array;
414 const store_type& s = get(src).m_array;
415 std::pair<const_iterator,const_iterator> its = get_iterator_pair(s, begin_pos, len);
416 #ifndef MDDS_MULTI_TYPE_VECTOR_USE_DEQUE
417 d.reserve(d.size() + len);
419 d.insert(d.end(), its.first, its.second);
422 static void assign_values_from_block(
425 store_type& d = get(dest).m_array;
426 const store_type& s = get(src).m_array;
427 std::pair<const_iterator,const_iterator> its = get_iterator_pair(s, begin_pos, len);
428 d.assign(its.first, its.second);
431 static void prepend_values_from_block(
434 store_type& d = get(dest).m_array;
435 const store_type& s = get(src).m_array;
436 std::pair<const_iterator,const_iterator> its = get_iterator_pair(s, begin_pos, len);
437 #ifndef MDDS_MULTI_TYPE_VECTOR_USE_DEQUE
438 d.reserve(d.size() + len);
440 d.insert(d.begin(), its.first, its.second);
443 static void swap_values(
446 store_type& st1 = get(blk1).m_array;
447 store_type& st2 = get(blk2).m_array;
448 assert(pos1 + len <= st1.size());
449 assert(pos2 + len <= st2.size());
451 typename store_type::iterator it1 = st1.begin(), it2 = st2.begin();
452 std::advance(it1, pos1);
453 std::advance(it2, pos2);
454 for (
size_t i = 0; i < len; ++i, ++it1, ++it2)
456 #ifdef MDDS_MULTI_TYPE_VECTOR_USE_DEQUE
457 std::swap(*it1, *it2);
459 value_type v1 = *it1, v2 = *it2;
466 template<
typename _Iter>
467 static void set_values(
470 store_type& d = get(block).m_array;
471 typename store_type::iterator it_dest = d.begin();
472 std::advance(it_dest, pos);
473 for (_Iter it = it_begin; it != it_end; ++it, ++it_dest)
477 template<
typename _Iter>
478 static void append_values(
base_element_block& block,
const _Iter& it_begin,
const _Iter& it_end)
480 store_type& d = get(block).m_array;
481 typename store_type::iterator it = d.end();
482 d.insert(it, it_begin, it_end);
485 template<
typename _Iter>
486 static void prepend_values(
base_element_block& block,
const _Iter& it_begin,
const _Iter& it_end)
488 store_type& d = get(block).m_array;
489 d.insert(d.begin(), it_begin, it_end);
492 template<
typename _Iter>
493 static void assign_values(
base_element_block& dest,
const _Iter& it_begin,
const _Iter& it_end)
495 store_type& d = get(dest).m_array;
496 d.assign(it_begin, it_end);
499 template<
typename _Iter>
500 static void insert_values(
503 store_type& blk = get(block).m_array;
504 blk.insert(blk.begin()+pos, it_begin, it_end);
509 #ifdef MDDS_MULTI_TYPE_VECTOR_USE_DEQUE
512 const store_type& blk = get(block).m_array;
513 return blk.capacity();
519 #ifndef MDDS_MULTI_TYPE_VECTOR_USE_DEQUE
520 get(block).m_array.shrink_to_fit();
525 static std::pair<const_iterator,const_iterator>
526 get_iterator_pair(
const store_type& array,
size_t begin_pos,
size_t len)
528 assert(begin_pos + len <= array.size());
529 const_iterator it = array.begin();
530 std::advance(it, begin_pos);
531 const_iterator it_end = it;
532 std::advance(it_end, len);
533 return std::pair<const_iterator,const_iterator>(it, it_end);
537 template<
typename _Self, element_t _TypeId,
typename _Data>
546 template<
typename _Iter>
550 using base_type::get;
555 return new _Self(get(blk));
559 template<
typename _Self, element_t _TypeId,
typename _Data>
568 template<
typename _Iter>
597 template<element_t _TypeId,
typename _Data>
607 template<
typename _Iter>
610 static self_type* create_block_with_value(
size_t init_size,
const _Data& val)
615 template<
typename _Iter>
616 static self_type* create_block_with_values(
const _Iter& it_begin,
const _Iter& it_end)
631 template<element_t _TypeId,
typename _Data>
637 using base_type::get;
638 using base_type::set_value;
639 using base_type::m_array;
645 #ifndef MDDS_MULTI_TYPE_VECTOR_USE_DEQUE
646 m_array.reserve(r.m_array.size());
648 typename managed_element_block::store_type::const_iterator it = r.m_array.begin(), it_end = r.m_array.end();
649 for (; it != it_end; ++it)
650 m_array.push_back(
new _Data(**it));
653 template<
typename _Iter>
658 std::for_each(m_array.begin(), m_array.end(), std::default_delete<_Data>());
661 static self_type* create_block_with_value(
size_t init_size, _Data* val)
665 throw general_error(
"You can't create a managed block with initial value.");
667 std::unique_ptr<self_type> blk = std::make_unique<self_type>(init_size);
669 set_value(*blk, 0, val);
671 return blk.release();
674 template<
typename _Iter>
675 static self_type* create_block_with_values(
const _Iter& it_begin,
const _Iter& it_end)
683 typename managed_element_block::store_type::iterator it = blk.m_array.begin() + pos;
684 typename managed_element_block::store_type::iterator it_end = it + len;
685 std::for_each(it, it_end, std::default_delete<_Data>());
689 template<element_t _TypeId,
typename _Data>
695 using base_type::get;
696 using base_type::m_array;
697 using base_type::set_value;
702 template<
typename _Iter>
707 std::for_each(m_array.begin(), m_array.end(), std::default_delete<_Data>());
710 static self_type* create_block_with_value(
size_t init_size, _Data* val)
714 throw general_error(
"You can't create a managed block with initial value.");
716 std::unique_ptr<self_type> blk = std::make_unique<self_type>(init_size);
718 set_value(*blk, 0, val);
720 return blk.release();
723 template<
typename _Iter>
724 static self_type* create_block_with_values(
const _Iter& it_begin,
const _Iter& it_end)
732 typename noncopyable_managed_element_block::store_type::iterator it = blk.m_array.begin() + pos;
733 typename noncopyable_managed_element_block::store_type::iterator it_end = it + len;
734 std::for_each(it, it_end, std::default_delete<_Data>());
Definition: global.hpp:82
Definition: types.hpp:173
friend element_t get_block_type(const base_element_block &)
Definition: types.hpp:588
Definition: types.hpp:539
Definition: types.hpp:160
Definition: types.hpp:182
Definition: types.hpp:561
Definition: types.hpp:599
Definition: types.hpp:633
Definition: types.hpp:691
Definition: types.hpp:130
std::string function_args
Definition: types.hpp:147
const char * function_name
Definition: types.hpp:141
int line_number
Definition: types.hpp:153
const void * instance
Definition: types.hpp:138
const char * filepath
Definition: types.hpp:150