jaulib v1.3.0
Jau Support Library (C++, Java, ..)
|
Implementation of a Copy-On-Write (CoW) using jau::darray as the underlying storage, exposing lock-free read operations using SC-DRF atomic synchronization. More...
#include <cow_darray.hpp>
Public Types | |
typedef Alloc_type | allocator_type |
typedef cow_ro_iterator< storage_t, storage_ref_t, cow_container_t > | const_iterator |
Immutable, read-only const_iterator, lock-free, holding the current shared store reference until destruction. More... | |
typedef const value_type * | const_pointer |
typedef const value_type & | const_reference |
typedef cow_darray< value_type, size_type, allocator_type, use_memmove, use_secmem > | cow_container_t |
typedef bool | darray_tag |
Used to determine whether this type is a darray or has a darray, see ::is_darray_type<T> More... | |
typedef std::make_signed< size_type >::type | difference_type |
typedef bool(* | equal_comparator) (const value_type &a, const value_type &b) |
Generic value_type equal comparator to be user defined for e.g. More... | |
typedef cow_rw_iterator< storage_t, storage_ref_t, cow_container_t > | iterator |
Mutable, read-write iterator, holding the write-lock and a store copy until destruction. More... | |
typedef value_type * | pointer |
typedef value_type & | reference |
typedef Size_type | size_type |
typedef std::shared_ptr< storage_t > | storage_ref_t |
typedef darray< value_type, size_type, allocator_type, use_memmove, use_secmem > | storage_t |
typedef Value_type | value_type |
Public Member Functions | |
constexpr | cow_darray () noexcept |
Default constructor, giving almost zero capacity and zero memory footprint, but the shared empty jau::darray. More... | |
constexpr_atomic | cow_darray (const cow_darray &x) |
Creates a new instance, copying all elements from the given array. More... | |
constexpr_atomic | cow_darray (const cow_darray &x, const float growth_factor, const allocator_type &alloc) |
Creates a new instance, copying all elements from the given array. More... | |
constexpr_atomic | cow_darray (const cow_darray &x, const size_type _capacity, const float growth_factor, const allocator_type &alloc) |
Creates a new instance with custom initial storage capacity, copying all elements from the given array. More... | |
constexpr | cow_darray (const size_type _capacity, const_iterator first, const_iterator last, const float growth_factor=DEFAULT_GROWTH_FACTOR, const allocator_type &alloc=allocator_type()) |
Creates a new instance with custom initial storage capacity, copying all elements from the given const_iterator value_type range [first, last). More... | |
template<class InputIt > | |
constexpr | cow_darray (const size_type _capacity, InputIt first, InputIt last, const float growth_factor=DEFAULT_GROWTH_FACTOR, const allocator_type &alloc=allocator_type()) |
Creates a new instance with custom initial storage capacity, copying all elements from the given template input-iterator value_type range [first, last). More... | |
constexpr | cow_darray (const storage_t &x) |
constexpr | cow_darray (const storage_t &x, const float growth_factor, const allocator_type &alloc) |
constexpr_atomic | cow_darray (cow_darray &&x) noexcept |
template<class InputIt > | |
constexpr | cow_darray (InputIt first, InputIt last, const allocator_type &alloc=allocator_type()) |
Creates a new instance, copying all elements from the given template input-iterator value_type range [first, last). More... | |
constexpr | cow_darray (size_type capacity, const float growth_factor=DEFAULT_GROWTH_FACTOR, const allocator_type &alloc=allocator_type()) |
Creating an empty instance with initial capacity and other (default) properties. More... | |
constexpr | cow_darray (std::initializer_list< value_type > initlist, const allocator_type &alloc=allocator_type()) |
Using the std::initializer_list requires to copy the given value_type objects into this cow_darray. More... | |
constexpr | cow_darray (storage_t &&x) noexcept |
constexpr | cow_darray (storage_t &&x, const float growth_factor, const allocator_type &alloc) noexcept |
~cow_darray () noexcept | |
constexpr iterator | begin () |
Returns an jau::cow_rw_iterator to the first element of this CoW storage. More... | |
constexpr_atomic size_type | capacity () const noexcept |
Like std::vector::empty(). More... | |
constexpr const_iterator | cbegin () const noexcept |
Returns an jau::cow_ro_iterator to the first element of this CoW storage. More... | |
constexpr_atomic void | clear () noexcept |
Like std::vector::clear(), but ending with zero capacity. More... | |
constexpr_atomic storage_ref_t | copy_store () |
Returns a new shared_ptr copy of the underlying store, i.e. More... | |
template<typename... Args> | |
constexpr_atomic reference | emplace_back (Args &&... args) |
Like std::vector::emplace_back(), construct a new element in place at the end(). More... | |
constexpr_atomic bool | empty () const noexcept |
Like std::vector::empty(). More... | |
constexpr_atomic size_type | erase_matching (const value_type &x, const bool all_matching, equal_comparator comparator) |
Erase either the first matching element or all matching elements. More... | |
allocator_type | get_allocator () const noexcept |
const allocator_type & | get_allocator_ref () const noexcept |
std::string | get_info () const noexcept |
constexpr std::recursive_mutex & | get_write_mutex () noexcept |
Returns this instances' recursive write mutex, allowing user to implement more complex mutable write operations. More... | |
constexpr_atomic float | growth_factor () const noexcept |
Returns the growth factor. More... | |
constexpr size_type | max_size () const noexcept |
Returns std::numeric_limits<difference_type>::max() as the maximum array size. More... | |
constexpr_atomic cow_darray & | operator= (const cow_darray &x) |
Like std::vector::operator=(&), assignment. More... | |
cow_darray & | operator= (const storage_t &x) |
Like std::vector::operator=(&), assignment, but copying from the underling jau::darray. More... | |
constexpr_atomic cow_darray & | operator= (cow_darray &&x) noexcept |
Like std::vector::operator=(&&), move. More... | |
cow_darray & | operator= (storage_t &&x) |
Like std::vector::operator=(&&), move, but taking the underling jau::darray. More... | |
constexpr_atomic void | pop_back () noexcept |
Like std::vector::pop_back(). More... | |
constexpr_atomic void | push_back (const value_type &x) |
Like std::vector::push_back(), copy. More... | |
template<class InputIt > | |
constexpr_atomic void | push_back (InputIt first, InputIt last) |
Like std::vector::push_back(), but appends the whole value_type range [first, last). More... | |
constexpr_atomic void | push_back (value_type &&x) |
Like std::vector::push_back(), move. More... | |
template<typename... Args> | |
constexpr_atomic void | push_back_list (Args &&... args) |
Like push_back(), but for more multiple r-value references to move. More... | |
template<typename... Args> | |
constexpr_atomic void | push_back_list (const Args &... args) |
Like push_back(), but for more multiple const r-value to copy. More... | |
constexpr_atomic bool | push_back_unique (const value_type &x, equal_comparator comparator) |
Like std::vector::push_back(), but only if the newly added element does not yet exist. More... | |
void | reserve (size_type new_capacity) |
Like std::vector::reserve(), increases this instance's capacity to new_capacity . More... | |
constexpr_atomic void | set_store (storage_ref_t &&new_store_ref) noexcept |
Replace the current store with the given instance, potentially acquired via jau::cow_darray::copy_store() and mutated while holding the jau::cow_darray::get_write_mutex() lock. More... | |
constexpr_atomic size_type | size () const noexcept |
Like std::vector::size(). More... | |
constexpr_atomic storage_ref_t | snapshot () const noexcept |
Returns the current snapshot of the underlying shared storage by reference. More... | |
constexpr_atomic void | swap (cow_darray &x) noexcept |
Like std::vector::swap(). More... | |
std::string | toString () const noexcept |
Static Public Attributes | |
static constexpr const float | DEFAULT_GROWTH_FACTOR = 1.618f |
Default growth factor using the golden ratio 1.618. More... | |
static constexpr const bool | uses_memmove = use_memmove |
static constexpr const bool | uses_realloc = use_memmove && std::is_base_of_v<jau::callocator<Value_type>, Alloc_type> |
static constexpr const bool | uses_secmem = use_secmem |
Implementation of a Copy-On-Write (CoW) using jau::darray as the underlying storage, exposing lock-free read operations using SC-DRF atomic synchronization.
This data structure is also supporting Concurrency.
This class shall be compliant with C++ named requirements for Container.
The store is owned using a shared reference to the data structure, allowing its replacement on Copy-On-Write (CoW).
Writing to the store utilizes a mutex lock to avoid data races on the instances' write operations only, leaving read operations lock-free.
Write operations replace the store reference with a new instance using jau::sc_atomic_critical to synchronize with read operations.
Reading from the store is lock-free and accesses the store reference using jau::sc_atomic_critical to synchronizing with write operations.
Immutable storage const_iterators are supported via jau::cow_ro_iterator, which are constructed lock-free.
jau::cow_ro_iterator holds a snapshot retrieved via jau::cow_darray::snapshot() until its destruction.
Mutable storage iterators are supported via jau::cow_rw_iterator, which holds a copy of this CoW storage and locks its write mutex until jau::cow_rw_iterator::write_back() or its destruction.
After completing all mutable operations but before this iterator's destruction, the user might want to write back this iterators' storage to this CoW using jau::cow_rw_iterator::write_back().
Both, jau::cow_ro_iterator and jau::cow_rw_iterator are harmonized to work with jau::darray::const_iterator and jau::darray::iterator for all iterator based operations.
Index operation via ::operator[](size_t) or ::at(size_t) are not supported, since they would be only valid if value_type itself is a std::shared_ptr and hence prohibit the destruction of the object if mutating the storage, e.g. via jau::cow_darray::push_back().
Custom mutable write operations are also supported via jau::cow_darray::get_write_mutex(), jau::cow_darray::copy_store() and jau::cow_darray::set_store().
See example in jau::cow_darray::set_store()
To allow data-race free operations using iterators from a potentially mutated CoW, only one cow_darray::begin() const_iterator or iterator should be retrieved from this CoW and all further operations shall use its jau::cow_ro_iterator::size(), jau::cow_ro_iterator::begin() and jau::cow_ro_iterator::end()
See darray_ntt_params.
use_memmove
see darray_memmove.
use_secmem
see darray_secmem.
See also:
Definition at line 126 of file cow_darray.hpp.
typedef Value_type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::value_type |
Definition at line 138 of file cow_darray.hpp.
typedef value_type* jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::pointer |
Definition at line 139 of file cow_darray.hpp.
typedef const value_type* jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::const_pointer |
Definition at line 140 of file cow_darray.hpp.
typedef value_type& jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::reference |
Definition at line 141 of file cow_darray.hpp.
typedef const value_type& jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::const_reference |
Definition at line 142 of file cow_darray.hpp.
typedef Size_type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::size_type |
Definition at line 143 of file cow_darray.hpp.
typedef std::make_signed<size_type>::type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::difference_type |
Definition at line 144 of file cow_darray.hpp.
typedef Alloc_type jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::allocator_type |
Definition at line 145 of file cow_darray.hpp.
typedef darray<value_type, size_type, allocator_type, use_memmove, use_secmem> jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::storage_t |
Definition at line 149 of file cow_darray.hpp.
typedef std::shared_ptr<storage_t> jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::storage_ref_t |
Definition at line 150 of file cow_darray.hpp.
typedef bool jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::darray_tag |
Used to determine whether this type is a darray or has a darray, see ::is_darray_type<T>
Definition at line 153 of file cow_darray.hpp.
typedef cow_darray<value_type, size_type, allocator_type, use_memmove, use_secmem> jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::cow_container_t |
Definition at line 157 of file cow_darray.hpp.
typedef cow_ro_iterator<storage_t, storage_ref_t, cow_container_t> jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::const_iterator |
Immutable, read-only const_iterator, lock-free, holding the current shared store reference until destruction.
Using jau::cow_darray::snapshot() at construction.
This iterator is the preferred choice if no mutations are made to the elements state itself, or all changes can be discarded after the iterator's destruction.
This avoids the costly mutex lock and storage copy of jau::cow_rw_iterator.
Also see jau::for_each_fidelity to iterate through in this good faith fashion.
Definition at line 178 of file cow_darray.hpp.
typedef cow_rw_iterator<storage_t, storage_ref_t, cow_container_t> jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::iterator |
Mutable, read-write iterator, holding the write-lock and a store copy until destruction.
Using jau::cow_darray::get_write_mutex(), jau::cow_darray::copy_store() at construction
and jau::cow_darray::set_store() at destruction.
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.
Definition at line 197 of file cow_darray.hpp.
typedef bool(* jau::cow_darray< Value_type, Size_type, Alloc_type, use_memmove, use_secmem >::equal_comparator) (const value_type &a, const value_type &b) |
Generic value_type equal comparator to be user defined for e.g.
jau::cow_darray::push_back_unique().
a | one element of the equality test. |
b | the other element of the equality test. |
Definition at line 989 of file cow_darray.hpp.
|
inlineconstexprnoexcept |
Default constructor, giving almost zero capacity and zero memory footprint, but the shared empty jau::darray.
Definition at line 215 of file cow_darray.hpp.
|
inlineexplicitconstexpr |
Creating an empty instance with initial capacity and other (default) properties.
capacity | initial capacity of the new instance. |
growth_factor | given growth factor |
alloc | given allocator_type |
Definition at line 226 of file cow_darray.hpp.
|
inlineconstexpr |
Definition at line 233 of file cow_darray.hpp.
|
inlineexplicitconstexpr |
Definition at line 239 of file cow_darray.hpp.
|
inlineconstexprnoexcept |
Definition at line 262 of file cow_darray.hpp.
|
inlineexplicitconstexprnoexcept |
Definition at line 269 of file cow_darray.hpp.
|
inline |
Creates a new instance, copying all elements from the given array.
Capacity and size will equal the given array, i.e. the result is a trimmed array.
x | the given cow_darray, all elements will be copied into the new instance. |
Definition at line 302 of file cow_darray.hpp.
|
inlineexplicit |
Creates a new instance, copying all elements from the given array.
Capacity and size will equal the given array, i.e. the result is a trimmed array.
x | the given cow_darray, all elements will be copied into the new instance. |
growth_factor | custom growth factor |
alloc | custom allocator_type instance |
Definition at line 322 of file cow_darray.hpp.
|
inlineexplicit |
Creates a new instance with custom initial storage capacity, copying all elements from the given array.
Size will equal the given array.
Throws jau::IllegalArgumentException() if _capacity < x.size()
.
x | the given cow_darray, all elements will be copied into the new instance. |
_capacity | custom initial storage capacity |
growth_factor | custom growth factor |
alloc | custom allocator_type instance |
Definition at line 346 of file cow_darray.hpp.
|
inlinenoexcept |
Definition at line 385 of file cow_darray.hpp.
|
inlineconstexpr |
Creates a new instance with custom initial storage capacity, copying all elements from the given const_iterator value_type range [first, last).
Size will equal the range [first, last), i.e. size_type(last-first)
.
Throws jau::IllegalArgumentException() if _capacity < size_type(last - first)
.
_capacity | custom initial storage capacity |
first | const_iterator to first element of value_type range [first, last) |
last | const_iterator to last element of value_type range [first, last) |
growth_factor | custom growth factor |
alloc | custom allocator_type instance |
Definition at line 447 of file cow_darray.hpp.
|
inlineexplicitconstexpr |
Creates a new instance with custom initial storage capacity, copying all elements from the given template input-iterator value_type range [first, last).
Size will equal the range [first, last), i.e. size_type(last-first)
.
Throws jau::IllegalArgumentException() if _capacity < size_type(last - first)
.
InputIt | template input-iterator custom type |
_capacity | custom initial storage capacity |
first | template input-iterator to first element of value_type range [first, last) |
last | template input-iterator to last element of value_type range [first, last) |
growth_factor | custom growth factor |
alloc | custom allocator_type instance |
Definition at line 469 of file cow_darray.hpp.
|
inlineconstexpr |
Creates a new instance, copying all elements from the given template input-iterator value_type range [first, last).
Size will equal the range [first, last), i.e. size_type(last-first)
.
InputIt | template input-iterator custom type |
first | template input-iterator to first element of value_type range [first, last) |
last | template input-iterator to last element of value_type range [first, last) |
alloc | custom allocator_type instance |
Definition at line 486 of file cow_darray.hpp.
|
inlineconstexpr |
Using the std::initializer_list
requires to copy the given value_type objects into this cow_darray.
To utilize more efficient move semantics, see push_back_list() and jau::make_cow_darray().
initlist | initializer_list. |
alloc | allocator |
Definition at line 502 of file cow_darray.hpp.
|
inlinenoexcept |
Definition at line 509 of file cow_darray.hpp.
|
inline |
Like std::vector::operator=(&), assignment, but copying from the underling jau::darray.
This write operation uses a mutex lock and is blocking this instances' write operations only.
Definition at line 251 of file cow_darray.hpp.
|
inline |
Like std::vector::operator=(&&), move, but taking the underling jau::darray.
This write operation uses a mutex lock and is blocking this instances' write operations only.
Definition at line 282 of file cow_darray.hpp.
|
inline |
Like std::vector::operator=(&), assignment.
This write operation uses a mutex lock and is blocking this instances' write operations only.
Definition at line 365 of file cow_darray.hpp.
|
inlinenoexcept |
Like std::vector::operator=(&&), move.
This write operation uses a mutex lock and is blocking both cow_vector instance's write operations.
Definition at line 410 of file cow_darray.hpp.
|
inlineconstexprnoexcept |
Returns std::numeric_limits<difference_type>::max()
as the maximum array size.
We rely on the signed difference_type
for pointer arithmetic, deducing ranges from iterator.
Definition at line 520 of file cow_darray.hpp.
|
inlineconstexprnoexcept |
Returns this instances' recursive write mutex, allowing user to implement more complex mutable write operations.
See example in jau::cow_darray::set_store()
Definition at line 535 of file cow_darray.hpp.
|
inline |
Returns a new shared_ptr copy of the underlying store, i.e.
using a new copy-constructed vectore.
See example in jau::cow_darray::set_store()
This special operation uses a mutex lock and is blocking this instances' write operations only.
Definition at line 551 of file cow_darray.hpp.
|
inlinenoexcept |
Replace the current store with the given instance, potentially acquired via jau::cow_darray::copy_store() and mutated while holding the jau::cow_darray::get_write_mutex() lock.
This is a move operation, i.e. the given new_store_ref is invalid on the caller side after this operation.
User shall pass the store via std::move()
cow_darray<std::shared_ptr<Thing>> list; ... { std::lock_guard<std::recursive_mutex> lock(list.get_write_mutex()); std::shared_ptr<std::vector<std::shared_ptr<Thing>>> snapshot = list.copy_store(); ... some fancy mutation ... list.set_store(std::move(snapshot)); }
Above functionality is covered by jau::cow_rw_iterator, see also jau::cow_rw_iterator::write_back()
new_store_ref | the user store to be moved here, replacing the current store. |
Definition at line 588 of file cow_darray.hpp.
|
inlinenoexcept |
Returns the current snapshot of the underlying shared storage by reference.
Note that this snapshot will be outdated by the next (concurrent) write operation.
The returned referenced vector is still valid and not mutated, but does not represent the current content of this cow_darray instance.
This read operation is lock-free.
Definition at line 611 of file cow_darray.hpp.
|
inlineconstexprnoexcept |
Returns an jau::cow_ro_iterator to the first element of this CoW storage.
This method is the preferred choice if the use case allows, read remarks in jau::cow_ro_iterator.
Use jau::cow_ro_iterator::end() on this returned const_iterator to retrieve the end const_iterator in a data-race free fashion.
Definition at line 637 of file cow_darray.hpp.
|
inlineconstexpr |
Returns an jau::cow_rw_iterator to the first element of this CoW storage.
Acquiring this mutable iterator has considerable costs attached, read remarks in jau::cow_rw_iterator.
Use jau::cow_rw_iterator::end() on this returned iterator to retrieve the end iterator in a data-race free fashion.
Definition at line 660 of file cow_darray.hpp.
|
inlinenoexcept |
Definition at line 666 of file cow_darray.hpp.
|
inlinenoexcept |
Definition at line 671 of file cow_darray.hpp.
|
inlinenoexcept |
Returns the growth factor.
Definition at line 680 of file cow_darray.hpp.
|
inlinenoexcept |
Like std::vector::empty().
This read operation is lock-free.
Definition at line 693 of file cow_darray.hpp.
|
inlinenoexcept |
Like std::vector::empty().
This read operation is lock-free.
Definition at line 705 of file cow_darray.hpp.
|
inlinenoexcept |
Like std::vector::size().
This read operation is lock-free.
Definition at line 717 of file cow_darray.hpp.
|
inline |
Like std::vector::reserve(), increases this instance's capacity to new_capacity
.
Only creates a new storage and invalidates iterators if new_capacity
is greater than the current jau::darray::capacity().
This write operation uses a mutex lock and is blocking this instances' write operations only.
Definition at line 734 of file cow_darray.hpp.
|
inlinenoexcept |
Like std::vector::clear(), but ending with zero capacity.
This write operation uses a mutex lock and is blocking this instances' write operations.
Definition at line 752 of file cow_darray.hpp.
|
inlinenoexcept |
Like std::vector::swap().
This write operation uses a mutex lock and is blocking both cow_darray instance's write operations.
Definition at line 768 of file cow_darray.hpp.
|
inlinenoexcept |
Like std::vector::pop_back().
This write operation uses a mutex lock and is blocking this instances' write operations only.
Definition at line 788 of file cow_darray.hpp.
|
inline |
Like std::vector::push_back(), copy.
This write operation uses a mutex lock and is blocking this instances' write operations only.
x | the value to be added at the tail. |
Definition at line 811 of file cow_darray.hpp.
|
inline |
Like std::vector::push_back(), move.
This write operation uses a mutex lock and is blocking this instances' write operations only.
Definition at line 836 of file cow_darray.hpp.
|
inline |
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.
args | arguments to forward to the constructor of the element |
Definition at line 866 of file cow_darray.hpp.
|
inline |
Like std::vector::push_back(), but appends the whole value_type range [first, last).
This write operation uses a mutex lock and is blocking this instances' write operations only.
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 896 of file cow_darray.hpp.
|
inline |
Like push_back(), but for more multiple const r-value to copy.
This write operation uses a mutex lock and is blocking this instances' write operations only.
Args |
args | r-value references to copy into this storage |
Definition at line 926 of file cow_darray.hpp.
|
inline |
Like push_back(), but for more multiple r-value references to move.
This write operation uses a mutex lock and is blocking this instances' write operations only.
Args |
args | r-value references to move into this storage |
Definition at line 960 of file cow_darray.hpp.
|
inline |
Like std::vector::push_back(), but only if the newly added element does not yet exist.
This write operation uses a mutex lock and is blocking this instances' write operations only.
Examples
static jau::cow_darray<Thing>::equal_comparator thingEqComparator = [](const Thing &a, const Thing &b) -> bool { return a == b; }; ... jau::cow_darray<Thing> list; bool added = list.push_back_unique(new_element, thingEqComparator); ... cow_darray<std::shared_ptr<Thing>> listOfRefs; bool added = listOfRefs.push_back_unique(new_element, [](const std::shared_ptr<Thing> &a, const std::shared_ptr<Thing> &b) -> bool { return *a == *b; });
x | the value to be added at the tail, if not existing yet. |
comparator | the equal comparator to return true if both given elements are equal |
Definition at line 1016 of file cow_darray.hpp.
|
inline |
Erase either the first matching element or all matching elements.
This write operation uses a mutex lock and is blocking this instances' write operations only.
Examples
cow_darray<Thing> list; int count = list.erase_matching(element, true, [](const Thing &a, const Thing &b) -> bool { return a == b; }); ... static jau::cow_darray<Thing>::equal_comparator thingRefEqComparator = [](const std::shared_ptr<Thing> &a, const std::shared_ptr<Thing> &b) -> bool { return *a == *b; }; ... cow_darray<std::shared_ptr<Thing>> listOfRefs; int count = listOfRefs.erase_matching(element, false, thingRefEqComparator);
x | the value to be added at the tail, if not existing yet. |
all_matching | if true, erase all matching elements, otherwise only the first matching element. |
comparator | the equal comparator to return true if both given elements are equal |
Definition at line 1054 of file cow_darray.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
staticconstexpr |
Default growth factor using the golden ratio 1.618.
Definition at line 130 of file cow_darray.hpp.
|
staticconstexpr |
Definition at line 132 of file cow_darray.hpp.
|
staticconstexpr |
Definition at line 133 of file cow_darray.hpp.
|
staticconstexpr |
Definition at line 134 of file cow_darray.hpp.