A space-optimised version of std::vector that compresses multiple letters into a single byte. More...
#include <bio/ranges/container/bitcompressed_vector.hpp>
Public Types | |
Associated types | |
using | value_type = alphabet_type |
Equals the alphabet_type. | |
using | reference = reference_proxy_type |
A proxy type that enables assignment, if the underlying data structure also provides a proxy. | |
using | const_reference = alphabet_type |
Equals the alphabet_type / value_type. | |
using | iterator = detail::random_access_iterator< bitcompressed_vector > |
The iterator type of this container (a random access iterator). | |
using | const_iterator = detail::random_access_iterator< bitcompressed_vector const > |
The const_iterator type of this container (a random access iterator). | |
using | difference_type = std::ranges::range_difference_t< data_type > |
A signed integer type (usually std::ptrdiff_t) | |
using | size_type = std::ranges::range_size_t< data_type > |
An unsigned integer type (usually std::size_t) | |
Public Member Functions | |
Constructors, destructor and assignment | |
bitcompressed_vector ()=default | |
Defaulted. | |
constexpr | bitcompressed_vector (bitcompressed_vector const &)=default |
Defaulted. | |
constexpr | bitcompressed_vector (bitcompressed_vector &&) noexcept=default |
Defaulted. | |
constexpr bitcompressed_vector & | operator= (bitcompressed_vector const &)=default |
Defaulted. | |
constexpr bitcompressed_vector & | operator= (bitcompressed_vector &&) noexcept=default |
Defaulted. | |
~bitcompressed_vector () noexcept=default | |
Defaulted. | |
template<meta::different_from< bitcompressed_vector > other_range_t> requires (std::ranges::input_range<other_range_t> && has_same_value_type_v<other_range_t>) | |
bitcompressed_vector (other_range_t &&range) | |
Construct from a different range. | |
bitcompressed_vector (size_type const count, value_type const value) | |
Construct with count times value . | |
template<std::forward_iterator begin_iterator_type, typename end_iterator_type > requires (std::sentinel_for<end_iterator_type, begin_iterator_type> && std::common_reference_with<std::iter_value_t<begin_iterator_type>, value_type>) | |
bitcompressed_vector (begin_iterator_type begin_it, end_iterator_type end_it) | |
Construct from pair of iterators. | |
bitcompressed_vector (std::initializer_list< value_type > ilist) | |
Construct from std::initializer_list . | |
bitcompressed_vector & | operator= (std::initializer_list< value_type > ilist) |
Assign from std::initializer_list . | |
template<std::ranges::input_range other_range_t> requires std::common_reference_with<std::ranges::range_value_t<other_range_t>, value_type> | |
void | assign (other_range_t &&range) |
Assign from a different range. | |
void | assign (size_type const count, value_type const value) |
Assign with count times value . | |
template<std::forward_iterator begin_iterator_type, typename end_iterator_type > requires (std::sentinel_for<end_iterator_type, begin_iterator_type> && std::common_reference_with<std::iter_value_t<begin_iterator_type>, value_type>) | |
void | assign (begin_iterator_type begin_it, end_iterator_type end_it) |
Assign from pair of iterators. | |
void | assign (std::initializer_list< value_type > ilist) |
Assign from std::initializer_list . | |
Iterators | |
iterator | begin () noexcept |
Returns an iterator to the first element of the container. | |
const_iterator | begin () const noexcept |
Returns an iterator to the first element of the container. | |
const_iterator | cbegin () const noexcept |
Returns an iterator to the first element of the container. | |
iterator | end () noexcept |
Returns an iterator to the element following the last element of the container. | |
const_iterator | end () const noexcept |
Returns an iterator to the element following the last element of the container. | |
const_iterator | cend () const noexcept |
Returns an iterator to the element following the last element of the container. | |
Element access | |
reference | at (size_type const i) |
Return the i-th element. | |
const_reference | at (size_type const i) const |
Return the i-th element. | |
reference | operator[] (size_type const i) noexcept |
Return the i-th element. | |
const_reference | operator[] (size_type const i) const noexcept |
Return the i-th element. | |
reference | front () noexcept |
Return the first element. Calling front on an empty container is undefined. | |
const_reference | front () const noexcept |
Return the first element. Calling front on an empty container is undefined. | |
reference | back () noexcept |
Return the last element. | |
const_reference | back () const noexcept |
Return the last element. | |
constexpr data_type & | raw_data () noexcept |
Provides direct, unsafe access to underlying data structures. | |
constexpr data_type const & | raw_data () const noexcept |
Provides direct, unsafe access to underlying data structures. | |
Capacity | |
bool | empty () const noexcept |
Checks whether the container is empty. | |
size_type | size () const noexcept |
Returns the number of elements in the container, i.e. std::distance(begin(), end()). | |
size_type | max_size () const noexcept |
Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest container. | |
size_type | capacity () const noexcept |
Returns the number of elements that the container has currently allocated space for. | |
void | reserve (size_type const new_cap) |
Increase the capacity to a value that's greater or equal to new_cap. | |
void | shrink_to_fit () |
Requests the removal of unused capacity. | |
Friends | |
auto | operator<=> (bitcompressed_vector const &lhs, bitcompressed_vector const &rhs) noexcept=default |
Comparison operators. | |
Modifiers | |
void | clear () noexcept |
Removes all elements from the container. | |
iterator | insert (const_iterator pos, value_type const value) |
Inserts value before position in the container. | |
iterator | insert (const_iterator pos, size_type const count, value_type const value) |
Inserts count copies of value before position in the container. | |
template<std::forward_iterator begin_iterator_type, typename end_iterator_type > requires (std::sentinel_for<end_iterator_type, begin_iterator_type> && std::common_reference_with<std::iter_value_t<begin_iterator_type>, value_type>) | |
iterator | insert (const_iterator pos, begin_iterator_type begin_it, end_iterator_type end_it) |
Inserts elements from range [begin_it, end_it) before position in the container. | |
iterator | insert (const_iterator pos, std::initializer_list< value_type > const &ilist) |
Inserts elements from initializer list before position in the container. | |
iterator | erase (const_iterator begin_it, const_iterator end_it) |
Removes specified elements from the container. | |
iterator | erase (const_iterator pos) |
Removes specified elements from the container. | |
void | push_back (value_type const value) |
Appends the given element value to the end of the container. | |
void | pop_back () |
Removes the last element of the container. | |
void | resize (size_type const count) |
Resizes the container to contain count elements. | |
void | resize (size_type const count, value_type const value) |
Resizes the container to contain count elements. | |
constexpr void | swap (bitcompressed_vector &rhs) noexcept |
Swap contents with another instance. | |
constexpr void | swap (bitcompressed_vector &&rhs) noexcept |
Swap contents with another instance. | |
constexpr void | swap (bitcompressed_vector &lhs, bitcompressed_vector &rhs) noexcept |
Swap contents with another instance. | |
constexpr void | swap (bitcompressed_vector &&lhs, bitcompressed_vector &&rhs) noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
A space-optimised version of std::vector that compresses multiple letters into a single byte.
alphabet_type | The value type of the container, must satisfy bio::alphabet::writable_semialphabet and std::regular. |
This class template behaves just like std::vector<alphabet_type> but has an internal representation where multiple values are packed into a single byte/word to save space, e.g. bitcompressed_vector<bio::alphabet::dna4> uses a quarter of of the memory that std::vector<bio::alphabet::dna4> uses, because a single bio::alphabet::dna4 letter can be represented in two bits (instead of 8 which is the lower bound for a single object in C++).
The disadvantages are slightly slower operations and unsafety towards parallel writes to adjacent positions in the bitcompressed_vector.
This container provides no thread-safety beyond the promise given also by the STL that all calls to const
member function are safe from multiple threads (as long as no thread calls a non-const
member function at the same time).
An important difference to std::vector is that calling vec[i] = value;
and vec[j] = value2;
from two different threads at the same time is not safe and will lead to corruption if both values are stored in the same 64bit-block, i.e. if the distance between i
and j
is smaller than 64 / alphabet_size.
|
inlineexplicit |
Construct from a different range.
other_range_t | The type of range to construct from; must satisfy std::ranges::input_range and std::common_reference_with<std::ranges::range_value_t<other_range_t>, value_type>. |
[in] | range | The sequences to construct/assign from. |
Linear in the size of range
.
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Construct with count
times value
.
[in] | count | Number of elements. |
[in] | value | The initial value to be assigned. |
In .
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Construct from pair of iterators.
begin_iterator_type | Must model std::forward_iterator and std::common_reference_with<std::iter_value_t<begin_iterator_type>, value_type>. |
end_iterator_type | Must model std::sentinel_for. |
[in] | begin_it | Begin of range to construct/assign from. |
[in] | end_it | End of range to construct/assign from. |
Linear in the distance between begin_it
and end_it
.
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Construct from std::initializer_list
.
[in] | ilist | A std::initializer_list of value_type. |
Linear in the size of ilist
.
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Assign from pair of iterators.
begin_iterator_type | Must satisfy std::forward_iterator and std::common_reference_with<std::iter_value_t<begin_iterator_type>, value_type>. |
end_iterator_type | Must satisfy std::sentinel_for. |
[in] | begin_it | Begin of range to construct/assign from. |
[in] | end_it | End of range to construct/assign from. |
Linear in the distance between begin_it
and end_it
.
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Assign from a different range.
other_range_t | The type of range to be inserted; must satisfy std::ranges::input_range and std::common_reference_with<std::ranges::range_value_t<other_range_t>, value_type>. |
[in] | range | The sequences to construct/assign from. |
Linear in the size of range
.
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Assign with count
times value
.
[in] | count | Number of elements. |
[in] | value | The initial value to be assigned. |
In .
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Assign from std::initializer_list
.
[in] | ilist | A std::initializer_list of value_type. |
Linear in the size of ilist
.
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Return the i-th element.
[in] | i | Index of the element to retrieve. |
std::out_of_range | If you access an element behind the last. |
Constant.
Throws std::out_of_range if i >= size()
.
|
inline |
Return the i-th element.
[in] | i | Index of the element to retrieve. |
std::out_of_range | If you access an element behind the last. |
Constant.
Throws std::out_of_range if i >= size()
.
|
inlinenoexcept |
Return the last element.
Calling back on an empty container is undefined. In debug mode an assertion checks the size of the container.
Constant.
No-throw guarantee.
|
inlinenoexcept |
Return the last element.
Calling back on an empty container is undefined. In debug mode an assertion checks the size of the container.
Constant.
No-throw guarantee.
|
inlinenoexcept |
Returns an iterator to the first element of the container.
If the container is empty, the returned iterator will be equal to end().
Constant.
No-throw guarantee.
|
inlinenoexcept |
Returns an iterator to the first element of the container.
If the container is empty, the returned iterator will be equal to end().
Constant.
No-throw guarantee.
|
inlinenoexcept |
Returns the number of elements that the container has currently allocated space for.
This does not operate on underlying concat container, see concat_capacity().
Constant.
No-throw guarantee.
|
inlinenoexcept |
Returns an iterator to the first element of the container.
If the container is empty, the returned iterator will be equal to end().
Constant.
No-throw guarantee.
|
inlinenoexcept |
Returns an iterator to the element following the last element of the container.
This element acts as a placeholder; attempting to dereference it results in undefined behaviour.
Constant.
No-throw guarantee.
|
inlinenoexcept |
Removes all elements from the container.
Constant.
No-throw guarantee.
|
inlinenoexcept |
Checks whether the container is empty.
true
if the container is empty, false
otherwise.Constant.
No-throw guarantee.
|
inlinenoexcept |
Returns an iterator to the element following the last element of the container.
This element acts as a placeholder; attempting to dereference it results in undefined behaviour.
Constant.
No-throw guarantee.
|
inlinenoexcept |
Returns an iterator to the element following the last element of the container.
This element acts as a placeholder; attempting to dereference it results in undefined behaviour.
Constant.
No-throw guarantee.
|
inline |
Removes specified elements from the container.
begin_it | Begin of range to erase. |
end_it | Behind the end of range to erase. |
begin_it
refers to the last element or begin_it == end_it, the end() iterator is returned.The iterator begin_it does not need to be dereferenceable if begin_it==end_it: erasing an empty range is a no-op.
This function always reallocates, so all iterators and references are invalidated.
Linear in the new size().
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Removes specified elements from the container.
pos | Remove the element at pos. |
pos
refers to the last element, the end() iterator is returned.This function always reallocates, so all iterators and references are invalidated.
Linear in the new size().
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inlinenoexcept |
Return the first element. Calling front on an empty container is undefined.
Calling front on an empty container is undefined. In debug mode an assertion checks the size of the container.
Constant.
No-throw guarantee.
|
inlinenoexcept |
Return the first element. Calling front on an empty container is undefined.
Calling front on an empty container is undefined. In debug mode an assertion checks the size of the container.
Constant.
No-throw guarantee.
|
inline |
Inserts elements from range [begin_it, end_it)
before position in the container.
begin_iterator_type | Must satisfy std::forward_iterator and std::common_reference_with<std::iter_value_t<begin_iterator_type>, value_type>. |
end_iterator_type | Must satisfy std::sentinel_for. |
[in] | pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
[in] | begin_it | Begin of range to construct/assign from. |
[in] | end_it | End of range to construct/assign from. |
pos
if begin_it==end_it
.The behaviour is well-defined, even if begin_it and end_it are iterators into *this
.
This function always reallocates, so all iterators and references are invalidated.
Linear in the new size().
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Inserts count copies of value before position in the container.
pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
count | Number of copies. |
value | Element value to insert. |
pos
if count==0
.This function always reallocates, so all iterators and references are invalidated.
Linear in the new size().
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Inserts elements from initializer list before position in the container.
pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
ilist | Initializer list with values to insert. |
pos
if ilist
is empty.This function always reallocates, so all iterators and references are invalidated.
Linear in the new size().
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Inserts value before position in the container.
pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
value | Element value to insert. |
This function always reallocates, so all iterators and references are invalidated.
Linear in the new size().
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inlinenoexcept |
Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest container.
This value typically reflects the theoretical limit on the size of the container. At runtime, the size of the container may be limited to a value smaller than max_size() by the amount of RAM available.
Constant.
No-throw guarantee.
|
inline |
Assign from std::initializer_list
.
[in] | ilist | A std::initializer_list of value_type. |
Linear in the size of ilist
.
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inlinenoexcept |
Return the i-th element.
i | The element to retrieve. |
Accessing an element behind the last causes undefined behaviour. In debug mode an assertion checks the size of the container.
Constant.
No-throw guarantee.
|
inlinenoexcept |
Return the i-th element.
i | The element to retrieve. |
Accessing an element behind the last causes undefined behaviour. In debug mode an assertion checks the size of the container.
Constant.
No-throw guarantee.
|
inline |
Removes the last element of the container.
Calling pop_back() on an empty container is undefined. In debug mode an assertion will be thrown.
No iterators or references except for back() and end() are invalidated.
Constant.
No exception is thrown in release mode.
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Appends the given element value to the end of the container.
value | The value to append. |
If the new size() is greater than capacity() then all iterators and references (including the past-the-end iterator) are invalidated. Otherwise only the past-the-end iterator is invalidated.
Amortised constant, worst-case linear in size().
Basic exception guarantee, i.e. guaranteed not to leak, but container may contain invalid data after exception is thrown.
|
inlineconstexprnoexcept |
Provides direct, unsafe access to underlying data structures.
The exact representation of the data is implementation defined. Do not rely on it for API stability.
|
inlineconstexprnoexcept |
Provides direct, unsafe access to underlying data structures.
The exact representation of the data is implementation defined. Do not rely on it for API stability.
|
inline |
Increase the capacity to a value that's greater or equal to new_cap.
new_cap | The new capacity. |
std::length_error | If new_cap > max_size(). |
std::exception | Any exception thrown by Allocator::allocate() (typically std::bad_alloc ). |
Increase the capacity of the vector to a value that's greater or equal to new_cap. If new_cap is greater than the current capacity(), new storage is allocated, otherwise the method does nothing. If new_cap is greater than capacity(), all iterators, including the past-the-end iterator, and all references to the elements are invalidated. Otherwise, no iterators or references are invalidated.
At most linear in the size() of the container.
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inline |
Resizes the container to contain count elements.
count | The new size. |
std::length_error | If count > max_size(). |
std::exception | Any exception thrown by Allocator::allocate() (typically std::bad_alloc ). |
Increase the size() of the vector to count.
If the current capacity() is smaller than count, new storage is allocated and all iterators, including the past-the-end iterator, and all references to the elements are invalidated. Otherwise only the past-the-end iterator is invalidated.
If the current size is greater than count, the container is reduced to its first count elements. Capacity is never reduced when resizing to smaller size because that would invalidate all iterators, rather than only the ones that would be invalidated by the equivalent sequence of pop_back() calls.
At most linear in the size() of the container.
Only new size: Strong exception guarantee (no data is modified in case an exception is thrown).
New default value: Basic exception guarantee, i.e. guaranteed not to leak, but container my contain bogus data after exceptions is thrown.
|
inline |
Resizes the container to contain count elements.
value | Append copies of value when resizing. |
count | The new size. |
std::length_error | If count > max_size(). |
std::exception | Any exception thrown by Allocator::allocate() (typically std::bad_alloc ). |
Increase the size() of the vector to count.
If the current capacity() is smaller than count, new storage is allocated and all iterators, including the past-the-end iterator, and all references to the elements are invalidated. Otherwise only the past-the-end iterator is invalidated.
If the current size is greater than count, the container is reduced to its first count elements. Capacity is never reduced when resizing to smaller size because that would invalidate all iterators, rather than only the ones that would be invalidated by the equivalent sequence of pop_back() calls.
At most linear in the size() of the container.
Only new size: Strong exception guarantee (no data is modified in case an exception is thrown).
New default value: Basic exception guarantee, i.e. guaranteed not to leak, but container my contain bogus data after exceptions is thrown.
|
inline |
Requests the removal of unused capacity.
It is a non-binding request to reduce capacity() to size() and concat_capacity() to concat_size(). It depends on the implementation if the request is fulfilled. If reallocation occurs, all iterators, including the past the end iterator, and all references to the elements are invalidated. If no reallocation takes place, no iterators or references are invalidated.
At most linear in the size() of the container.
Strong exception guarantee (no data is modified in case an exception is thrown).
|
inlinenoexcept |
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Constant.
No-throw guarantee.
|
inlineconstexprnoexcept |
Swap contents with another instance.
rhs | The other instance to swap with. |
Constant.
No-throw guarantee.
|
inlineconstexprnoexcept |
Swap contents with another instance.
rhs | The other instance to swap with. |
Constant.
No-throw guarantee.
|
friend |
Swap contents with another instance.
lhs | The first instance. |
rhs | The other instance to swap with. |
Constant.
No-throw guarantee.