jaulib v1.3.6
Jau Support Library (C++, Java, ..)
|
Implementation of a Copy-On-Write (CoW) read-write iterator over mutable value_type storage. More...
#include <cow_iterator.hpp>
Public Types | |
typedef CoW_container | cow_container_t |
typedef storage_t::difference_type | difference_type |
typedef sub_traits_t::iterator_category | iterator_category |
typedef storage_t::iterator | iterator_type |
Actual iterator type of the contained native iterator, probably a simple pointer. | |
typedef sub_traits_t::pointer | pointer |
typedef sub_traits_t::reference | reference |
typedef storage_t::size_type | size_type |
typedef Storage_ref_type | storage_ref_t |
typedef Storage_type | storage_t |
typedef sub_traits_t::value_type | value_type |
Public Member Functions | |
constexpr | cow_rw_iterator (const cow_rw_iterator &o) noexcept |
C++ named requirements: LegacyIterator: CopyConstructible. | |
constexpr | cow_rw_iterator (cow_rw_iterator &&o) noexcept |
C++ named requirements: LegacyIterator: MoveConstructable. | |
constexpr iterator_type | base () const noexcept |
Returns a copy of the underlying storage iterator. | |
constexpr cow_rw_iterator | begin () const noexcept |
Returns a new iterator pointing to the first element, aka begin. | |
constexpr bool | capacity_reached () const noexcept |
Returns true if storage capacity has been reached and the next push_back() will grow the storage and invalidates all iterators and references. | |
constexpr int | compare (const cow_rw_iterator &rhs) const noexcept |
Returns signum or three-way comparison value. | |
constexpr difference_type | dist_begin () const noexcept |
Returns the distance to_begin() using zero as first index. | |
constexpr difference_type | dist_end () const noexcept |
Returns the distance to_end() using zero as first index. | |
template<typename... Args> | |
constexpr void | emplace (Args &&... args) |
Like std::vector::emplace(), construct a new element in place. | |
template<typename... Args> | |
constexpr reference | emplace_back (Args &&... args) |
Like std::vector::emplace_back(), construct a new element in place at the end(). | |
constexpr bool | empty () const noexcept |
Returns true if storage is empty(). | |
constexpr cow_rw_iterator | end () const noexcept |
Returns a new iterator pointing to the element following the last element, aka end. | |
constexpr void | erase () |
Erases the element at the current position. | |
constexpr void | erase (size_type count) |
Like std::vector::erase(), removes the elements in the range [current, current+count). | |
std::string | get_info () const noexcept |
constexpr cow_ro_iterator< Storage_type, Storage_ref_type, CoW_container > | immutable () const noexcept |
Returns a new const_iterator pointing to the current position. | |
constexpr void | insert (const value_type &x) |
Inserts the element before the current position and moves all elements from there to the right beforehand. | |
template<class InputIt> | |
constexpr void | insert (InputIt first, InputIt last) |
Like std::vector::insert(), inserting the value_type range [first, last). | |
constexpr void | insert (value_type &&x) |
Inserts the element before the current position (std::move operation) and moves all elements from there to the right beforehand. | |
constexpr bool | is_begin () const noexcept |
Returns true, if this iterator points to begin(). | |
constexpr bool | is_end () const noexcept |
Returns true, if this iterator points to end(). | |
constexpr const reference | operator* () const noexcept |
Dereferencing iterator to value_type reference. | |
constexpr reference | operator* () noexcept |
Dereferencing iterator to value_type reference. | |
constexpr cow_rw_iterator | operator+ (difference_type rhs) const noexcept |
Binary 'iterator + element_count'; Try to avoid: Low performance due to returning copy-ctor. | |
constexpr cow_rw_iterator & | operator++ () noexcept |
Pre-increment; Well performing, return *this. | |
constexpr cow_rw_iterator | operator++ (int) noexcept |
Post-increment; Try to avoid: Low performance due to returning copy-ctor. | |
constexpr cow_rw_iterator & | operator+= (difference_type i) noexcept |
Addition-assignment of 'element_count'; Well performing, return *this. | |
constexpr difference_type | operator- (const cow_rw_iterator &rhs) const noexcept |
Binary 'iterator - iterator -> element_count'; Well performing, return element_count of type difference_type. | |
constexpr cow_rw_iterator | operator- (difference_type rhs) const noexcept |
Binary 'iterator - element_count'; Try to avoid: Low performance due to returning copy-ctor. | |
constexpr cow_rw_iterator & | operator-- () noexcept |
Pre-decrement; Well performing, return *this. | |
constexpr cow_rw_iterator | operator-- (int) noexcept |
Post-decrement; Try to avoid: Low performance due to returning copy-ctor. | |
constexpr cow_rw_iterator & | operator-= (difference_type i) noexcept |
Subtraction-assignment of 'element_count'; Well performing, return *this. | |
constexpr const pointer | operator-> () const noexcept |
Pointer to member access. | |
constexpr pointer | operator-> () noexcept |
Pointer to member access. | |
std::strong_ordering | operator<=> (const cow_rw_iterator &rhs) const noexcept |
Three way std::strong_ordering comparison operator, C++20. | |
constexpr cow_rw_iterator & | operator= (const cow_rw_iterator &o) noexcept |
Assigns content of other mutable iterator to this one, if they are not identical. | |
constexpr cow_rw_iterator & | operator= (cow_rw_iterator &&o) noexcept |
Assigns identity of given mutable iterator, if they are not identical. | |
constexpr bool | operator== (const cow_rw_iterator &rhs) const noexcept |
Two way comparison operator, != is implicit, C++20. | |
constexpr const reference | operator[] (difference_type i) const noexcept |
Subscript of 'element_index', returning immutable Value_type reference. | |
constexpr reference | operator[] (difference_type i) noexcept |
Subscript of 'element_index', returning mutable Value_type reference. | |
constexpr void | pop_back () noexcept |
Removes the last element and sets this iterator to end() | |
constexpr void | push_back (const value_type &x) |
Like std::vector::push_back(), copy. | |
template<class InputIt> | |
constexpr void | push_back (InputIt first, InputIt last) |
Like std::vector::push_back(), but appends the value_type range [first, last). | |
constexpr void | push_back (value_type &&x) |
Like std::vector::push_back(), move. | |
constexpr size_type | size () const noexcept |
Return the size of the underlying value_type store. | |
constexpr storage_t & | storage () const noexcept |
Returns this instances' underlying shared storage by reference. | |
void | swap (cow_rw_iterator &o) noexcept |
C++ named requirements: LegacyIterator: Swappable. | |
constexpr cow_rw_iterator & | to_begin () noexcept |
This iterator is set to the first element, begin(). | |
constexpr cow_rw_iterator & | to_end () noexcept |
This iterator is set to the last element, end(). | |
std::string | toString () const noexcept |
void | write_back () noexcept |
Replace the parent's current store with this iterators' instance, unlock the CoW parents' write lock and discard all storage references. | |
Friends | |
template<typename, typename, typename, bool, bool> | |
class | cow_darray |
template<typename, typename> | |
class | cow_vector |
Implementation of a Copy-On-Write (CoW) read-write iterator over mutable value_type storage.
Instance holds a copy of the parents' CoW storage and locks its write mutex until write_back() or destruction.
Implementation complies with Type Traits iterator_category 'random_access_iterator_tag'
This iterator wraps the native iterator of type 'iterator_type' and manages the CoW related resource lifecycle.
After completing all mutable operations but before this iterator's destruction, the user might want to write back this iterators' storage to its parents' CoW using write_back()
Due to the costly nature of mutable CoW resource management, consider using jau::cow_ro_iterator if elements won't get mutated or any changes can be discarded.
To allow data-race free operations on this iterator's data copy from a potentially mutated CoW, only one begin iterator should be retrieved from CoW and all further operations shall use jau::cow_rw_iterator::size(), jau::cow_rw_iterator::begin() and jau::cow_rw_iterator::end().
Definition at line 84 of file cow_iterator.hpp.
typedef Storage_type jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::storage_t |
Definition at line 90 of file cow_iterator.hpp.
typedef Storage_ref_type jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::storage_ref_t |
Definition at line 91 of file cow_iterator.hpp.
typedef CoW_container jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::cow_container_t |
Definition at line 92 of file cow_iterator.hpp.
typedef storage_t::iterator jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::iterator_type |
Actual iterator type of the contained native iterator, probably a simple pointer.
Definition at line 95 of file cow_iterator.hpp.
typedef sub_traits_t::iterator_category jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::iterator_category |
Definition at line 114 of file cow_iterator.hpp.
typedef storage_t::size_type jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::size_type |
Definition at line 116 of file cow_iterator.hpp.
typedef storage_t::difference_type jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::difference_type |
Definition at line 117 of file cow_iterator.hpp.
typedef sub_traits_t::value_type jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::value_type |
Definition at line 121 of file cow_iterator.hpp.
typedef sub_traits_t::reference jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::reference |
Definition at line 122 of file cow_iterator.hpp.
typedef sub_traits_t::pointer jau::cow_rw_iterator< Storage_type, Storage_ref_type, CoW_container >::pointer |
Definition at line 123 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
C++ named requirements: LegacyIterator: CopyConstructible.
Definition at line 167 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
C++ named requirements: LegacyIterator: MoveConstructable.
Definition at line 194 of file cow_iterator.hpp.
|
inlinenoexcept |
Replace the parent's current store with this iterators' instance, unlock the CoW parents' write lock and discard all storage references.
After calling write_back(), this iterator is invalidated and no more operational.
It is the user's responsibility to issue call this method to update the CoW parents' storage.
It is not feasible nor effective to automatically earmark a dirty state on mutable operations.
This is due to the ambiguous semantics of like operator*()
.
Also usage of multiple iterators to one CoW instance during a mutable operation complicates such an automated task, especially as we wish to only realize one storage replacement at the end.
Lastly, the user probably wants to issue the CoW storage sync in a programmatic deterministic fashion at the end.
Definition at line 154 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Assigns content of other mutable iterator to this one, if they are not identical.
C++ named requirements: LegacyIterator: CopyAssignable
o | the new identity value to be copied into this iterator |
Definition at line 180 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Assigns identity of given mutable iterator, if they are not identical.
C++ named requirements: LegacyIterator: MoveAssignable
o | the new identity to be taken |
Definition at line 210 of file cow_iterator.hpp.
|
inlinenoexcept |
C++ named requirements: LegacyIterator: Swappable.
Definition at line 224 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns a new const_iterator pointing to the current position.
This is the only explicit conversion operation of mutable -> immutable iterator, see below.
Be aware that the resulting cow_ro_iterator points to transient storage of this immutable iterator. In case write_back() won't be called and this iterator destructs, the returned immutable iterator is invalidated.
Definition at line 242 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns a new iterator pointing to the first element, aka begin.
This is an addition API entry, allowing data-race free operations on this iterator's data snapshot from a potentially mutated CoW.
Definition at line 254 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns a new iterator pointing to the element following the last element, aka end.
This is an addition API entry, allowing data-race free operations on this iterator's data snapshot from a potentially mutated CoW.
Definition at line 266 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns true if storage is empty().
Definition at line 272 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns true if storage capacity has been reached and the next push_back() will grow the storage and invalidates all iterators and references.
Definition at line 278 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Return the size of the underlying value_type store.
This is an addition API entry, allowing data-race free arithmetic on this iterator's data snapshot from a potentially mutated CoW.
Definition at line 289 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns this instances' underlying shared storage by reference.
Definition at line 294 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns the distance to_end() using zero as first index.
A.k.a the remaining elements iterable.
Definition at line 301 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns true, if this iterator points to end().
Definition at line 306 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
This iterator is set to the last element, end().
Returns *this;
Definition at line 311 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns the distance to_begin() using zero as first index.
A.k.a the index from start.
Definition at line 317 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns true, if this iterator points to begin().
Definition at line 322 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
This iterator is set to the first element, begin().
Returns *this;
Definition at line 327 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns a copy of the underlying storage iterator.
Definition at line 333 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Returns signum or three-way comparison value.
0 if equal (both, store and iteratore), -1 if this->iterator_ < rhs_iter and 1 if this->iterator_ > rhs_iter (otherwise)
rhs_store | right-hand side store |
rhs_iter | right-hand side iterator |
Definition at line 347 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Two way comparison operator, !=
is implicit, C++20.
Definition at line 353 of file cow_iterator.hpp.
|
inlinenoexcept |
Three way std::strong_ordering comparison operator, C++20.
Definition at line 357 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Dereferencing iterator to value_type reference.
Definition at line 368 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Pointer to member access.
Definition at line 376 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Dereferencing iterator to value_type reference.
Definition at line 384 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Pointer to member access.
Definition at line 390 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Pre-increment; Well performing, return *this.
Definition at line 395 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Post-increment; Try to avoid: Low performance due to returning copy-ctor.
Definition at line 401 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Pre-decrement; Well performing, return *this.
Definition at line 407 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Post-decrement; Try to avoid: Low performance due to returning copy-ctor.
Definition at line 413 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Subscript of 'element_index', returning immutable Value_type reference.
Definition at line 419 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Subscript of 'element_index', returning mutable Value_type reference.
Definition at line 425 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Addition-assignment of 'element_count'; Well performing, return *this.
Definition at line 430 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Binary 'iterator + element_count'; Try to avoid: Low performance due to returning copy-ctor.
Definition at line 434 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Subtraction-assignment of 'element_count'; Well performing, return *this.
Definition at line 438 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Binary 'iterator - element_count'; Try to avoid: Low performance due to returning copy-ctor.
Definition at line 442 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Binary 'iterator - iterator -> element_count'; Well performing, return element_count of type difference_type.
Definition at line 448 of file cow_iterator.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 459 of file cow_iterator.hpp.
|
inlineconstexprnoexcept |
Removes the last element and sets this iterator to end()
Definition at line 468 of file cow_iterator.hpp.
|
inlineconstexpr |
Erases the element at the current position.
This iterator is set to the element following the last removed element.
Definition at line 479 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::erase(), removes the elements in the range [current, current+count).
This iterator is set to the element following the last removed element.
Definition at line 489 of file cow_iterator.hpp.
|
inlineconstexpr |
Inserts the element before the current position and moves all elements from there to the right beforehand.
size will be increased by one.
This iterator is set to the inserted element.
Definition at line 503 of file cow_iterator.hpp.
|
inlineconstexpr |
Inserts the element before the current position (std::move operation) and moves all elements from there to the right beforehand.
size will be increased by one.
This iterator is set to the inserted element.
Definition at line 517 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::emplace(), construct a new element in place.
Constructs the element before the current position using placement new and moves all elements from there to the right beforehand.
size will be increased by one.
This iterator is set to the inserted element.
args | arguments to forward to the constructor of the element |
Definition at line 536 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::insert(), inserting the value_type range [first, last).
This iterator is set to the first element inserted, or pos if first==last.
InputIt | foreign input-iterator to range of value_type [first, last) |
first | first foreign input-iterator to range of value_type [first, last) |
last | last foreign input-iterator to range of value_type [first, last) |
Definition at line 550 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::push_back(), copy.
This iterator is set to the end.
x | the value to be added at the tail. |
Definition at line 561 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::push_back(), move.
This iterator is set to the end.
x | the value to be added at the tail. |
Definition at line 573 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::emplace_back(), construct a new element in place at the end().
Constructs the element at the end() using placement new.
size will be increased by one.
This iterator is set to the end.
args | arguments to forward to the constructor of the element |
Definition at line 592 of file cow_iterator.hpp.
|
inlineconstexpr |
Like std::vector::push_back(), but appends the value_type range [first, last).
This iterator is set to the end.
InputIt | foreign input-iterator to range of value_type [first, last) |
first | first foreign input-iterator to range of value_type [first, last) |
last | last foreign input-iterator to range of value_type [first, last) |
Definition at line 608 of file cow_iterator.hpp.
|
friend |
Definition at line 86 of file cow_iterator.hpp.
|
friend |
Definition at line 87 of file cow_iterator.hpp.