44# ifndef TPL_DYNARRAY_H
45# define TPL_DYNARRAY_H
199 template <
typename T>
243 <<
"two_raised: exponent " << n <<
" is too large";
244 return static_cast<size_t>(1) << n;
261 static void compute_sizes(
const size_t n,
size_t & d,
size_t & s,
size_t & b)
294 return std::make_tuple(d, s, b);
345 for (
size_t i = 0; i <
dir_size; ++i)
353 for (
size_t i = 0; i <
seg_size; ++i)
435 for (
size_t i = 0; i <
seg_size; ++i)
436 if (
seg[i] !=
nullptr)
451 for (
size_t i = 0; i <
dir_size; ++i)
452 if (
dir[i] !=
nullptr)
471 static size_t next2Pow(
const size_t number)
noexcept
473 return static_cast<size_t>(
ceil(
log(
static_cast<float>(number)) /
log(2.0)));
491 const size_t len)
const noexcept
513 for (
size_t i = 0; i <
seg_size; i++)
521 for (
size_t i = 0; i <
dir_size; i++)
563 if (
block ==
nullptr)
596 if (
block ==
nullptr)
636 if (
block ==
nullptr)
738 static_assert(std::is_copy_constructible_v<T>,
"No copy constructor for T");
739 static_assert(std::is_move_constructible_v<T>,
"No move constructor for T");
740 static_assert(std::is_copy_assignable_v<T>,
"No copy assign for T");
741 static_assert(std::is_move_assignable_v<T>,
"No move assign for T");
760 static_assert(std::is_default_constructible_v<T>,
"No default constructor for T");
761 static_assert(std::is_copy_constructible_v<T>,
"No copy constructor for T");
762 static_assert(std::is_move_constructible_v<T>,
"No move constructor for T");
763 static_assert(std::is_copy_assignable_v<T>,
"No copy assign for T");
764 static_assert(std::is_move_assignable_v<T>,
"No move assign for T");
785 for (
size_t i = 0; i <
src_array.current_dim; ++i)
845 std::swap(
dir, array.dir);
846 std::swap(
pow_dir, array.pow_dir);
847 std::swap(
pow_seg, array.pow_seg);
851 std::swap(
dir_size, array.dir_size);
852 std::swap(
seg_size, array.seg_size);
854 std::swap(
mask_seg, array.mask_seg);
856 std::swap(
max_dim, array.max_dim);
858 std::swap(
num_segs, array.num_segs);
864 array.default_initial_value_ptr = &array.default_initial_value;
934 if (
dir[pos_in_dir] ==
nullptr)
941 if (
dir[pos_in_dir][pos_in_seg] ==
nullptr)
957 T *
test(
const size_t i)
const noexcept
963 if (
dir[pos_in_dir] ==
nullptr)
967 if (
dir[pos_in_dir][pos_in_seg] ==
nullptr)
995 if (
dir[pos_in_dir] ==
nullptr)
1002 if (
dir[pos_in_dir][pos_in_seg] ==
nullptr)
1046 std::vector<std::pair<size_t, size_t>>
new_blocks;
1163 <<
"new dimension greater than current dimension";
1227 ref = std::move(data);
1245 ret = std::forward<T>(item);
1269 std::swap(item, this->
access(this->
size() - 1));
1282 for (
size_t i = 0, j =
current_dim - 1; i < j; ++i, --j)
1302 return (*
this)[
size() - 1];
1318 return (*
this)[
size() - 1];
1424 it.
set_pos(
static_cast<long>(pos));
1435 template <
class Operation>
1471 template <
class Operation>
1478 template <
class Operation>
1485 template <
class Operation>
1492 template <
class Operation>
1499 template <
typename T>
1502 template <
typename T>
1505 template <
typename T>
1508 template <
typename T>
1511 template <
typename T>
1513 256 * 1024 * 1024 * 1024ull;
1515 template <
typename T>
1517 (Max_Bits_Allowed - Default_Pow_Dir - Default_Pow_Seg - 1);
Variadic constructor macros for containers.
Container traversal and functional operation mixins.
Exception handling system with formatted messages for Aleph-w.
#define ah_length_error_if(C)
Throws std::length_error if condition holds.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
#define ah_bad_alloc_unless(C)
Throws std::bad_alloc if condition does NOT hold.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
DRY (Don't Repeat Yourself) utilities and macros.
#define Special_Ctors(Set_Type, Type)
Generates special constructors for containers.
Iterator traits and STL-compatible iterator wrappers.
Core header for the Aleph-w library.
Utility functions for array manipulation.
Contiguous array of bits.
Iterator on the items of array.
void reset_last() noexcept
Reset the iterator to the last item.
long get_pos() const noexcept
Return the ordinal position of current item.
void set_pos(const long pos) noexcept
void reset_first() noexcept
Reset the iterator to the first item.
void prev()
Move the current a position backward.
T & get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
bool is_last() const noexcept
void next()
Move the current a position forward.
void end() noexcept
Put the iterator in the end state.
Iterator() noexcept=default
Default constructor creates an "end" iterator.
bool has_curr() const noexcept
Return true if there is current item.
void next_ne() noexcept
Move the iterator one position forward guaranteeing no exception.
T & get_curr() const
Return the current item.
void prev_ne() noexcept
exception. Be careful.
Proxy(DynArray< T > &_array, const size_t i) noexcept
Proxy & operator=(const T &data)
bool traverse(Operation &operation)
DynArray(const DynArray< T > &array)
Copy constructor.
void allocate_dir(T ***src_dir)
void release_block(T *&block) noexcept
void allocate_block(T *&block, T *src_block)
T * test(const size_t i) const noexcept
Test if the i-th entry es writable,.
size_t get_block_size() const noexcept
Return the block size.
bool __traverse(Operation &operation)
size_t index_in_dir(const size_t i) const noexcept
size_t index_in_seg(const size_t &i) const noexcept
void adjust(const size_t dim)
Set a new dimension.
void cut(const size_t new_dim=0)
Cut the array to a new dimension; that is, it reduces the dimension of array and frees the remaining ...
DynArray & reverse()
Reverse the order of items in array.
size_t modulus_from_index_in_dir(const size_t i) const noexcept
void swap(DynArray< T > &array) noexcept
Swap in constant time array with this
size_t get_dir_size() const noexcept
Return the directory size.
void remove(T &item)
Given a valid reference to an item in the array, it removes it and decrease the dimension.
unsigned long long max_dim
static size_t compute_dim(size_t d, size_t s, size_t b) noexcept
void release_dir() noexcept
void advance_block_index(size_t block_index, size_t seg_index, const size_t len) const noexcept
T Key_Type
The type of element stored in the array.
bool traverse(Operation &&operation)
T & insert(const T &item)
T & get_last() const
Return a modifiable reference to the last item of array (as if this was a queue)
size_t seg_plus_block_pow
static size_t next2Pow(const size_t number) noexcept
Proxy operator[](const size_t i) const
void cut_ne(const size_t new_dim=0)
Iterator get_it(const size_t pos) const
T & get_first() const
Return a modifiable reference to the first item of array (as if this was a queue)
DynArray(const size_t _pow_dir, const size_t _pow_seg, const size_t _pow_block)
Construct a dynamic array given directory, segment and block sizes.
void reserve(const size_t dim)
Assure that the range between 0 and dim is allocated.
size_t get_num_blocks() const noexcept
Return the number of blocks consumed by the array.
void set_default_initial_value(const T &value) noexcept
Set the default value.
T & append(const T &data)
Copy data to the end of array, increase the dimension and return a modifiable reference to the copied...
void copy_array(const DynArray< T > &src_array)
Copy the items of src_array to this
static const size_t Default_Pow_Seg
Default two power for directory size.
T & touch(const size_t i)
Touch the entry i.
size_t size() const noexcept
Return the current dimension of array.
void release_blocks_and_segment(T **&seg) noexcept
void allocate_segment(T **&seg)
static const size_t Max_Pow_Block
T pop()
Remove the last item of array (as if this was a stack)
bool traverse(Operation &&operation) const
T & access(const size_t i) const noexcept
Fast access without checking allocation and bound_min_clock checking.
static const size_t Default_Pow_Dir
The type of element stored in the array.
T * default_initial_value_ptr
DynArray(const size_t dim=0)
Default constructor.
void fill_dir_to_null() noexcept
void set_default_initial_value(T &&value=T())
static const size_t Default_Pow_Block
Default two power for segment size.
size_t max_size() const noexcept
Return the maximum allowed dimension (or the maximum number of elements that could have the array tre...
void resize_dir(const size_t i)
void release_all_segments_and_blocks() noexcept
bool exist(const size_t i) const
Return true if the i-th entry is accessible.
size_t modulus_by_block_size(const size_t number) const noexcept
size_t divide_by_block_size(const size_t number) const noexcept
static void compute_sizes(const size_t n, size_t &d, size_t &s, size_t &b) noexcept
Given a dimension n, it proposes values for the directory, segment and block sizes.
size_t mask_seg_plus_block
bool traverse(Operation &operation) const
Traverse all the array and execute a conditioned operation must have the signature:
static const unsigned long long Max_Dim_Allowed
Maximum dimension allowed.
T & append(T &&data)
Move data to the end of array, increase the dimension and return a modifiable reference to the copied...
size_t get_seg_size() const noexcept
Return the segment size.
T & top() const
Return a modifiable reference to the last item of stack.
void allocate_segment(T **&seg, T **src_seg)
void allocate_block(T *&block)
DynArray< T > & operator=(const DynArray< T > &array)
Copy assignment.
void release_segment(T **&seg) noexcept
Iterator get_it(const size_t pos)
static std::tuple< size_t, size_t, size_t > compute_sizes(const size_t n) noexcept
Given a dimension n, it proposes values for the directory, segment and block sizes.
void ensure_not_empty(const char *context) const
size_t index_in_block(const size_t i) const noexcept
T & append()
Allocate a new entry to the end of array.
static const size_t Max_Bits_Allowed
Default two power for block size.
bool is_empty() const noexcept
Return true if the array is empty.
void fill_seg_to_null(T **seg) noexcept
void empty() noexcept
Empty the array.
DynArray(DynArray &&other) noexcept
Move constructor.
static size_t two_raised(const size_t n) noexcept
void reserve(const size_t l, const size_t r)
Allocate a range of entries.
T & operator()(const size_t i) const noexcept
Equality test for containers.
Common methods to the Aleph-w ( ) containers.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Common sequential searching methods on containers.
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_dim_function > > dim(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_log_function > > log(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_ceil_function > > ceil(const __gmp_expr< T, U > &expr)
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
void open_gap(Tarray &ptr, size_t n, size_t pos=0, size_t num_entries=1)
Open a gap in an array by shifting elements right.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Generic list of items stored in a container.
Dynamic doubly linked list implementation.