|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Simple, scalable and fast dynamic array. More...
#include <tpl_memArray.H>
Inherited by Aleph::ArrayQueue< int > [protected], Aleph::ArrayQueue< Aleph::DynList< int > > [protected], and Aleph::ArrayQueue< T > [protected].
Classes | |
| struct | Iterator |
| Simple iterator on elements of array. More... | |
Public Types | |
| using | Item_Type = T |
| using | Const_Iterator = Aleph::Const_Iterator< Iterator > |
| Read-only iterator: the iterator of a constant container. | |
Public Member Functions | |
| T * | get_ptr () noexcept |
| Return the current base of array. | |
| const T * | get_ptr () const noexcept |
See get_ptr(). | |
| const size_t & | get_dim () const noexcept |
| Return the current dimension of array. | |
| constexpr size_t | capacity () const noexcept |
| The type of element of array. | |
| size_t | size () const noexcept |
| Return the number of elements. | |
| bool | is_empty () const noexcept |
Return true is the array is empty. | |
| MemArray (size_t _dim=Min_Dim) | |
Construct an array con capacity equal or greater than _dim. | |
| ~MemArray () | |
| void | swap (MemArray &a) noexcept |
Swap in constant time this with a | |
| MemArray (const MemArray &a) | |
Construct a copy of a, with its capacity. | |
| MemArray (MemArray &&a) noexcept | |
| Transfer storage without allocation. | |
| MemArray & | operator= (const MemArray &a) |
Assign by copy a to this | |
| MemArray & | operator= (MemArray &&a) noexcept |
Assign by moving a to this | |
| void | empty () noexcept |
| Empties the container. | |
| void | clear () noexcept |
| Alias for empty(). | |
| void | empty_and_release () |
| Clear the array and reduce allocated storage to Min_Dim. | |
| T & | put (const T &item) |
Put a copy of item at the end of the sequence. | |
| T & | put (T &&item) |
Move item to the end of the sequence. | |
| T & | push (const T &item) |
Push a copy of item at the beginning of the sequence. | |
| T & | push (T &&item) |
Move item to the beginning of the sequence. | |
| T & | top () |
| const T & | top () const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const. | |
| T | remove_first () |
| Remove the first item. Gap is closed. | |
| T | pop () |
| pop() the most recently pushed item | |
| T & | append (const T &item) |
See put(const T & item). | |
| T & | append (T &&item) |
See put(T && item). | |
| T & | insert (const T &item) |
See push(const T & item). | |
| T & | insert (T &&item) |
See push(T && item). | |
| void | putn (const size_t more) |
Reserve more additional logical slots in the array. | |
| MemArray & | append (const MemArray &a) |
| void | reserve (const size_t cap) |
Reserves cap cells into the array. | |
| T | get (const size_t i=1) |
Remove i elements from the end. | |
| T | get_ne (const size_t i=1) noexcept |
| T | remove_last () |
See get(). | |
| T & | last () |
| Return a modifiable reference to the last element. | |
| const T & | last () const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const. | |
| T & | first () |
| Return a modifiable reference to the first element. | |
| const T & | first () const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const. | |
| T & | get_first () |
See first. | |
| const T & | get_first () const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const. | |
| T & | get_last () |
See last. | |
| const T & | get_last () const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const. | |
| MemArray & | reverse () |
| Reverse the order of items in array. | |
| T & | access (const size_t i) noexcept |
| Return a modifiable reference to the ith element. | |
| const T & | access (const size_t i) const noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const. | |
| T & | operator[] (const size_t i) |
| Return a reference to the ith element. | |
| const T & | operator[] (const size_t i) const |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const. | |
| T & | operator() (const size_t i) noexcept |
Unlike access(), which also reaches the reserved slots beyond the logical size (a build with AddressSanitizer and ALEPH_ANNOTATE_CONTAINERS reports that), debug builds assert that i is a live item (i < n). | |
| const T & | operator() (const size_t i) const noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const. | |
| template<class Operation > requires Aleph::PredicateWith<Operation &, T &> | |
| bool | traverse (Operation &operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >) |
Traverse all the elements from index 0 to n - 1 and execute operation on each on them. | |
| template<class Operation > requires Aleph::PredicateWith<Operation &, const T &> | |
| bool | traverse (Operation &operation) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >) |
| Traverse a constant array; each element is handed out as a constant reference. | |
| template<class Operation > requires Aleph::PredicateWith<Operation &, const T &> | |
| bool | traverse (Operation &&operation) const noexcept(Aleph::NothrowPredicateWith< Operation &, const T & >) |
See traverse(Operation & operation) const. | |
| template<class Operation > requires Aleph::PredicateWith<Operation &, T &> | |
| bool | traverse (Operation &&operation) noexcept(Aleph::NothrowPredicateWith< Operation &, T & >) |
See traverse(Operation & operation). | |
| bool | is_valid () const noexcept |
Public Attributes | |
| size_t | contract_threshold |
| Number of items at or below which contract() halves the capacity. | |
Static Public Attributes | |
| static constexpr size_t | Min_Dim = 4 |
Protected Member Functions | |
| void | annotate (const size_t old_n, const size_t new_n) const noexcept |
| Tell AddressSanitizer that the live items, previously the prefix [0, old_n), are now [0, new_n): accesses to the slots in [new_n, dim) are then reported as container-overflow. | |
| void | disable_annotations () noexcept |
| Make the whole buffer accessible and stop annotating it. | |
| void | allocate () |
| Allocate memory for the current dimension. | |
| void | reallocate (const size_t cap, const size_t first=0) |
| Relocate the logical sequence into a new buffer. | |
| bool | expand (const size_t first=0) |
| Grow a full array, including an empty moved-from array. | |
| template<class U > | |
| T & | relocate_and_insert (const size_t pos, U &&item, const size_t first) |
| Grow a full array and insert one item into the new buffer. | |
| template<class U > | |
| T & | grow_and_insert (const size_t pos, U &&item, const size_t first=0) |
| Grow a full array and insert one item: relocate_and_insert(). | |
| bool | contract (const size_t first=0) |
Test if n is lesser than contract_threshold and eventually contract the array half long and copies its content. | |
| void | init_dim (size_t d) |
Initialize the dimension of the array to d or to the next two power if d is not a two power. | |
Static Protected Member Functions | |
| static size_t | next_power_of_two (const size_t requested) |
Protected Attributes | |
| T * | ptr = nullptr |
| size_t | dim = Min_Dim |
| size_t | n = 0 |
Static Protected Attributes | |
| static constexpr bool | copied_as_bytes |
Whether memcpy() copies an item as its assignments do: T is trivially copyable, its copy and move assignments are trivial, and it is not volatile, whose pointers memcpy() does not take. | |
Private Member Functions | |
| template<class U > | |
| T & | put_item (U &&item) |
| Shared body of both put() overloads. | |
| template<class U > | |
| T & | push_item (U &&item) |
| Shared body of both push() overloads. | |
| void | open_gap (size_t pos=0, size_t num_entries=1) |
| void | close_gap (size_t pos, size_t num_entries=1) |
Simple, scalable and fast dynamic array.
MemArray implements a totally sequential dynamic array. That is, conditioned to memory availability, the array is stored in a contiguous chunk of memory. So, the access is direct and with exactly the same cost of accessing a normal array.
The array allows inserting and removing elements. These operations are conceived by the ends. The number of stored elements is called n.
The allocation technique obeys to "buddy system"; that is, the exact dimension of array always is an exact two power.
When the array is full, a new chunk twice as long is allocated and the current entries are moved (by move semantic if available).
When the number of entries descends to a contract_threshold the array is half long contracted.
Definition at line 156 of file tpl_memArray.H.
| using Aleph::MemArray< T >::Const_Iterator = Aleph::Const_Iterator<Iterator> |
Read-only iterator: the iterator of a constant container.
Definition at line 1054 of file tpl_memArray.H.
| using Aleph::MemArray< T >::Item_Type = T |
Definition at line 421 of file tpl_memArray.H.
|
inline |
Construct an array con capacity equal or greater than _dim.
| [in] | _dim | proposed dimension of array which could be adjusted to the next two power greater than _dim |
| bad_alloc | if there is not enough memory. |
| overflow_error | if that power of two, or its bytes, do not fit in a size_t. |
Definition at line 449 of file tpl_memArray.H.
References Aleph::MemArray< T >::allocate(), and Aleph::MemArray< T >::init_dim().
|
inline |
Definition at line 457 of file tpl_memArray.H.
References Aleph::MemArray< T >::annotate(), Aleph::MemArray< T >::dim, Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
|
inline |
Construct a copy of a, with its capacity.
| [in] | a | the array to copy. |
| std::bad_alloc | or an exception from T. |
memcpy() copies T as its assignments do (copied_as_bytes), the items are copied with it from 5 of them on: item by item, the compilers do not see that the two arrays do not overlap. Definition at line 487 of file tpl_memArray.H.
References Aleph::MemArray< T >::copied_as_bytes, Aleph::MemArray< T >::n, Aleph::MemArray< T >::ptr, and Aleph::MemArray< T >::putn().
|
inlinenoexcept |
Transfer storage without allocation.
| [in,out] | a | Source; left empty with zero capacity and reusable. |
| Nothing. |
Definition at line 507 of file tpl_memArray.H.
References Aleph::MemArray< T >::swap().
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const.
Definition at line 924 of file tpl_memArray.H.
References Aleph::MemArray< T >::ptr.
|
inlinenoexcept |
Return a modifiable reference to the ith element.
No bound_statics check is performed
Definition at line 916 of file tpl_memArray.H.
References Aleph::MemArray< T >::ptr.
Referenced by Aleph::ArrayQueue< T >::ArrayQueue(), Aleph::ArrayQueue< T >::complete_put(), Aleph::ArrayQueue< T >::front(), Aleph::ArrayQueue< T >::front(), Aleph::ArrayQueue< T >::get(), Aleph::ArrayQueue< T >::getn(), Aleph::ArrayQueue< T >::operator()(), Aleph::ArrayQueue< T >::operator()(), Aleph::ArrayQueue< T >::put_item(), Aleph::ArrayQueue< T >::rear_item(), Aleph::ArrayQueue< T >::rear_item(), TEST(), Aleph::ArrayQueue< T >::traverse(), and Aleph::ArrayQueue< T >::traverse().
|
inlineprotected |
Allocate memory for the current dimension.
Definition at line 250 of file tpl_memArray.H.
References ah_overflow_error_if, Aleph::MemArray< T >::annotate(), Aleph::MemArray< T >::contract_threshold, Aleph::MemArray< T >::dim, Aleph::is_power_of_2(), Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
Referenced by Aleph::MemArray< T >::MemArray().
|
inlineprotectednoexcept |
Tell AddressSanitizer that the live items, previously the prefix [0, old_n), are now [0, new_n): accesses to the slots in [new_n, dim) are then reported as container-overflow.
The whole buffer must be accessible again before it is deleted. No-op unless the annotations are in effect (ALEPH_ANNOTATE_CONTAINERS with AddressSanitizer).
| [in] | old_n | previous end of the accessible prefix |
| [in] | new_n | new end of the accessible prefix |
Definition at line 214 of file tpl_memArray.H.
References Aleph::and, Aleph::MemArray< T >::dim, and Aleph::MemArray< T >::ptr.
Referenced by Aleph::MemArray< T >::~MemArray(), Aleph::MemArray< T >::allocate(), Aleph::MemArray< T >::close_gap(), Aleph::MemArray< T >::disable_annotations(), Aleph::MemArray< T >::empty(), Aleph::MemArray< T >::get(), Aleph::MemArray< T >::get_ne(), Aleph::MemArray< T >::put_item(), and Aleph::MemArray< T >::putn().
Definition at line 783 of file tpl_memArray.H.
References Aleph::MemArray< T >::n, Aleph::MemArray< T >::ptr, Aleph::MemArray< T >::putn(), and Aleph::MemArray< T >::size().
|
inline |
See put(const T & item).
Definition at line 723 of file tpl_memArray.H.
References Aleph::MemArray< T >::put().
Referenced by MemArray_with_30_items::MemArray_with_30_items(), TEST(), and TEST().
|
inline |
See put(T && item).
Definition at line 730 of file tpl_memArray.H.
References Aleph::MemArray< T >::put().
|
inlineconstexprnoexcept |
The type of element of array.
Return the capacity of array (its dimension)
Definition at line 424 of file tpl_memArray.H.
References Aleph::MemArray< T >::dim.
Referenced by Aleph::FlatMap< Key, T, Compare >::capacity(), Aleph::FlatSet< Key, Compare >::capacity(), Aleph::FlatMap< Key, T, Compare >::grow_array(), Aleph::FlatSet< Key, Compare >::grow_to(), Aleph::FlatSet< Key, Compare >::insert_at(), Aleph::FlatMap< Key, T, Compare >::insert_at(), print(), print(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST_F().
|
inlinenoexcept |
Alias for empty().
| none |
Definition at line 554 of file tpl_memArray.H.
References Aleph::MemArray< T >::empty().
Referenced by Aleph::FlatSet< Key, Compare >::clear().
|
inlineprivate |
Definition at line 650 of file tpl_memArray.H.
References ah_underflow_error_if, Aleph::MemArray< T >::annotate(), Aleph::close_gap(), Aleph::MemArray< T >::contract(), Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
Referenced by Aleph::MemArray< T >::remove_first().
|
inlineprotected |
Test if n is lesser than contract_threshold and eventually contract the array half long and copies its content.
contract(first) first testes n with contract_threshold. If it is lesser, then a new array half as long is allocated and the n elements from first are copied.
| [in] | first | index of first element |
true if the array is reallocated Definition at line 388 of file tpl_memArray.H.
References Aleph::MemArray< T >::contract_threshold, Aleph::MemArray< T >::dim, Aleph::MemArray< T >::first(), Aleph::MemArray< T >::n, Aleph::MemArray< T >::ptr, and Aleph::MemArray< T >::reallocate().
Referenced by Aleph::MemArray< T >::close_gap(), Aleph::ArrayQueue< T >::get(), Aleph::MemArray< T >::get(), Aleph::MemArray< T >::get_ne(), Aleph::ArrayQueue< T >::getn(), and Aleph::ArrayQueue< T >::remove_last().
|
inlineprotectednoexcept |
Make the whole buffer accessible and stop annotating it.
For users that keep their items in a circular layout (ArrayQueue), where the live items are not a prefix of the buffer.
Definition at line 229 of file tpl_memArray.H.
References Aleph::MemArray< T >::annotate(), Aleph::MemArray< T >::dim, and Aleph::MemArray< T >::n.
Referenced by Aleph::ArrayQueue< T >::ArrayQueue(), Aleph::ArrayQueue< T >::ArrayQueue(), Aleph::ArrayQueue< T >::ArrayQueue(), Aleph::MemArray< T >::empty_and_release(), Aleph::MemArray< T >::reallocate(), and Aleph::MemArray< T >::relocate_and_insert().
|
inlinenoexcept |
Empties the container.
The array size is set to zero, but the allocated memory is not released.
| none |
std::vector::clear(), the items are not destroyed: the storage is an array of T built with new T[dim], so the objects stay alive, with their last values, until they are overwritten or the array is released. Use empty_and_release() or the destructor to release them. Definition at line 543 of file tpl_memArray.H.
References Aleph::MemArray< T >::annotate(), and Aleph::MemArray< T >::n.
Referenced by Aleph::MemArray< T >::clear(), Aleph::ArrayQueue< T >::empty(), Aleph::FlatMap< Key, T, Compare >::empty(), Aleph::FlatSet< Key, Compare >::empty(), and Aleph::MemArray< T >::empty_and_release().
|
inline |
Clear the array and reduce allocated storage to Min_Dim.
| std::bad_alloc | or an exception from default construction of T. |
Definition at line 564 of file tpl_memArray.H.
References Aleph::MemArray< T >::dim, Aleph::MemArray< T >::disable_annotations(), Aleph::MemArray< T >::empty(), Aleph::MemArray< T >::Min_Dim, and Aleph::MemArray< T >::swap().
Referenced by Aleph::ArrayQueue< T >::empty_and_release().
|
inlineprotected |
Grow a full array, including an empty moved-from array.
| [in] | first | Physical index of the first logical element. |
| std::bad_alloc,std::overflow_error | or an exception from T. |
Definition at line 291 of file tpl_memArray.H.
References ah_overflow_error_if, Aleph::and, Aleph::MemArray< T >::dim, Aleph::MemArray< T >::first(), Aleph::is_power_of_2(), Aleph::MemArray< T >::Min_Dim, Aleph::MemArray< T >::n, Aleph::MemArray< T >::ptr, and Aleph::MemArray< T >::reallocate().
Referenced by Aleph::ArrayQueue< T >::putn().
|
inline |
Return a modifiable reference to the first element.
Definition at line 863 of file tpl_memArray.H.
References ah_underflow_error_if, Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
Referenced by Aleph::MemArray< T >::contract(), Aleph::MemArray< T >::expand(), Aleph::MemArray< T >::get_first(), Aleph::MemArray< T >::get_first(), Aleph::MemArray< T >::grow_and_insert(), Aleph::MemArray< T >::reallocate(), and Aleph::MemArray< T >::relocate_and_insert().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const.
Definition at line 871 of file tpl_memArray.H.
References ah_underflow_error_if, Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
|
inline |
Remove i elements from the end.
Return the value of the last removed element
Definition at line 811 of file tpl_memArray.H.
References ah_underflow_error_if, Aleph::MemArray< T >::annotate(), Aleph::MemArray< T >::contract(), Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
Referenced by Aleph::FlatMap< Key, T, Compare >::drop_last(), main(), Aleph::FlatSet< Key, Compare >::remove_at(), Aleph::MemArray< T >::remove_last(), Aleph::FlatMap< Key, T, Compare >::sort_and_unique(), Aleph::FlatSet< Key, Compare >::sort_and_unique(), TEST(), and TEST().
|
inlinenoexcept |
Return the current dimension of array.
Definition at line 199 of file tpl_memArray.H.
References Aleph::MemArray< T >::dim.
|
inline |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const.
Definition at line 885 of file tpl_memArray.H.
References Aleph::MemArray< T >::first().
|
inline |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const.
Definition at line 898 of file tpl_memArray.H.
References Aleph::MemArray< T >::last().
|
inlinenoexcept |
Definition at line 826 of file tpl_memArray.H.
References Aleph::MemArray< T >::annotate(), Aleph::MemArray< T >::contract(), Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
|
inlinenoexcept |
|
inlinenoexcept |
Return the current base of array.
Definition at line 187 of file tpl_memArray.H.
References Aleph::MemArray< T >::ptr.
Referenced by Aleph::FlatMap< Key, T, Compare >::begin(), Aleph::FlatSet< Key, Compare >::begin(), Aleph::FlatMap< Key, T, Compare >::begin(), Aleph::FlatSet< Key, Compare >::data(), Aleph::FlatMap< Key, T, Compare >::end(), Aleph::FlatSet< Key, Compare >::end(), Aleph::FlatMap< Key, T, Compare >::end(), Aleph::FlatMap< Key, T, Compare >::erase(), Aleph::FlatSet< Key, Compare >::grow_to(), Aleph::FlatSet< Key, Compare >::insert_at(), Aleph::FlatMap< Key, T, Compare >::insert_at(), Aleph::FlatMap< Key, T, Compare >::keys(), Aleph::FlatMap< Key, T, Compare >::keys_data(), Aleph::FlatMap< Key, T, Compare >::make_room(), Aleph::FlatSet< Key, Compare >::make_room(), Aleph::FlatMap< Key, T, Compare >::operator==(), Aleph::FlatMap< Key, T, Compare >::relocate(), Aleph::FlatMap< Key, T, Compare >::remove_at(), Aleph::FlatSet< Key, Compare >::remove_at(), Aleph::FlatMap< Key, T, Compare >::sort_and_unique(), Aleph::FlatSet< Key, Compare >::sort_and_unique(), TEST(), TEST(), TEST_F(), Aleph::FlatMap< Key, T, Compare >::traverse(), Aleph::FlatMap< Key, T, Compare >::traverse(), and Aleph::FlatSet< Key, Compare >::traverse().
|
inlineprotected |
Grow a full array and insert one item: relocate_and_insert().
A scalar item goes as a copy. The growth takes its item by reference, and an item whose address leaves its function lives in memory: a loop that appends would store it at each step, also when nothing grows.
| [in] | pos | Logical position of the new item, at most size(). |
| [in] | item | Value to insert; it may be an element of this array. |
| [in] | first | Physical index of the first logical element. |
pos. | std::overflow_error,std::bad_alloc | or an exception from T. |
Definition at line 370 of file tpl_memArray.H.
References Aleph::MemArray< T >::first(), and Aleph::MemArray< T >::relocate_and_insert().
Referenced by Aleph::MemArray< T >::push_item(), Aleph::ArrayQueue< T >::put_item(), and Aleph::MemArray< T >::put_item().
|
inlineprotected |
Initialize the dimension of the array to d or to the next two power if d is not a two power.
If d is 0 then d is set to Min_Dim.
| [in] | d | the proposed dimension of array |
Definition at line 409 of file tpl_memArray.H.
References Aleph::MemArray< T >::dim, Aleph::is_power_of_2(), Aleph::MemArray< T >::Min_Dim, and Aleph::MemArray< T >::next_power_of_two().
Referenced by Aleph::MemArray< T >::MemArray().
|
inline |
See push(const T & item).
Definition at line 736 of file tpl_memArray.H.
References Aleph::MemArray< T >::push().
|
inline |
See push(T && item).
Definition at line 743 of file tpl_memArray.H.
References Aleph::MemArray< T >::push().
|
inlinenoexcept |
Return true is the array is empty.
Definition at line 436 of file tpl_memArray.H.
References Aleph::MemArray< T >::n.
Referenced by Aleph::FlatMap< Key, T, Compare >::is_empty(), Aleph::FlatSet< Key, Compare >::is_empty(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST_F().
|
inlinenoexcept |
Definition at line 1030 of file tpl_memArray.H.
References Aleph::MemArray< T >::ptr.
|
inline |
Return a modifiable reference to the last element.
Definition at line 848 of file tpl_memArray.H.
References ah_underflow_error_if, Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
Referenced by Aleph::MemArray< T >::get_last(), and Aleph::MemArray< T >::get_last().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const.
Definition at line 856 of file tpl_memArray.H.
References ah_underflow_error_if, Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
|
inlinestaticprotected |
Definition at line 237 of file tpl_memArray.H.
References ah_overflow_error_if.
Referenced by Aleph::MemArray< T >::init_dim(), and Aleph::MemArray< T >::reserve().
|
inlineprivate |
Definition at line 644 of file tpl_memArray.H.
References Aleph::MemArray< T >::n, Aleph::open_gap(), Aleph::MemArray< T >::ptr, and Aleph::MemArray< T >::putn().
Referenced by Aleph::MemArray< T >::push_item().
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const.
Definition at line 963 of file tpl_memArray.H.
References Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
|
inlinenoexcept |
Unlike access(), which also reaches the reserved slots beyond the logical size (a build with AddressSanitizer and ALEPH_ANNOTATE_CONTAINERS reports that), debug builds assert that i is a live item (i < n).
access(const size_t i) Definition at line 954 of file tpl_memArray.H.
References Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
Assign by copy a to this
Definition at line 513 of file tpl_memArray.H.
References Aleph::copy(), and Aleph::MemArray< T >::swap().
|
inlinenoexcept |
Assign by moving a to this
Definition at line 526 of file tpl_memArray.H.
References Aleph::MemArray< T >::swap().
|
inline |
Return a reference to the ith element.
Throws out_of_range if i is out of range
Definition at line 932 of file tpl_memArray.H.
References ah_out_of_range_error_if, Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const.
Definition at line 941 of file tpl_memArray.H.
References ah_out_of_range_error_if, Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
|
inline |
pop() the most recently pushed item
Definition at line 717 of file tpl_memArray.H.
References Aleph::MemArray< T >::remove_first().
|
inline |
Push a copy of item at the beginning of the sequence.
| [in] | item | Value to insert; it may be an element of this array, as in a.push(a(1)), even when the array must grow. |
| std::bad_alloc,std::overflow_error | or an exception from T. |
Definition at line 671 of file tpl_memArray.H.
References Aleph::MemArray< T >::push_item().
Referenced by Aleph::MemArray< T >::insert(), Aleph::MemArray< T >::insert(), TEST(), TEST(), TEST(), and TEST().
|
inline |
Move item to the beginning of the sequence.
| [in] | item | Value to insert; it may be an element of this array, as in a.push(std::move(a(1))), which leaves that element moved from. |
| std::bad_alloc,std::overflow_error | or an exception from T. |
Definition at line 685 of file tpl_memArray.H.
References Aleph::MemArray< T >::push_item().
|
inlineprivate |
Shared body of both push() overloads.
Definition at line 632 of file tpl_memArray.H.
References Aleph::MemArray< T >::dim, Aleph::MemArray< T >::grow_and_insert(), Aleph::MemArray< T >::n, Aleph::MemArray< T >::open_gap(), and Aleph::MemArray< T >::ptr.
Referenced by Aleph::MemArray< T >::push(), and Aleph::MemArray< T >::push().
|
inline |
Put a copy of item at the end of the sequence.
| [in] | item | Value to append; it may be an element of this array, as in a.put(a(0)), even when the array must grow. |
| std::bad_alloc,std::overflow_error | or an exception from T. |
Definition at line 588 of file tpl_memArray.H.
References Aleph::MemArray< T >::put_item().
Referenced by Aleph::FlatMap< Key, T, Compare >::FlatMap(), Aleph::FlatSet< Key, Compare >::FlatSet(), Aleph::MemArray< T >::append(), Aleph::MemArray< T >::append(), create_memarray(), main(), Aleph::FlatMap< Key, T, Compare >::sort_and_unique(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inline |
Move item to the end of the sequence.
| [in] | item | Value to append; it may be an element of this array, as in a.put(std::move(a(0))), which leaves that element moved from. |
| std::bad_alloc,std::overflow_error | or an exception from T. |
item is untouched if the allocation throws. Definition at line 603 of file tpl_memArray.H.
References Aleph::MemArray< T >::put_item().
|
inlineprivate |
Shared body of both put() overloads.
Definition at line 611 of file tpl_memArray.H.
References Aleph::MemArray< T >::annotate(), Aleph::MemArray< T >::dim, Aleph::MemArray< T >::grow_and_insert(), Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
Referenced by Aleph::MemArray< T >::put(), and Aleph::MemArray< T >::put().
|
inline |
Reserve more additional logical slots in the array.
putn(more) only adjusts the logical size and grows the backing storage if necessary; it does not value-initialize the new entries. Callers must assign to the returned positions before reading them.
| [in] | more | number of cells to reserve |
| bad_alloc | if there is no enough memory |
Definition at line 758 of file tpl_memArray.H.
References ah_overflow_error_if, Aleph::MemArray< T >::annotate(), Aleph::MemArray< T >::dim, Aleph::MemArray< T >::Min_Dim, Aleph::MemArray< T >::n, and Aleph::MemArray< T >::reallocate().
Referenced by Aleph::MemArray< T >::MemArray(), Aleph::MemArray< T >::append(), Aleph::FlatSet< Key, Compare >::grow_to(), Aleph::FlatMap< Key, T, Compare >::make_room(), Aleph::FlatSet< Key, Compare >::make_room(), Aleph::MemArray< T >::open_gap(), Aleph::MemArray< T >::reallocate(), Aleph::FlatMap< Key, T, Compare >::relocate(), Aleph::MemArray< T >::relocate_and_insert(), TEST(), and TEST().
|
inlineprotected |
Relocate the logical sequence into a new buffer.
| [in] | cap | Requested capacity, at least size(). |
| [in] | first | Physical index of the first logical element. |
| std::bad_alloc | or any exception from constructing/assigning T. |
Definition at line 271 of file tpl_memArray.H.
References Aleph::MemArray< T >::dim, Aleph::MemArray< T >::disable_annotations(), Aleph::MemArray< T >::first(), Aleph::MemArray< T >::n, Aleph::MemArray< T >::ptr, Aleph::MemArray< T >::putn(), and Aleph::MemArray< T >::swap().
Referenced by Aleph::MemArray< T >::contract(), Aleph::MemArray< T >::expand(), Aleph::MemArray< T >::putn(), Aleph::ArrayQueue< T >::reserve(), and Aleph::MemArray< T >::reserve().
|
inlineprotected |
Grow a full array and insert one item into the new buffer.
The item is assigned before any element leaves the current buffer, so it may be one of those elements: growth never reads freed memory and inserts the value that item had on entry.
| [in] | pos | Logical position of the new item, at most size(). |
| [in] | item | Value to insert; it may be an element of this array. |
| [in] | first | Physical index of the first logical element. |
pos. | std::overflow_error,std::bad_alloc | or an exception from T. |
item throws; a throwing move may leave some elements moved from, as in reallocate(). memcpy() copies T as its assignments do (copied_as_bytes), the items that are in a row, from the first slot, are moved with it. Definition at line 326 of file tpl_memArray.H.
References ah_overflow_error_if, Aleph::and, Aleph::MemArray< T >::copied_as_bytes, Aleph::MemArray< T >::dim, Aleph::MemArray< T >::disable_annotations(), Aleph::MemArray< T >::first(), Aleph::MemArray< T >::Min_Dim, Aleph::MemArray< T >::n, Aleph::MemArray< T >::ptr, Aleph::MemArray< T >::putn(), and Aleph::MemArray< T >::swap().
Referenced by Aleph::MemArray< T >::grow_and_insert().
|
inline |
Remove the first item. Gap is closed.
Definition at line 707 of file tpl_memArray.H.
References ah_underflow_error_if, Aleph::MemArray< T >::close_gap(), Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
Referenced by Aleph::MemArray< T >::pop().
|
inline |
|
inline |
Reserves cap cells into the array.
| [in] | cap | new dimension |
| bad_alloc | if there is no enough memory |
Definition at line 800 of file tpl_memArray.H.
References Aleph::MemArray< T >::dim, Aleph::is_power_of_2(), Aleph::MemArray< T >::next_power_of_two(), and Aleph::MemArray< T >::reallocate().
Referenced by Aleph::FlatMap< Key, T, Compare >::grow_array(), Aleph::FlatSet< Key, Compare >::grow_to(), TEST(), and TEST().
|
inline |
Reverse the order of items in array.
Definition at line 904 of file tpl_memArray.H.
References Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
|
inlinenoexcept |
Return the number of elements.
Definition at line 430 of file tpl_memArray.H.
References Aleph::MemArray< T >::n.
Referenced by Aleph::MemArray< T >::append(), Aleph::FlatSet< Key, Compare >::end(), expect_order(), Aleph::FlatSet< Key, Compare >::get_last(), Aleph::FlatSet< Key, Compare >::grow_to(), Aleph::FlatSet< Key, Compare >::insert_at(), Aleph::FlatMap< Key, T, Compare >::insert_at(), Aleph::FlatMap< Key, T, Compare >::lower_idx(), Aleph::FlatSet< Key, Compare >::lower_idx(), Aleph::FlatMap< Key, T, Compare >::make_room(), Aleph::FlatSet< Key, Compare >::make_room(), Aleph::FlatMap< Key, T, Compare >::match_at(), Aleph::FlatSet< Key, Compare >::match_at(), print(), print(), Aleph::FlatMap< Key, T, Compare >::relocate(), Aleph::FlatMap< Key, T, Compare >::remove_at(), Aleph::FlatSet< Key, Compare >::remove_at(), Aleph::FlatMap< Key, T, Compare >::size(), Aleph::FlatSet< Key, Compare >::size(), Aleph::FlatMap< Key, T, Compare >::sort_and_unique(), Aleph::FlatSet< Key, Compare >::sort_and_unique(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), Aleph::FlatSet< Key, Compare >::traverse(), Aleph::FlatMap< Key, T, Compare >::upper_idx(), and Aleph::FlatSet< Key, Compare >::upper_idx().
|
inlinenoexcept |
Swap in constant time this with a
Definition at line 468 of file tpl_memArray.H.
References Aleph::MemArray< T >::contract_threshold, Aleph::MemArray< T >::dim, Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
Referenced by Aleph::MemArray< T >::MemArray(), Aleph::MemArray< T >::empty_and_release(), Aleph::FlatSet< Key, Compare >::grow_to(), Aleph::MemArray< T >::operator=(), Aleph::MemArray< T >::operator=(), Aleph::MemArray< T >::reallocate(), Aleph::FlatMap< Key, T, Compare >::relocate(), Aleph::MemArray< T >::relocate_and_insert(), Aleph::ArrayQueue< T >::swap(), Aleph::FlatMap< Key, T, Compare >::swap(), and Aleph::FlatSet< Key, Compare >::swap().
|
inline |
Definition at line 690 of file tpl_memArray.H.
References ah_underflow_error_if, Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. A reference to const.
Definition at line 699 of file tpl_memArray.H.
References ah_underflow_error_if, Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
|
inlinenoexcept |
See traverse(Operation & operation) const.
Definition at line 1016 of file tpl_memArray.H.
|
inlinenoexcept |
See traverse(Operation & operation).
Definition at line 1025 of file tpl_memArray.H.
|
inlinenoexcept |
Traverse a constant array; each element is handed out as a constant reference.
| [in] | operation | to be performed on each element; it must accept const T &. |
true if operation was executed on all elements; false otherwise. | anything | that operation throws. |
Definition at line 1002 of file tpl_memArray.H.
References Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
|
inlinenoexcept |
Traverse all the elements from index 0 to n - 1 and execute operation on each on them.
| [in] | operation | to be performed on each element; it receives a modifiable reference. |
true if operation was executed on all elements; false otherwise. | anything | that operation throws. |
Definition at line 981 of file tpl_memArray.H.
References Aleph::MemArray< T >::n, and Aleph::MemArray< T >::ptr.
Referenced by TEST().
|
mutable |
Number of items at or below which contract() halves the capacity.
It is recomputed as a quarter of the capacity whenever the array is reallocated. Changing it only changes when the array contracts: contract() never shrinks the capacity below the number of items, so no item can be lost. ArrayQueue exports it with a using-declaration.
Definition at line 184 of file tpl_memArray.H.
Referenced by Aleph::MemArray< T >::allocate(), Aleph::MemArray< T >::contract(), and Aleph::MemArray< T >::swap().
|
staticconstexprprotected |
Whether memcpy() copies an item as its assignments do: T is trivially copyable, its copy and move assignments are trivial, and it is not volatile, whose pointers memcpy() does not take.
Definition at line 172 of file tpl_memArray.H.
Referenced by Aleph::MemArray< T >::MemArray(), and Aleph::MemArray< T >::relocate_and_insert().
|
protected |
Definition at line 163 of file tpl_memArray.H.
Referenced by Aleph::ArrayQueue< T >::ArrayQueue(), Aleph::MemArray< T >::~MemArray(), Aleph::MemArray< T >::allocate(), Aleph::MemArray< T >::annotate(), Aleph::MemArray< T >::capacity(), Aleph::MemArray< T >::contract(), Aleph::MemArray< T >::disable_annotations(), Aleph::MemArray< T >::empty_and_release(), Aleph::MemArray< T >::expand(), Aleph::ArrayQueue< T >::front(), Aleph::ArrayQueue< T >::front(), Aleph::MemArray< T >::get_dim(), Aleph::ArrayQueue< T >::increase_index(), Aleph::MemArray< T >::init_dim(), Aleph::ArrayQueue< T >::operator()(), Aleph::ArrayQueue< T >::operator()(), Aleph::MemArray< T >::push_item(), Aleph::ArrayQueue< T >::put_item(), Aleph::MemArray< T >::put_item(), Aleph::MemArray< T >::putn(), Aleph::ArrayQueue< T >::putn(), Aleph::MemArray< T >::reallocate(), Aleph::ArrayQueue< T >::rear_item(), Aleph::ArrayQueue< T >::rear_item(), Aleph::ArrayQueue< T >::recenter_indices(), Aleph::MemArray< T >::relocate_and_insert(), Aleph::ArrayQueue< T >::remove_last(), Aleph::ArrayQueue< T >::reserve(), Aleph::MemArray< T >::reserve(), and Aleph::MemArray< T >::swap().
|
staticconstexpr |
Definition at line 159 of file tpl_memArray.H.
Referenced by Aleph::MemArray< T >::empty_and_release(), Aleph::MemArray< T >::expand(), Aleph::MemArray< T >::init_dim(), Aleph::MemArray< T >::putn(), Aleph::ArrayQueue< T >::putn(), and Aleph::MemArray< T >::relocate_and_insert().
|
protected |
Definition at line 164 of file tpl_memArray.H.
Referenced by Aleph::ArrayQueue< T >::ArrayQueue(), Aleph::MemArray< T >::MemArray(), Aleph::MemArray< T >::~MemArray(), Aleph::MemArray< T >::allocate(), Aleph::MemArray< T >::append(), Aleph::MemArray< T >::close_gap(), Aleph::ArrayQueue< T >::complete_put(), Aleph::MemArray< T >::contract(), Aleph::MemArray< T >::disable_annotations(), Aleph::MemArray< T >::empty(), Aleph::MemArray< T >::expand(), Aleph::ArrayQueue< T >::first(), Aleph::MemArray< T >::first(), Aleph::ArrayQueue< T >::first(), Aleph::MemArray< T >::first(), Aleph::ArrayQueue< T >::front(), Aleph::ArrayQueue< T >::front(), Aleph::ArrayQueue< T >::get(), Aleph::MemArray< T >::get(), Aleph::MemArray< T >::get_ne(), Aleph::ArrayQueue< T >::getn(), Aleph::MemArray< T >::is_empty(), Aleph::ArrayQueue< T >::last(), Aleph::MemArray< T >::last(), Aleph::ArrayQueue< T >::last(), Aleph::MemArray< T >::last(), Aleph::MemArray< T >::open_gap(), Aleph::ArrayQueue< T >::operator()(), Aleph::MemArray< T >::operator()(), Aleph::ArrayQueue< T >::operator()(), Aleph::MemArray< T >::operator()(), Aleph::ArrayQueue< T >::operator[](), Aleph::MemArray< T >::operator[](), Aleph::ArrayQueue< T >::operator[](), Aleph::MemArray< T >::operator[](), Aleph::MemArray< T >::push_item(), Aleph::ArrayQueue< T >::put_item(), Aleph::MemArray< T >::put_item(), Aleph::MemArray< T >::putn(), Aleph::ArrayQueue< T >::putn(), Aleph::MemArray< T >::reallocate(), Aleph::ArrayQueue< T >::rear(), Aleph::ArrayQueue< T >::rear(), Aleph::ArrayQueue< T >::recenter_indices(), Aleph::MemArray< T >::relocate_and_insert(), Aleph::MemArray< T >::remove_first(), Aleph::ArrayQueue< T >::remove_last(), Aleph::ArrayQueue< T >::reverse(), Aleph::MemArray< T >::reverse(), Aleph::MemArray< T >::size(), Aleph::MemArray< T >::swap(), Aleph::MemArray< T >::top(), Aleph::MemArray< T >::top(), Aleph::ArrayQueue< T >::traverse(), Aleph::MemArray< T >::traverse(), Aleph::ArrayQueue< T >::traverse(), and Aleph::MemArray< T >::traverse().
|
protected |
Definition at line 162 of file tpl_memArray.H.
Referenced by Aleph::MemArray< T >::MemArray(), Aleph::MemArray< T >::~MemArray(), Aleph::MemArray< T >::access(), Aleph::MemArray< T >::access(), Aleph::MemArray< T >::allocate(), Aleph::MemArray< T >::annotate(), Aleph::MemArray< T >::append(), Aleph::MemArray< T >::close_gap(), Aleph::MemArray< T >::contract(), Aleph::MemArray< T >::expand(), Aleph::MemArray< T >::first(), Aleph::MemArray< T >::first(), Aleph::MemArray< T >::get(), Aleph::MemArray< T >::get_ne(), Aleph::MemArray< T >::get_ptr(), Aleph::MemArray< T >::get_ptr(), Aleph::MemArray< T >::is_valid(), Aleph::MemArray< T >::last(), Aleph::MemArray< T >::last(), Aleph::MemArray< T >::open_gap(), Aleph::MemArray< T >::operator()(), Aleph::MemArray< T >::operator()(), Aleph::MemArray< T >::operator[](), Aleph::MemArray< T >::operator[](), Aleph::MemArray< T >::push_item(), Aleph::MemArray< T >::put_item(), Aleph::MemArray< T >::reallocate(), Aleph::MemArray< T >::relocate_and_insert(), Aleph::MemArray< T >::remove_first(), Aleph::MemArray< T >::reverse(), Aleph::MemArray< T >::swap(), Aleph::MemArray< T >::top(), Aleph::MemArray< T >::top(), Aleph::MemArray< T >::traverse(), and Aleph::MemArray< T >::traverse().