45 #include <range/v3/view/const.hpp> 46 #include <range/v3/view/join.hpp> 47 #include <range/v3/view/repeat_n.hpp> 48 #include <range/v3/view/slice.hpp> 59 #if SEQAN3_WITH_CEREAL 60 #include <cereal/types/vector.hpp> 110 template <
typename inner_type,
111 typename data_delimiters_type = std::vector<typename inner_type::size_type>>
113 requires reservable_container_concept<std::remove_reference_t<inner_type>> &&
114 reservable_container_concept<std::remove_reference_t<data_delimiters_type>> &&
115 std::is_same_v<size_type_t<inner_type>, value_type_t<data_delimiters_type>>
122 std::decay_t<inner_type> data_values;
124 data_delimiters_type data_delimiters{0};
137 using reference = decltype(data_values | ranges::view::slice(0, 1));
141 using const_reference = decltype(std::as_const(data_values) | ranges::view::slice(0, 1) | ranges::view::const_);
145 using iterator = detail::random_access_iterator<concatenated_sequences>;
149 using const_iterator = detail::random_access_iterator<concatenated_sequences const>;
162 using allocator_type = void;
172 template <
typename t>
173 requires (dimension_v<t> == dimension_v<value_type> + 1) &&
174 std::is_same_v<remove_cvref_t<innermost_value_type_t<value_type>>,
176 static constexpr
bool is_compatible_this_aux =
true;
182 template <
typename t>
185 std::is_same_v<remove_cvref_t<t>,
iterator> ||
191 template <
typename t>
193 std::is_same_v<remove_cvref_t<t>,
value_type> ||
194 std::is_same_v<remove_cvref_t<t>,
reference> ||
226 template <std::ranges::InputRange rng_of_rng_type>
229 requires is_compatible_this<rng_of_rng_type>
235 for (
auto && val : rng_of_rng)
237 data_values.insert(data_values.end(), val.begin(), val.end());
238 data_delimiters.push_back(data_delimiters.back() + val.size());
255 template <std::ranges::ForwardRange rng_type>
258 requires is_compatible_value<rng_type>
265 insert(
cend(), count, std::forward<rng_type>(value));
283 template <std::ForwardIterator begin_iterator_type, std::SizedSentinel<begin_iterator_type> end_iterator_type>
286 requires is_compatible_this<begin_iterator_type>
304 template <std::ranges::ForwardRange rng_type = value_type>
307 requires is_compatible_value<rng_type>
310 assign(std::begin(ilist), std::end(ilist));
325 template <std::ranges::ForwardRange rng_type>
328 requires is_compatible_value<rng_type>
331 assign(std::begin(ilist), std::end(ilist));
347 template <std::ranges::InputRange rng_of_rng_type>
348 void assign(rng_of_rng_type && rng_of_rng)
350 requires is_compatible_this<rng_of_rng_type>
370 template <
typename rng_type>
394 template <std::ForwardIterator begin_iterator_type,
typename end_iterator_type>
395 void assign(begin_iterator_type begin_it, end_iterator_type end_it)
397 requires is_compatible_this<begin_iterator_type> &&
417 template <std::ranges::ForwardRange rng_type = value_type>
418 void assign(std::initializer_list<rng_type> ilist)
420 requires is_compatible_value<rng_type>
423 assign(std::begin(ilist), std::end(ilist));
450 const_iterator
begin() const noexcept
452 return const_iterator{*
this};
458 return const_iterator{*
this};
480 const_iterator
end() const noexcept
482 return const_iterator{*
this,
size()};
486 const_iterator
cend() const noexcept
488 return const_iterator{*
this,
size()};
512 throw std::out_of_range{
"Trying to access element behind the last in concatenated_sequences."};
521 throw std::out_of_range{
"Trying to access element behind the last in concatenated_sequences."};
542 return data_values | ranges::view::slice(data_delimiters[i], data_delimiters[i+1]);
549 return data_values | ranges::view::slice(data_delimiters[i], data_delimiters[i+1])
550 | ranges::view::const_;
593 return (*
this)[
size()-1];
600 return (*
this)[
size()-1];
619 return data_values | ranges::view::slice(static_cast<size_type>(0),
concat_size());
625 return data_values | ranges::view::slice(static_cast<size_type>(0),
concat_size()) | ranges::view::const_;
633 std::pair<decltype(data_values) &, decltype(data_delimiters) &>
data()
635 return {data_values, data_delimiters};
639 std::pair<decltype(data_values) const &, decltype(data_delimiters) const &>
data()
const 641 return {std::as_const(data_values), std::as_const(data_delimiters)};
677 return data_delimiters.size() - 1;
696 return data_delimiters.max_size() - 1;
716 return data_delimiters.capacity();
743 data_delimiters.reserve(new_cap + 1);
767 data_values.shrink_to_fit();
768 data_delimiters.shrink_to_fit();
788 return data_values.size();
804 return data_values.capacity();
827 data_values.reserve(new_cap);
849 data_delimiters.clear();
850 data_delimiters.push_back(0);
877 template <std::ranges::ForwardRange rng_type>
879 requires is_compatible_value<rng_type>
881 return insert(pos, 1, std::forward<rng_type>(value));
909 template <std::ranges::ForwardRange rng_type>
911 requires is_compatible_value<rng_type>
914 auto const pos_as_num = std::distance(
cbegin(), pos);
917 return begin() + pos_as_num;
932 value_len = std::distance(seqan3::begin(value), seqan3::end(value));
934 data_values.reserve(data_values.size() + count * value_len);
938 data_values.insert(data_values.begin() + data_delimiters[pos_as_num],
939 seqan3::begin(placeholder),
940 seqan3::end(placeholder));
943 size_t i = data_delimiters[pos_as_num];
944 for (
size_t j = 0; j < count; ++j)
945 for (
auto && v : value)
946 data_values[i++] = v;
948 data_delimiters.reserve(data_values.size() + count);
949 data_delimiters.insert(data_delimiters.begin() + pos_as_num,
951 *(data_delimiters.begin() + pos_as_num));
955 data_delimiters[pos_as_num + i + 1] += value_len * (i + 1);
959 std::for_each(data_delimiters.begin() + pos_as_num + count + 1,
960 data_delimiters.end(),
961 [full_len = value_len * count] (
auto & d) { d += full_len; });
963 return begin() + pos_as_num;
989 template <std::ForwardIterator begin_iterator_type,
typename end_iterator_type>
990 iterator insert(const_iterator pos, begin_iterator_type first, end_iterator_type last)
992 requires is_compatible_this<begin_iterator_type> &&
996 auto const pos_as_num = std::distance(
cbegin(), pos);
998 if (last - first == 0)
999 return begin() + pos_as_num;
1003 data_delimiters.reserve(data_values.size() + ilist.size());
1004 data_delimiters.insert(data_delimiters.begin() + pos_as_num,
1006 *(data_delimiters.begin() + pos_as_num));
1011 for (
size_type i = 0; i < ilist.size(); ++i, ++first)
1017 full_len += std::distance(seqan3::begin(*first), seqan3::end(*first));
1019 data_delimiters[pos_as_num + 1 + i] += full_len;
1026 data_values.insert(data_values.begin() + data_delimiters[pos_as_num],
1027 seqan3::begin(placeholder),
1028 seqan3::end(placeholder));
1031 size_t i = data_delimiters[pos_as_num];
1032 for (
auto && v0 : ilist)
1033 for (
auto && v1 : v0)
1034 data_values[i++] = v1;
1039 std::for_each(data_delimiters.begin() + pos_as_num + ilist.size() + 1,
1040 data_delimiters.end(),
1041 [full_len] (
auto & d) { d += full_len; });
1043 return begin() + pos_as_num;
1065 template <std::ranges::ForwardRange rng_type>
1067 requires is_compatible_value<rng_type>
1069 return insert(pos, ilist.begin(), ilist.end());
1092 auto const dist = std::distance(
cbegin(), last);
1094 if (last - first == 0)
1095 return begin() + dist;
1097 auto const distf = std::distance(
cbegin(), first);
1101 for (; first != last; ++first)
1104 data_values.erase(data_values.begin() + data_delimiters[distf],
1105 data_values.begin() + data_delimiters[dist]);
1107 data_delimiters.erase(data_delimiters.begin() + distf + 1,
1108 data_delimiters.begin() + dist + 1);
1112 std::for_each(data_delimiters.begin() + distf + 1,
1113 data_delimiters.end(),
1114 [sum_size] (
auto & d) { d -= sum_size; });
1115 return begin() + dist;
1138 return erase(pos, pos + 1);
1157 template <std::ranges::ForwardRange rng_type>
1159 requires is_compatible_value<rng_type>
1161 data_values.insert(data_values.end(), seqan3::begin(value), seqan3::end(value));
1162 data_delimiters.push_back(data_delimiters.back() +
seqan3::size(value));
1184 auto back_length = data_delimiters[
size()] - data_delimiters[
size() - 1];
1185 data_values.resize(data_values.size() - back_length);
1186 data_delimiters.pop_back();
1218 data_delimiters.resize(count + 1, data_delimiters.back());
1219 data_values.resize(data_delimiters.back());
1227 template <std::ranges::ForwardRange rng_type>
1229 requires is_compatible_value<rng_type>
1236 else if (count >
size())
1253 std::swap(data_values, rhs.data_values);
1254 std::swap(data_delimiters, rhs.data_delimiters);
1260 std::swap(data_values, rhs.data_values);
1261 std::swap(data_delimiters, rhs.data_delimiters);
1305 template <cereal_archive_concept archive_t>
1306 void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
1308 archive(data_values, data_delimiters);
concatenated_sequences()=default
Default constructors.
constexpr concatenated_sequences & operator=(concatenated_sequences const &)=default
Default constructors.
detail::random_access_iterator< concatenated_sequences > iterator
The iterator type of this container (a random access iterator).
Definition: concatenated_sequences.hpp:145
void concat_reserve(size_type const new_cap)
Increase the concat_capacity() to a value that's greater or equal to new_cap.
Definition: concatenated_sequences.hpp:825
const_reference at(size_type const i) const
Return the i-th element as a view.
Definition: concatenated_sequences.hpp:517
size_type max_size() const noexcept
Returns the maximum number of elements the container is able to hold due to system or library impleme...
Definition: concatenated_sequences.hpp:694
iterator erase(const_iterator pos)
Removes specified elements from the container.
Definition: concatenated_sequences.hpp:1136
iterator end() noexcept
Returns an iterator to the element following the last element of the container.
Definition: concatenated_sequences.hpp:474
void reserve(size_type const new_cap)
Increase the capacity to a value that's greater or equal to new_cap.
Definition: concatenated_sequences.hpp:741
Provides C++20 additions to the <iterator> header.
constexpr void swap(concatenated_sequences &rhs) noexcept
Swap contents with another instance.
Definition: concatenated_sequences.hpp:1251
Contains various shortcuts for common std::ranges functions.
iterator erase(const_iterator first, const_iterator last)
Removes specified elements from the container.
Definition: concatenated_sequences.hpp:1090
concatenated_sequences(begin_iterator_type begin_it, end_iterator_type end_it)
Construct/assign from pair of iterators.
Definition: concatenated_sequences.hpp:284
std::decay_t< inner_type > value_type
== inner_type.
Definition: concatenated_sequences.hpp:133
static constexpr bool is_compatible_value
Whether a type satisfies seqan3::compatible_concept with this class's value_type or reference type...
Definition: concatenated_sequences.hpp:192
void pop_back()
Removes the last element of the container.
Definition: concatenated_sequences.hpp:1181
Provides the seqan3::detail::random_access_iterator class.
void assign(rng_of_rng_type &&rng_of_rng)
Construct/assign from a different range.
Definition: concatenated_sequences.hpp:348
const_iterator cend() const noexcept
Returns an iterator to the element following the last element of the container.
Definition: concatenated_sequences.hpp:486
::ranges::size size
Alias for ranges::size. Obtains the size of a range whose size can be calculated in constant time...
Definition: ranges:195
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
Two types are "compatible" if their seqan3::dimension_v and their seqan3::innermost_value_type_t are ...
std::pair< decltype(data_values) const &, decltype(data_delimiters) const & > data() const
Provides direct, unsafe access to underlying data structures.
Definition: concatenated_sequences.hpp:639
decltype(data_values|ranges::view::slice(0, 1)) reference
A proxy of type ranges::view::slice that represents the range on the concatenated vector...
Definition: concatenated_sequences.hpp:137
size_type concat_size() const noexcept
Returns the cumulative size of all elements in the container.
Definition: concatenated_sequences.hpp:786
constexpr void swap(concatenated_sequences &&rhs) noexcept
Swap contents with another instance.
Definition: concatenated_sequences.hpp:1258
const_reference concat() const
Return the concatenation of all members.
Definition: concatenated_sequences.hpp:623
difference_type_t< data_delimiters_type > difference_type
A signed integer type (usually std::ptrdiff_t)
Definition: concatenated_sequences.hpp:153
void clear() noexcept
Removes all elements from the container.
Definition: concatenated_sequences.hpp:846
Provides seqan3::view::common.
size_type_t< data_delimiters_type > size_type
An unsigned integer type (usually std::size_t)
Definition: concatenated_sequences.hpp:157
Container that stores sequences concatenated internally.
Definition: concatenated_sequences.hpp:117
::ranges::make_iterator_range make_iterator_range
Alias for ranges::make_iterator_range. Makes the iterator adaptor.
Definition: ranges:240
bool empty() const noexcept
Checks whether the container is empty.
Definition: concatenated_sequences.hpp:659
size_type concat_capacity() const noexcept
Returns the concatenated size the container has currently allocated space for.
Definition: concatenated_sequences.hpp:802
concatenated_sequences(std::initializer_list< rng_type > ilist)
Construct/assign from std::initializer_list.
Definition: concatenated_sequences.hpp:305
const_reference operator[](size_type const i) const
Return the i-th element as a view.
Definition: concatenated_sequences.hpp:546
size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition: concatenated_sequences.hpp:675
constexpr auto common
A range adaptor that makes any range satisfy std::ranges::CommonRange (at the expense of some perform...
Definition: common.hpp:99
std::pair< decltype(data_values) &, decltype(data_delimiters) & > data()
Provides direct, unsafe access to underlying data structures.
Definition: concatenated_sequences.hpp:633
iterator insert(const_iterator pos, rng_type &&value) requires is_compatible_value< rng_type >
Inserts value before position in the container.
Definition: concatenated_sequences.hpp:878
reference front()
Return the first element as a view. Calling front on an empty container is undefined.
Definition: concatenated_sequences.hpp:565
void resize(size_type const count)
Resizes the container to contain count elements.
Definition: concatenated_sequences.hpp:1215
decltype(std::as_const(data_values)|ranges::view::slice(0, 1)|ranges::view::const_) const_reference
An immutable proxy of type ranges::view::slice that represents the range on the concatenated vector...
Definition: concatenated_sequences.hpp:141
~concatenated_sequences()=default
Default constructors.
Adaptations of concepts from the Ranges TS.
iterator begin() noexcept
Returns an iterator to the first element of the container.
Definition: concatenated_sequences.hpp:444
const_reference front() const
Return the first element as a view. Calling front on an empty container is undefined.
Definition: concatenated_sequences.hpp:572
const_iterator begin() const noexcept
Returns an iterator to the first element of the container.
Definition: concatenated_sequences.hpp:450
Adaptions of concepts from the Cereal library.
static constexpr bool is_compatible_this
Whether a type satisfies seqan3::compatible_concept with this class.
Definition: concatenated_sequences.hpp:183
void assign(begin_iterator_type begin_it, end_iterator_type end_it)
Construct/assign from pair of iterators.
Definition: concatenated_sequences.hpp:395
void resize(size_type const count, rng_type &&value) requires is_compatible_value< rng_type >
Resizes the container to contain count elements.
Definition: concatenated_sequences.hpp:1228
Specifies requirements of a Range type for which begin returns a type that models std::ForwardIterato...
iterator insert(const_iterator pos, std::initializer_list< rng_type > const &ilist) requires is_compatible_value< rng_type >
Inserts elements from initializer list before position in the container.
Definition: concatenated_sequences.hpp:1066
size_type capacity() const noexcept
Returns the number of elements that the container has currently allocated space for.
Definition: concatenated_sequences.hpp:714
Provides C++20 additions to the type_traits header.
reference operator[](size_type const i)
Return the i-th element as a view.
Definition: concatenated_sequences.hpp:539
const_iterator end() const noexcept
Returns an iterator to the element following the last element of the container.
Definition: concatenated_sequences.hpp:480
concatenated_sequences(rng_of_rng_type &&rng_of_rng)
Construct/assign from a different range.
Definition: concatenated_sequences.hpp:227
void shrink_to_fit()
Requests the removal of unused capacity.
Definition: concatenated_sequences.hpp:765
The SizedSentinel concept specifies that an object of the iterator type I and an object of the sentin...
iterator insert(const_iterator pos, size_type const count, rng_type &&value) requires is_compatible_value< rng_type >
Inserts count copies of value before position in the container.
Definition: concatenated_sequences.hpp:910
reference concat()
Return the concatenation of all members.
Definition: concatenated_sequences.hpp:617
const_iterator cbegin() const noexcept
Returns an iterator to the first element of the container.
Definition: concatenated_sequences.hpp:456
detail::random_access_iterator< concatenated_sequences const > const_iterator
The const iterator type of this container (a random access iterator).
Definition: concatenated_sequences.hpp:149
reference back()
Return the last element as a view.
Definition: concatenated_sequences.hpp:590
void assign(std::initializer_list< rng_type > ilist)
Construct/assign from std::initializer_list.
Definition: concatenated_sequences.hpp:418
Adaptations of concepts from the standard library.
iterator insert(const_iterator pos, begin_iterator_type first, end_iterator_type last)
Inserts elements from range [first, last) before position in the container.
Definition: concatenated_sequences.hpp:990
Specifies the requirements of a Range type that knows its size in constant time with the size functio...
const_reference back() const
Return the last element as a view.
Definition: concatenated_sequences.hpp:597
reference at(size_type const i)
Return the i-th element as a view.
Definition: concatenated_sequences.hpp:508
void assign(size_type const count, rng_type &&value)
Construct/assign with count times value.
Definition: concatenated_sequences.hpp:371
concatenated_sequences(size_type const count, rng_type &&value)
Construct/assign with count times value.
Definition: concatenated_sequences.hpp:256
void push_back(rng_type &&value) requires is_compatible_value< rng_type >
Appends the given element value to the end of the container.
Definition: concatenated_sequences.hpp:1158
concatenated_sequences & operator=(std::initializer_list< rng_type > ilist)
Construct/assign from std::initializer_list.
Definition: concatenated_sequences.hpp:326