Aleph-w  1.9
General library for algorithms and data structures
Aleph::DynArray< T > Class Template Reference

#include <tpl_dynArray.H>

+ Inheritance diagram for Aleph::DynArray< T >:
+ Collaboration diagram for Aleph::DynArray< T >:

Classes

class  Iterator
 

Public Types

using Item_Type = T
 
using Key_Type = T
 The type of element stored in the array.
 
using iterator = StlIterator< SetName >
 
using const_iterator = StlConstIterator< SetName >
 

Public Member Functions

size_t get_dir_size () const noexcept
 Return the directory size.
 
size_t get_seg_size () const noexcept
 Return the segment size.
 
size_t get_block_size () const noexcept
 Return the block size.
 
size_t size () const noexcept
 
size_t max_size () const noexcept
 
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
 
void set_default_initial_value (T &&value=T()) noexcept(noexcept(std::swap(default_initial_value, value)))
 
 DynArray (size_t _pow_dir, size_t _pow_seg, size_t _pow_block)
 
 DynArray (const size_t dim=0)
 
 Special_Ctors (DynArray, T)
 
void copy_array (const DynArray< T > &src_array)
 
 DynArray (const DynArray< T > &array)
 
DynArray< T > & operator= (const DynArray< T > &array)
 
void swap (DynArray< T > &array) noexcept
 
 DynArray (DynArray &&other) noexcept
 Move constructor.
 
DynArrayoperator= (DynArray &&other) noexcept
 Move assignment.
 
T & access (const size_t i) const noexcept
 
T & operator() (const size_t i) const noexcept
 
bool exist (const size_t i) const
 
T * test (const size_t i) const noexcept
 
T & touch (const size_t i)
 
void reserve (const size_t l, const size_t r)
 
void reserve (const size_t dim)
 
void cut_ne (const size_t new_dim=0)
 
void cut (const size_t new_dim=0)
 
void adjust (const size_t dim)
 
void empty () noexcept
 
Proxy operator[] (const size_t i) const
 
Proxy operator[] (const size_t i)
 
T & append ()
 
T & append (const T &data)
 
T & append (T &&data)
 
T & insert (const T &item)
 
T & insert (T &&item)
 
void push (const T &data)
 
T & push (T &&data)
 
void put (const T &data)
 
T & put (T &&data)
 
void remove (T &item) noexcept
 
void erase (T &item) noexcept
 
bool is_empty () const noexcept
 Return true if the array is empty.
 
DynArrayreverse ()
 Reverse the order of items in array.
 
pop ()
 Remove the last item of array (as if this was a stack)
 
T & top () const
 Return a modifiable reference to the last item of stack.
 
T & get_first () const
 
T & get_last () const
 
template<class Operation >
bool traverse (Operation &operation) const noexcept(noexcept(operation))
 
template<class Operation >
bool traverse (Operation &operation) noexcept(noexcept(operation))
 
template<class Operation >
bool traverse (Operation &&operation) const noexcept(noexcept(operation))
 
template<class Operation >
bool traverse (Operation &&operation) noexcept(noexcept(operation))
 
auto get_it () const
 
auto get_it (size_t pos) const
 
auto get_itor () const
 
T & nth_ne (const size_t n) noexcept
 
const T & nth_ne (const size_t n) const noexcept
 
T & nth (const size_t n)
 
const T & nth (const size_t n) const
 
T * find_ptr (Operation &operation) noexcept(noexcept(operation))
 
const T * find_ptr (Operation &operation) const noexcept(noexcept(operation))
 
const T * find_ptr (Operation &&operation) const noexcept(noexcept(operation))
 
T * find_ptr (Operation &&operation) noexcept(noexcept(operation))
 
size_t find_index (Operation &operation) const noexcept(noexcept(operation))
 
size_t find_index (Operation &&operation) const noexcept(noexcept(operation))
 
std::tuple< bool, T > find_item (Operation &operation) noexcept(noexcept(operation))
 
std::tuple< bool, T > find_item (Operation &operation) const noexcept(noexcept(operation))
 
std::tuple< bool, T > find_item (Operation &&operation) noexcept(noexcept(operation))
 
std::tuple< bool, T > find_item (Operation &&operation) const noexcept(noexcept(operation))
 
void emplace (Args &&... args)
 
void emplace_end (Args &&... args)
 
void emplace_ins (Args &&... args)
 
size_t ninsert (Args ... args)
 
size_t nappend (Args ... args)
 
void for_each (Operation &operation) noexcept(noexcept(operation))
 
void for_each (Operation &operation) const noexcept(noexcept(operation))
 
void for_each (Operation &&operation) const noexcept(noexcept(operation))
 
void for_each (Operation &&operation) noexcept(noexcept(operation))
 
void each (Operation &operation) noexcept(noexcept(operation))
 
void each (Operation &operation) const noexcept(noexcept(operation))
 
void each (Operation &&operation) const noexcept(noexcept(operation))
 
void each (Operation &&operation) noexcept(noexcept(operation))
 
void each (size_t pos, size_t slice, Operation &operation) const
 
void each (size_t pos, size_t slice, Operation &&operation) const
 
void mutable_for_each (Operation &operation) noexcept(noexcept(operation))
 
void mutable_for_each (Operation &&operation) noexcept(noexcept(operation))
 
bool all (Operation &operation) const noexcept(noexcept(operation))
 
bool all (Operation &&operation) const noexcept(noexcept(operation))
 
bool exists (Operation &op) const noexcept(noexcept(op))
 
bool exists (Operation &&op) const noexcept(noexcept(op))
 
DynList< __T > maps (Operation &op) const
 
DynList< __T > maps (Operation &&op) const
 
DynList< __T > maps_if (Prop prop, Operation &op) const
 
DynList< __T > maps_if (Prop prop, Operation &&op) const
 
DynList< T > to_dynlist () const
 
__T foldl (const __T &init, Op &op) const noexcept(noexcept(op))
 
__T foldl (const __T &init, Op &&op=Op()) const noexcept(noexcept(op))
 
fold (const T &init, Operation &operation) const noexcept(noexcept(operation))
 
fold (const T &init, Operation &&operation) const noexcept(noexcept(operation))
 
DynList< T > filter (Operation &operation) const
 
DynList< T > filter (Operation &&operation) const
 
DynList< const T *> ptr_filter (Operation &operation) const
 
DynList< const T *> ptr_filter (Operation &&operation) const
 
DynList< std::tuple< T, size_t > > pfilter (Operation &operation) const
 
DynList< std::tuple< T, size_t > > pfilter (Operation &&operation) const
 
std::pair< DynList< T >, DynList< T > > partition (Operation &op) const
 
std::pair< DynList< T >, DynList< T > > partition (Operation &&op) const
 
std::pair< DynList< T >, DynList< T > > partition (size_t n) const
 
std::tuple< DynList< T >, DynList< T > > tpartition (Operation &op) const
 
std::tuple< DynList< T >, DynList< T > > tpartition (Operation &&op) const
 
size_t length () const noexcept
 
DynList< T > rev () const
 
DynList< T > take (const size_t n) const
 
DynList< T > take (size_t i, size_t j, size_t step=1) const
 
DynList< T > drop (const size_t n) const
 
void mutable_drop (size_t n)
 
DynList< T > items () const
 
DynList< T > keys () const
 
bool equal_to (const DynArray< T > &r) const noexcept
 
bool operator== (const DynArray< T > &r) const noexcept
 
bool operator!= (const DynArray< T > &r) const noexcept
 Negation of are_equal()
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cbegin () noexcept
 
const_iterator cend () const noexcept
 
const_iterator cend () noexcept
 

Static Public Member Functions

static void compute_sizes (const size_t n, size_t &d, size_t &s, size_t &b) noexcept
 
static std::tuple< size_t, size_t, size_t > compute_sizes (const size_t n) noexcept
 

Static Public Attributes

static const size_t Default_Pow_Dir = 6
 The type of element stored in the array.
 
static const size_t Default_Pow_Seg = 8
 Default two power for directory size.
 
static const size_t Default_Pow_Block = 12
 Default two power for segment size.
 
static const unsigned long long Max_Dim_Allowed
 Maximum dimension allowed. More...
 

Friends

class BitArray
 

Detailed Description

template<typename T>
class Aleph::DynArray< T >

Lazy and scalable dynamic array

This class implements a very versatile dynamic array which would represent a good trade off between fast and constant access time and memory consumption. The array is lazy in the sense that the dimension grows dynamically and the required memory for a cell could be allocated at the first writing.

The data structure consists of three array types. A first array type is called block and it is a contiguous chunk of block_size data entries. if an array occupies n entries then there are n/block_size + 1 blocks allocated. The blocks are indexed by segments of seg_size blocks which in turn are indexed by a directory of dir_size segment. For accessing to entry i the following calculations are done:

  1. The directory entry corresponds to i/(seg_size*block_size).
  2. The modulus of previous operation is divided between block_size. This gives the index in the segment.
  3. Finally, the modulus of previous operation gives the index of i-th in the block.

So, there are always four operations for each access what gives a constant access time.

In order to faster perform the calculations, the directory, segment and block size are adjusted to two powers. In this way, the division and modulus can be done with shifting and masking.

Access through [] operator

For lazy writing, that is to allocate the block just when it is sure that this will be used, the operator [] is used. This operator is able to determine whether the i-th entry has been o not written. If for example a reading on a non allocated block is done, some such as:

cout << a[i] << end;

Then a default initialization value will be returned. This value corresponds to the resulting of default constructor call.

At the contrary, if the first time that a writing is done, some such as:

a[i] = value;

Then the block, and eventually the segment will be allocated.

Eventually the array could be fragmented and to consume memory some proportional to the writes done. Suppose for example that you only perform:

a[0] = value;
a[100000000] = valuey;

In this case, the registered dimension of array will be 100000000, but only two blocks will be allocated. If you only performs reads between $(0, 100000000)$ always it will be returned the default value and the majority of times neither the segment nor the block will be read, since they have not been written.

Acces through [] operator perform bound checks and it requires to test if the segment and/or block have been allocated and eventually to allocate them.

Faster access though [] operator

If you know (you are absolutely sure of) that the entry has already been written and consequentely it has already its block allocated, the you could use the operator () for direct access.

Access with () operator does not perform any check (bounds and blocks and segement existence). This way is faster but unsure.

() operator is an alias of access(i) method.

In order to assure that an range of entries is already allocated, you could use reserve(l, r) method, which test and eventually allocates the needed memory for the entries comprised in the range $[l,r]$.

Managing a dynamic array as a list

From a functional perspective, an dynamic array could be treated as a list.

Initially, the array is empty.

A new item can be inserted with append(item. This method copy (or moves) the item to the next available entry (at the end). The dimension is increased in one unit.

You can also to treat the dynamic array as stack or queue.

Setting the directory, segment and block sizes

The interface offer a default constructor which normally sets the sizes and serves for almost all situations.

However, sometimes is desirable to set oneself these parameter. The principal justification is given for situations where the memory is very limited.

Note that a memory manager could have enough memory dispersed through the total of available chunks but it could not exists an contiguous block of a given size. The more large is the block size, the higher is the probability for failing to allocate. So, there are circunstances where you could be interested in setting a small block size, so as to facilitate thge block's allocation.

Of course, these settings restrict the maximum dimension, which eventually could be compesed with a larger directory. As example, consider a directory of 1024 segments of 512 blocks of 4096 entries. This gives a total of

$1024 \times 512 \times 4096 = 2147483648$ entries.

Now suppose that you think that 4096 is too much for a block, the you could set the block to 128 and displace the difference to the diretory. This gives sizes of 32768, 512 and 128 respectively and thus to obtain the same maximum capacity.

You could think that failure probability is displaced to the directory allocation, but the directory is allocated once at construction time.

Constructor & Destructor Documentation

◆ DynArray() [1/3]

template<typename T>
Aleph::DynArray< T >::DynArray ( size_t  _pow_dir,
size_t  _pow_seg,
size_t  _pow_block 
)
inline

Construct a dynamic array given directory, segment and block sizes.

Parameters
[in]_pow_dirtwo power for directory size
[in]_pow_segtwo power for segment size
[in]_pow_blocktwo power for block size
Exceptions
bad_allocif there is no enough memory
length_errorif the given sizes exceed the maximum possible dimension
overflow_errorif it happens an arithmetic overflow with the bits operations

◆ DynArray() [2/3]

template<typename T>
Aleph::DynArray< T >::DynArray ( const size_t  dim = 0)
inline

Default constructor

Parameters
[in]diminitial dimension of array
Exceptions
bad_allocif there is no enough memory
length_errorsi dim is greater than maximum allowed
overflow_errorif it happens an arithmetic overflow with the bits operations

◆ DynArray() [3/3]

template<typename T>
Aleph::DynArray< T >::DynArray ( const DynArray< T > &  array)
inline

Copy constructor

Parameters
[in]arraysource of copy
Exceptions
bad_allocif there is no enough memory

Member Function Documentation

◆ access()

template<typename T>
T& Aleph::DynArray< T >::access ( const size_t  i) const
inlinenoexcept

Fast access without checking allocation and bound checking

The purpose of this method is to access the i-th entry in the fastest possible way. For that, no checks are done.

Parameters
[in]iindex of entry to be accessed
See also
exist
+ Here is the caller graph for this function:

◆ adjust()

template<typename T>
void Aleph::DynArray< T >::adjust ( const size_t  dim)
inline

Set a new dimension.

If dimension is greater than the current, then more memory is allocated; otherwise the remaining memory is freed. In both cases, the current dimension is adjusted.

Parameters
[in]dimnew dimension value
+ Here is the caller graph for this function:

◆ all() [1/2]

bool Aleph::FunctionalMethods< DynArray< T > , T >::all ( Operation &  operation) const
inlinenoexceptinherited

Check if all the elements of container satisfy a condition.

all(operation) checks if for each element item of container operation(item) returns true.

This method has complexity $O(n)$ in average and worst case.

Parameters
[in]operationto be used as condition
Returns
true if all the elements satisfy the criteria: false otherwise.
Exceptions
anythingthat could throw operation

◆ all() [2/2]

bool Aleph::FunctionalMethods< DynArray< T > , T >::all ( Operation &&  operation) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ append() [1/3]

template<typename T>
T& Aleph::DynArray< T >::append ( )
inline

Allocate a new entry to the end of array. Increase the dimension and return a mdoficiable reference to the last entry

+ Here is the caller graph for this function:

◆ append() [2/3]

template<typename T>
T& Aleph::DynArray< T >::append ( const T &  data)
inline

Copy data to the end of array, increase the dimension and return a modifiable reference to teh copied data

◆ append() [3/3]

template<typename T>
T& Aleph::DynArray< T >::append ( T &&  data)
inline

Move data to the end of array, increase the dimension and return a modifiable reference to teh copied data

◆ compute_sizes() [1/2]

template<typename T>
static void Aleph::DynArray< T >::compute_sizes ( const size_t  n,
size_t &  d,
size_t &  s,
size_t &  b 
)
inlinestaticnoexcept

Given a dimension n, it proposes values for the directory, segment and block sizes.

Parameters
[in]nproposed dimension
[out]ddirectory size
[out]ssegment size
[out]bblock size
+ Here is the caller graph for this function:

◆ compute_sizes() [2/2]

template<typename T>
static std::tuple<size_t, size_t, size_t> Aleph::DynArray< T >::compute_sizes ( const size_t  n)
inlinestaticnoexcept

Given a dimension n, it proposes values for the directory, segment and block sizes.

Parameters
[in]nproposed dimension
Returns
a 3-tuple with the directory, segment and block sizes

◆ copy_array()

template<typename T>
void Aleph::DynArray< T >::copy_array ( const DynArray< T > &  src_array)
inline

Copy the items of src_array to this

Parameters
[in]src_arraysource array
+ Here is the caller graph for this function:

◆ cut()

template<typename T>
void Aleph::DynArray< T >::cut ( const size_t  new_dim = 0)
inline

Cut the array to a new dimension; that is, it reduces the dimension of array and frees the remaining memory.

Parameters
[in]new_dimnew dimension value
Exceptions
domain_errorif new_dim is greater than current dim
+ Here is the caller graph for this function:

◆ drop()

DynList<T> Aleph::FunctionalMethods< DynArray< T > , T >::drop ( const size_t  n) const
inlineinherited

Drop the first n elements seen in the container during its traversal.

The complexity of this method is $O(N)$ where N always is the number of elements of container.

Returns
A DynList<T> having the remainder $N - n$ elements according to traversal order.
Exceptions
bad_allocif there is no enough memory or out_of_range if n is greater or equal than N (the number of elements in the container).

◆ each() [1/6]

void Aleph::FunctionalMethods< DynArray< T > , T >::each ( Operation &  operation)
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ each() [2/6]

void Aleph::FunctionalMethods< DynArray< T > , T >::each ( Operation &  operation) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ each() [3/6]

void Aleph::FunctionalMethods< DynArray< T > , T >::each ( Operation &&  operation) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ each() [4/6]

void Aleph::FunctionalMethods< DynArray< T > , T >::each ( Operation &&  operation)
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ each() [5/6]

void Aleph::FunctionalMethods< DynArray< T > , T >::each ( size_t  pos,
size_t  slice,
Operation &  operation 
) const
inlineinherited

Traverse all the container and performs a mutable operation on each element.

mutable_for_each(operation) traverses the container and on each element item is performed operation(item).

operation could have the following signature:

void operation(T & item)

Be very careful with the fact that this method allows to modify the elements themselves, what could badly alter the internal state of container. This would be the case for heaps, binary trees and hash tables.

Parameters
[in]<tt>operation</tt>to be done on each element.
Returns
an reference to this
Exceptions
anythingthat can throw operation

◆ each() [6/6]

void Aleph::FunctionalMethods< DynArray< T > , T >::each ( size_t  pos,
size_t  slice,
Operation &&  operation 
) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ emplace()

void Aleph::FunctionalMethods< DynArray< T > , T >::emplace ( Args &&...  args)
inlineinherited

Appends a new element into the container by constructing it in-place with the given args.

emplace(args) tries to match a constructor T(args). If this exists, then this is constructed in-place and directly forwarded to the method append() of container. If all on the container and T` is adequately done, then the object is constructed once time, successively forwarded and at its target place in the container is moved, avoiding thus unnecessary copies.

Note
The semantic of append depends of container. In general, this has some sense for lists and arrays and it means insertion at the end of sequence. On other type of container append() is equivalent to insert().
Parameters
[in]argsvariadic arguments list
Exceptions
bad_allocif there is no enough memory

◆ emplace_end()

void Aleph::FunctionalMethods< DynArray< T > , T >::emplace_end ( Args &&...  args)
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ emplace_ins()

void Aleph::FunctionalMethods< DynArray< T > , T >::emplace_ins ( Args &&...  args)
inlineinherited

Insert a new element into the container by constructing it in-place with the given args.

emplace_ins(args) tries to match a constructor T(args). If this exists, then this is constructed in-place and directly forwarded to the method insert() of container. If all on the container and T` is adequately done, then the object is constructed once time, successively forwarded and finally, at its target place in the container, is moved, avoiding thus unnecessary copies.

Note
The semantic of insert() depends of container. In general, this has some sense for lists and arrays and it means insertion at the beginning of sequence. On other type of container append() is equivalent to insert().
Parameters
[in]argsvariadic arguments list
Exceptions
bad_allocif there is no enough memory

◆ empty()

template<typename T>
void Aleph::DynArray< T >::empty ( )
inlinenoexcept

Empty the array. All the occuped memory is freed and the dimension is to set to zero

◆ equal_to()

bool Aleph::EqualToMethod< DynArray< T > >::equal_to ( const DynArray< T > &  r) const
inlinenoexceptinherited

Test if elements of this are exactly contained in another container.

This method serves for testing if two containers contain the same elements. First, the container sizes are tested for equality. If they have the same size, then the testing is done by traversing this. Each seen element is searched in the another container with the method search(). So the container r must export the search() method, which frequently is the case for containers oriented to fast retrieval.

Warning
On some container, concretely DynList, the size is computed, not retrieved. So take in account this fact.
Parameters
[in]rcontainer on which the searches will be performed.
Returns
true if the container have the same size and all the elements of this are present in r

◆ erase()

template<typename T>
void Aleph::DynArray< T >::erase ( T &  item)
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ exist()

template<typename T>
bool Aleph::DynArray< T >::exist ( const size_t  i) const
inline

Return true if the i-th entry is accessible.

By accessible is understood that eitjer the entry has been previously written or the block than would contain it is already allocated,

Parameters
[in]iindex to test
+ Here is the caller graph for this function:

◆ exists() [1/2]

bool Aleph::FunctionalMethods< DynArray< T > , T >::exists ( Operation &  op) const
inlinenoexceptinherited

Test for existence in the container of an element satisfying a criteria.

exists(op) returns true if it exists any element item in container for which op(item) return true.

This method has complexity $O(n)$ in average and worst case.

Parameters
[in]opoperation for testing existence
Returns
true if it exists an item for which op return true; false otherwise.
Exceptions
anythingthat could throw op

◆ exists() [2/2]

bool Aleph::FunctionalMethods< DynArray< T > , T >::exists ( Operation &&  op) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ filter() [1/2]

DynList<T> Aleph::FunctionalMethods< DynArray< T > , T >::filter ( Operation &  operation) const
inlineinherited

Filter the elements of a container according to a matching criteria.

This method builds a dynamic list with copies of items of container matching a criteria defined by operation, which should have the following signature:

bool operation(const T & item)

If operation return true then item matches the criteria; otherwise, operation must return false.

For example, if the container has integer, the the following code snippet would return a list containing the items greater than 100:

c.filter([] (auto item) { return item > 100; });
Parameters
[in]operationdefining the flter criteria
Returns
a DynList<T> with the matched elements.
Exceptions
anythingthat could throw operation or bad_alloc if there is no enough memory

◆ filter() [2/2]

DynList<T> Aleph::FunctionalMethods< DynArray< T > , T >::filter ( Operation &&  operation) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_index() [1/2]

size_t Aleph::LocateFunctions< DynArray< T > , T >::find_index ( Operation &  operation) const
inlinenoexceptinherited

Find the position of an item in the container according to a searching criteria.

find_index(operation) traverses the container and on each item perform operation(item). If the result of operation is true, then the traversal is stopped and the position of the current item (which mathes operation) is returned.

operation must have the following signature:

bool operation(const typename Container::Item_Type & item)
Warning
Frequent use of this method will definitively degrade the performance. Try not to use this method inside loops. In general, if you falls in this situation, the consider your design and use a faster approach.
Parameters
[in]<tt>operation</tt>to be performed on each item for matching a searching criteria.
Returns
the last seen position. If the item is not found, then the number of items is returned.

◆ find_index() [2/2]

size_t Aleph::LocateFunctions< DynArray< T > , T >::find_index ( Operation &&  operation) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_item() [1/4]

std::tuple<bool, T > Aleph::LocateFunctions< DynArray< T > , T >::find_item ( Operation &  operation)
inlinenoexceptinherited

Safe sequential searching of an item matching a criteria.

find_item(operation) traverses the container and on each item perform operation(item). If the result of operation is true, then the traversal is stopped and duple containg a copy of found item is returned.

The method is said safe because returns a copy of item.

operation must have the following signature:

bool operation(const typename Container::Item_Type & item)
Parameters
[in]<tt>operation</tt>to be used as searching criteria
Returns
a duple tuple<bool, Type>. The first field indicates if the item was found and the second contains a copy of found item. If no item is found, then the first field is false and the second is the result of default constructor on the type stored in the container.

◆ find_item() [2/4]

std::tuple<bool, T > Aleph::LocateFunctions< DynArray< T > , T >::find_item ( Operation &  operation) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_item() [3/4]

std::tuple<bool, T > Aleph::LocateFunctions< DynArray< T > , T >::find_item ( Operation &&  operation)
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_item() [4/4]

std::tuple<bool, T > Aleph::LocateFunctions< DynArray< T > , T >::find_item ( Operation &&  operation) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_ptr() [1/4]

T * Aleph::LocateFunctions< DynArray< T > , T >::find_ptr ( Operation &  operation)
inlinenoexceptinherited

Find a pointer to an item in the container according to a searching criteria.

find_ptr(operation) traverses the container and on each item perform operation(item). If the result of operation is true, then the traversal is stopped and a pointer to the current item (which mathes operation) is returned.

operation must have the following signature:

bool operation(const typename Container::Item_Type & item)
Warning
Frequent use of this method will definitively degrade the performance. Try not to use this method inside loops. In general, if you falls in thie situation, the consider your design and to use an faster approach.
Parameters
[in]<tt>operation</tt>to be performed on each item for matching a searching criteria.
Returns
a valid pointer to an item if this was found or nullptr otherwise.

◆ find_ptr() [2/4]

const T * Aleph::LocateFunctions< DynArray< T > , T >::find_ptr ( Operation &  operation) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_ptr() [3/4]

const T * Aleph::LocateFunctions< DynArray< T > , T >::find_ptr ( Operation &&  operation) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ find_ptr() [4/4]

T * Aleph::LocateFunctions< DynArray< T > , T >::find_ptr ( Operation &&  operation)
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ fold() [1/2]

T Aleph::FunctionalMethods< DynArray< T > , T >::fold ( const T &  init,
Operation &  operation 
) const
inlinenoexceptinherited

Simplified version of foldl() where the folded type is the same type of elements stored in the container.

See also
foldl(const __T & init, Op & op)

◆ fold() [2/2]

T Aleph::FunctionalMethods< DynArray< T > , T >::fold ( const T &  init,
Operation &&  operation 
) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ foldl() [1/2]

__T Aleph::FunctionalMethods< DynArray< T > , T >::foldl ( const __T &  init,
Op &  op 
) const
inlinenoexceptinherited

Fold the elements of the container to a specific result.

foldl(init, op) set an internal variable acc of type __T to init value. Then it traverses the container and on each item it performs:

acc = op(acc, op(acc, item);

So acc serves as a sort of accumulator.

op should have the following signature:

__T op(__T acc, const T & item);

Since foldl is overloaded with several operation structures, there is a certain flexibility with the parameter qualifiers. You could, for example, to declare acc and/or item by value.

The method is a template. The first template parameter __T specifies the final folded type. By default, this type is T (the type of elements stored in the container). The second parameter is the operation. If the folded type is the same than T (the type of item stored), the you can simply write a foldl(). For example, if the container stores integer, in order to determine the maximum of all elements you could do:

c.foldl(std::numeric_limits<int>::min(), [] (int acc, int item)
  {
    return std::min(acc, item);
  });

When the folded type is different than T, then you must specify the folded type as template parameter. For example, if you want to compute the sum of inversed elements, the you could do it as follows:

c.template foldl<double>(0, [] (double acc, int item)
  {
    return acu + 1.0/item;
  });
Parameters
[in]initinitial value of folded value (or accumulator).
[in]opoperation to be performed on each item and used for folding.
Returns
the final folded computation.
Exceptions
anythingthat could throw op

◆ foldl() [2/2]

__T Aleph::FunctionalMethods< DynArray< T > , T >::foldl ( const __T &  init,
Op &&  op = Op() 
) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ for_each() [1/4]

void Aleph::FunctionalMethods< DynArray< T > , T >::for_each ( Operation &  operation)
inlinenoexceptinherited

Traverse all the container and performs an operation on each element.

for_each(operation) traverses the container and on each element item is performed operation(item).

operation must have the following signature:

void operation(const T & item)

Overloadings of this method allow that that the signature can be lightly different; for example, remove the reference or the const.

Parameters
[in]<tt>operation</tt>to be done on each element.
Returns
an reference to this
Exceptions
anythingthat can throw operation

◆ for_each() [2/4]

void Aleph::FunctionalMethods< DynArray< T > , T >::for_each ( Operation &  operation) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ for_each() [3/4]

void Aleph::FunctionalMethods< DynArray< T > , T >::for_each ( Operation &&  operation) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ for_each() [4/4]

void Aleph::FunctionalMethods< DynArray< T > , T >::for_each ( Operation &&  operation)
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get_first()

template<typename T>
T& Aleph::DynArray< T >::get_first ( ) const
inline

Return a modifiable reference to the first item of array (as if this was a queue)

◆ get_it() [1/2]

auto Aleph::LocateFunctions< DynArray< T > , T >::get_it ( ) const
inlineinherited

Return an properly initialized iterator positioned at the first item on the container

◆ get_it() [2/2]

auto Aleph::LocateFunctions< DynArray< T > , T >::get_it ( size_t  pos) const
inlineinherited

Return an properly initialized iterator positioned at the pos item on the container

◆ get_itor()

auto Aleph::LocateFunctions< DynArray< T > , T >::get_itor ( ) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get_last()

template<typename T>
T& Aleph::DynArray< T >::get_last ( ) const
inline

Return a modifiable reference to the last item of array (as if this was a queue)

◆ items()

template<class Container, typename T>
DynList<T> Aleph::GenericItems< Container, T >::items ( ) const
inlineinherited

Return a list of all the elements of a container sorted by traversal order.

Returns
a DynList<T> containing all the elements of the container
Exceptions
bad_allocif there is no enough memory

◆ keys()

template<class Container, typename T>
DynList<T> Aleph::GenericItems< Container, T >::keys ( ) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

+ Here is the caller graph for this function:

◆ length()

size_t Aleph::FunctionalMethods< DynArray< T > , T >::length ( ) const
inlinenoexceptinherited

Count the number of elements of a container.

This method counts the number of elements stored in the container.

Note
Take in account that this method computes; it does not retrieve. Consequently it always takes $O(n)$. However, for many containers this number is already stored and retrievable in $O(1)$ through the methos size()
Returns
the number of elements stored in the container.

◆ maps() [1/2]

DynList<__T> Aleph::FunctionalMethods< DynArray< T > , T >::maps ( Operation &  op) const
inlineinherited

Map the elements of the container.

maps(op) produces a dynamic list resulting of mapping of each element of container item to the result of operation op(item).

maps() is a template method which receives as template parameters the type __T, which is the type of target or range of mapping, and the transforming operation. By default __T is the same type of the elements stored in the container.

operation should have the following signature:

__T operation(const T & item)

So, operation(item) performs a transformation of item towards the type __T.

If __T ==T`, which is common and by default, then you could specify a mapping without need of template specification. For example, if the container has integer values, the a mapping of item multiplied by 4 could be very simply written as follows:

c.maps([] (int item) { return 4*i; });

In contrast, if the range type is different than the domain type, then it is necessary to specify the template keyword in the method call. For example, if the range is double and you want to return the elements divided by 4, the could do as follows:

c.template maps<double>([] (int item) { return 1.0*item/4; });
Parameters
[in]opoperation to be performed in order to do the transformation on an item
Returns
a `DynList<__T> object containing the mapped items. The order of resulting list is the same than the order of visit of the iterator for the container.
Exceptions
anythingthat could throw op or bad_alloc if there is no enough memory

◆ maps() [2/2]

DynList<__T> Aleph::FunctionalMethods< DynArray< T > , T >::maps ( Operation &&  op) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ maps_if() [1/2]

DynList<__T> Aleph::FunctionalMethods< DynArray< T > , T >::maps_if ( Prop  prop,
Operation &  op 
) const
inlineinherited

Conditional mapping of the elements of the container.

maps_if(prop, op) traverses each item of container, on each item it tests the proposition prop. If this last is true, then the item is mapped through the function op(item).

Parameters
[in]opoperation to be perfomed in order to do the transformation on an item.
[in]propa lambda returning a bool which perform the logical test.
Returns
a `DynList<__T> object containing the mapped items. The order of resulting list is the same than the order of visit of the iterator for the container.
Exceptions
anythingthat could throw op or bad_alloc if there is no enough memory

◆ maps_if() [2/2]

DynList<__T> Aleph::FunctionalMethods< DynArray< T > , T >::maps_if ( Prop  prop,
Operation &&  op 
) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ max_size()

template<typename T>
size_t Aleph::DynArray< T >::max_size ( ) const
inlinenoexcept

Return the maximum allowed dimension (or the maximum number of elements that could have the array treated as a container). Be careful with the fact that this bound is not related to available memory

+ Here is the caller graph for this function:

◆ mutable_drop()

void Aleph::FunctionalMethods< DynArray< T > , T >::mutable_drop ( size_t  n)
inlineinherited

Drop the first n elements seen from container.

The complexity of this method is $O(N)$ where N always is the number of elements of container.

Exceptions
out_of_rangeif n is greater or equal than N (the number of elements in the container).

◆ mutable_for_each()

void Aleph::FunctionalMethods< DynArray< T > , T >::mutable_for_each ( Operation &&  operation)
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ nappend()

size_t Aleph::FunctionalMethods< DynArray< T > , T >::nappend ( Args ...  args)
inlineinherited

Append n variadic items

Parameters
[in]argsitems to be appended
Returns
the number of appended items

◆ ninsert()

size_t Aleph::FunctionalMethods< DynArray< T > , T >::ninsert ( Args ...  args)
inlineinherited

Insert n variadic items

Parameters
[in]argsitems to be inserted
Returns
the number of inserted items

◆ nth() [1/2]

T & Aleph::LocateFunctions< DynArray< T > , T >::nth ( const size_t  n)
inlineinherited

Return the n-th item of container.

The notion of ordinal depends of type of container. On list, probably will be the insertion order. On binary search trees will be the nth smaller item. On hash tables will be pseudo random.

Warning
Frequent use of this method will definitively degrade the performance. Try not to use this method inside loops. In general, if you falls in this situation, then consider your design and to use an faster approach.
Parameters
[in]nthe nth item to find
Returns
a valid reference to the item into the container.
Exceptions
out_of_rangeif n is greater or equal that the size of container.

◆ nth() [2/2]

const T & Aleph::LocateFunctions< DynArray< T > , T >::nth ( const size_t  n) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ nth_ne()

const T & Aleph::LocateFunctions< DynArray< T > , T >::nth_ne ( const size_t  n) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator()()

template<typename T>
T& Aleph::DynArray< T >::operator() ( const size_t  i) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ operator=()

template<typename T>
DynArray<T>& Aleph::DynArray< T >::operator= ( const DynArray< T > &  array)
inline

Copy assignment

Parameters
[in]arraysource of copy
Exceptions
bad_allocif there is no enough memory

◆ operator==()

bool Aleph::EqualToMethod< DynArray< T > >::operator== ( const DynArray< T > &  r) const
inlinenoexceptinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ partition() [1/3]

std::pair<DynList<T>, DynList<T> > Aleph::FunctionalMethods< DynArray< T > , T >::partition ( Operation &  op) const
inlineinherited

Exclusive partition of container according to a filter criteria.

partition(op) traverses the container and filters its elements according to the filter criteria defined by op. The filtered elements are copied to a first list and the not filtered ones to a second list. When all the container is traversed, a pair containing these lists is returned.

The op requirements are the same than for filter().

Parameters
[in]opoperation instrumenting the filter criteria
Returns
a std::pair<DynList<T>, DynList<T>>.firstcontains the filtered elements andsecondthe non-filtered ones. \throw anything that could throw op orbad_alloc` if there is no enough memory
See also
filter()

◆ partition() [2/3]

std::pair<DynList<T>, DynList<T> > Aleph::FunctionalMethods< DynArray< T > , T >::partition ( Operation &&  op) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ partition() [3/3]

std::pair<DynList<T>, DynList<T> > Aleph::FunctionalMethods< DynArray< T > , T >::partition ( size_t  n) const
inlineinherited

Exclusive partition of container in the nth item

partition(n) traverses the container and produces a pair of lists. The first one contains the first n elements and the second one the this->size() - n remaining elements.

Parameters
[in]nthe first n items of the first list
Exceptions
anythingthat could throw op or bad_alloc if there is no enough memory

◆ pfilter() [1/2]

DynList<std::tuple<T, size_t> > Aleph::FunctionalMethods< DynArray< T > , T >::pfilter ( Operation &  operation) const
inlineinherited

Filter the elements of a container according to a matching criteria and determine its positions respect to the traversal of container.

pfilter(operation) is very similar to filter(), but instead of building a list of filtered elements, it builds a list of pairs with form (item, pos), where item is a copy of filtered element and pos is its position respect to the traversal order. The position is relative to the container type.

The pair is defined with a tuple:

std::tuple<T, size_t>
Parameters
[in]operationthat defines the filter criteria
Returns
a DynList
Exceptions
bad_allocif there is no enough memory
See also
filter(Operation & operation)

◆ pfilter() [2/2]

DynList<std::tuple<T, size_t> > Aleph::FunctionalMethods< DynArray< T > , T >::pfilter ( Operation &&  operation) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ ptr_filter()

DynList<const T*> Aleph::FunctionalMethods< DynArray< T > , T >::ptr_filter ( Operation &  operation) const
inlineinherited

Filter the elements of a container according to a matching criteria an return pointer to the matched items in the container.

This method builds a dynamic list with stores pointers to the items of matching a criteria defined by operation, which should have the followgin signature:

bool operation(const T & item)

If operation return true then item matches the criteria; otherwise, operation must return false.

For example, if the container has integer, the the following code snippet would return a list containing the items greater than 100:

c.ptr_filter([] (auto item) { return item > 100; });
Parameters
[in]operationdefining the flter criteria
Returns
a DynList<const T*> with the pointers to the matched elements.
Exceptions
anythingthat could throw operation or bad_alloc if there is no enough memory

◆ push() [1/2]

template<typename T>
void Aleph::DynArray< T >::push ( const T &  data)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ push() [2/2]

template<typename T>
T& Aleph::DynArray< T >::push ( T &&  data)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ put() [1/2]

template<typename T>
void Aleph::DynArray< T >::put ( const T &  data)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ put() [2/2]

template<typename T>
T& Aleph::DynArray< T >::put ( T &&  data)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ remove()

template<typename T>
void Aleph::DynArray< T >::remove ( T &  item)
inlinenoexcept

Given a valid referecce to an item in the array, it removes it and decrease the dimension.

Parameters
[in]itemvalid reference to the item to remove

◆ reserve() [1/2]

template<typename T>
void Aleph::DynArray< T >::reserve ( const size_t  l,
const size_t  r 
)
inline

Allocate a range of entries.

reserve(l, r) assures that all the entries comprised between l and r are allocated. After a successfully call, any entry between l and r can be surely accessed with access().

Parameters
[in]llower index
[in]rupper index
Exceptions
bad_allocif there is no enough memory
domain_errorif l is greater than r
+ Here is the caller graph for this function:

◆ reserve() [2/2]

template<typename T>
void Aleph::DynArray< T >::reserve ( const size_t  dim)
inline

Assure that the range between 0 and dim is allocated

Parameters
[in]dimupper index
Exceptions
bad_allocif there is no enough memory

◆ rev()

DynList<T> Aleph::FunctionalMethods< DynArray< T > , T >::rev ( ) const
inlineinherited

Return a list with the elements of container in reverse order respect to its traversal order.

Returns
a DynList<T> inversely ordered accordirg to the traversal order.
Exceptions
bad_allocif there is no enough memory

◆ set_default_initial_value() [1/2]

template<typename T>
void Aleph::DynArray< T >::set_default_initial_value ( const T &  value)
inlinenoexcept

Set the default value.

The default value of a dynamic array is the value to be returned when entries not still written are accessed.

Parameters
[in]valuedefault value
+ Here is the caller graph for this function:

◆ set_default_initial_value() [2/2]

template<typename T>
void Aleph::DynArray< T >::set_default_initial_value ( T &&  value = T())
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ size()

template<typename T>
size_t Aleph::DynArray< T >::size ( ) const
inlinenoexcept

Return the current dimension of array. According to usage style, this could represent the number of items stored in the array seen as a container

+ Here is the caller graph for this function:

◆ swap()

template<typename T>
void Aleph::DynArray< T >::swap ( DynArray< T > &  array)
inlinenoexcept

Swap in constant time array with this

Parameters
[in]arrayto swap
Note
The sizes of directory, segment and block are also swapped
+ Here is the caller graph for this function:

◆ take() [1/2]

DynList<T> Aleph::FunctionalMethods< DynArray< T > , T >::take ( const size_t  n) const
inlineinherited

Return a list with the first n elements seen in the container during its traversal.

The complexity of this method is $O(n)$ where n can be less than the number of elements of container.

Returns
A DynList<T> having the first n elements according to its traversal order.
Exceptions
bad_allocif there is no enough memory or out_of_range if n is greater or equal than the number of elements in the container.

◆ take() [2/2]

DynList<T> Aleph::FunctionalMethods< DynArray< T > , T >::take ( size_t  i,
size_t  j,
size_t  step = 1 
) const
inlineinherited

Return a list with elements seen in the container between i and j position respect to its traversal.

The complexity of this method is $O(n)$ where n can be less than the number of elements of container.

Returns
A DynList<T> having the first n elements according to its traversal order.
Exceptions
bad_allocif there is no enough memory or out_of_range if n is greater or equal than the number of elements in the container.

◆ test()

template<typename T>
T* Aleph::DynArray< T >::test ( const size_t  i) const
inlinenoexcept

Test if the i-th entry es writable,

test(i) inspects if the entry i is already allocated. If affirmative, then a pointer to the entry in the array is returned. Otherwise nullptr is returned.

Parameters
[in]iindex to test.
Returns
nullptr if the entry is not allocated; a valid pointer inside the array otherwise
+ Here is the caller graph for this function:

◆ touch()

template<typename T>
T& Aleph::DynArray< T >::touch ( const size_t  i)
inline

Touch the entry i.

touch(i) testes if the block that would contain to i is allready allocated. If this is not the case, then the block, and eventually the segment, is allocated. If everything is ok, the method returns a valid pointer to the entry inside the array.

touch(i) is a concise and effective way to test and eventually to allocate memory for a new entry.

Parameters
[in]iindex to touch
Exceptions
bad_allocif there is no enough memory
See also
cut
+ Here is the caller graph for this function:

◆ tpartition() [1/2]

std::tuple<DynList<T>, DynList<T> > Aleph::FunctionalMethods< DynArray< T > , T >::tpartition ( Operation &  op) const
inlineinherited

Exclusive partition of container according to a filter criteria.

This methos has exactly the same semantic than partition(Operation & op), excepts than instead of returning a std::pair it returns a std::tuple.

Parameters
[in]opoperation instrumenting the filter criteria
Returns
a std::tuple<DynList<T>, DynList<T>>.firstcontains the filteres elements andsecondthe non-filtered ones. \throw anything that could throw op orbad_alloc` if there is no enough memory
See also
partition(Operation & op)

◆ tpartition() [2/2]

std::tuple<DynList<T>, DynList<T> > Aleph::FunctionalMethods< DynArray< T > , T >::tpartition ( Operation &&  op) const
inlineinherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ traverse() [1/4]

template<typename T>
template<class Operation >
bool Aleph::DynArray< T >::traverse ( Operation &  operation) const
inlinenoexcept

Traverse all the array and execute a conditioned operation

Operation must have the signature:

bool operation(const T & item)

If

operation()

returns false then the traversal is stopped; otherwise the the traverse move to the next item.

Parameters
[in]operation
Returns
true if all items are traversed; false otherwise
+ Here is the caller graph for this function:

◆ traverse() [2/4]

template<typename T>
template<class Operation >
bool Aleph::DynArray< T >::traverse ( Operation &  operation)
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ traverse() [3/4]

template<typename T>
template<class Operation >
bool Aleph::DynArray< T >::traverse ( Operation &&  operation) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ traverse() [4/4]

template<typename T>
template<class Operation >
bool Aleph::DynArray< T >::traverse ( Operation &&  operation)
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Member Data Documentation

◆ Max_Dim_Allowed

template<typename T>
const unsigned long long Aleph::DynArray< T >::Max_Dim_Allowed
static
Initial value:
=
256*1024*1024*1024ull

Maximum dimension allowed.


The documentation for this class was generated from the following file:

Leandro Rabindranath León