Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::DynMatrix< T > Class Template Reference

Dynamic matrix with sparse storage. More...

#include <tpl_dynMat.H>

Inheritance diagram for Aleph::DynMatrix< T >:
[legend]
Collaboration diagram for Aleph::DynMatrix< T >:
[legend]

Classes

class  Iterator
 Iterator for traversing matrix elements. More...
 

Public Types

using Set_Type = DynMatrix< T >
 The container type (self-reference for generic programming).
 
using Item_Type = T
 The type of elements stored in the matrix.
 
using Key_Type = T
 Alias for Item_Type, required by functional mixins.
 

Public Member Functions

void set_default_initial_value (const T &value)
 Set the default value for unwritten entries.
 
const Tget_default_value () const noexcept
 Get the default value for unwritten entries.
 
void swap (DynMatrix &mat) noexcept
 Swap the contents of this matrix with another.
 
void set_dimension (const size_t num_rows, const size_t num_cols)
 Change the matrix dimensions.
 
void allocate ()
 Pre-allocate memory for the entire matrix.
 
 DynMatrix (const size_t num_rows, const size_t num_cols, const T &zero=T())
 Construct a matrix with specified dimensions.
 
 DynMatrix () noexcept=default
 Default constructor - creates an invalid matrix.
 
 ~DynMatrix ()
 Destructor - releases all allocated memory.
 
 DynMatrix (const DynMatrix< T > &mat)
 Copy constructor.
 
 DynMatrix (DynMatrix< T > &&mat) noexcept
 Move constructor.
 
DynMatrix< T > & operator= (const DynMatrix< T > &mat)
 Copy assignment operator.
 
DynMatrix< T > & operator= (DynMatrix< T > &&mat) noexcept
 Move assignment operator.
 
bool operator== (const DynMatrix< T > &mat) const
 Equality comparison.
 
bool operator!= (const DynMatrix< T > &mat) const
 Inequality comparison.
 
constexpr size_t rows () const noexcept
 Get the number of rows.
 
constexpr size_t cols () const noexcept
 Get the number of columns.
 
constexpr size_t size () const noexcept
 Get the total number of entries.
 
constexpr bool is_square () const noexcept
 Check if the matrix is square.
 
constexpr bool is_empty () const noexcept
 Check if the matrix is empty (uninitialized).
 
const Tread (const size_t i, const size_t j) const
 Read the entry at position (i, j).
 
const Tread_ne (const size_t i, const size_t j) const noexcept
 Read entry without bounds checking.
 
Twrite (const size_t i, const size_t j, const T &data)
 Write a value to position (i, j).
 
Twrite (const size_t i, const size_t j, T &&data)
 
Taccess (const size_t i, const size_t j)
 Direct access to an allocated entry.
 
const Taccess (const size_t i, const size_t j) const
 Direct const access to an allocated entry.
 
Toperator() (const size_t i, const size_t j)
 Subscript operator for allocated entries.
 
const Toperator() (const size_t i, const size_t j) const
 Const subscript operator for allocated entries.
 
void fill (const T &value)
 Fill all entries with a value.
 
DynMatrix< Ttranspose () const
 Create a transposed copy of the matrix.
 
Iterator get_it () const
 Get an iterator positioned at the first element.
 
template<class Operation >
bool traverse (Operation &operation) const
 Traverse all elements in row-major order.
 
template<class Operation >
bool traverse (Operation &operation)
 
template<class Operation >
bool traverse (Operation &&operation) const
 
template<class Operation >
bool traverse (Operation &&operation)
 
template<class Operation >
bool traverse_allocated (Operation &&operation)
 Traverse entries in allocated memory blocks.
 
template<class Operation >
bool traverse_allocated (Operation &&operation) const
 
- Public Member Functions inherited from LocateFunctions< DynMatrix< T >, T >
auto get_it () const
 Return a properly initialized iterator positioned at the first item on the container.
 
auto get_it (const size_t pos) const
 Return a properly initialized iterator positioned at the pos item on the container.
 
auto get_itor () const
 Alias of get_it().
 
T & nth_ne (const size_t n) noexcept
 Return the n‑th element without bounds checking.
 
const T & nth_ne (const size_t n) const noexcept
 Const overload of nth_ne(size_t).
 
T & nth (const size_t n)
 Return the n-th item of container.
 
const T & nth (const size_t n) const
 Const overload of nth(size_t).
 
T * find_ptr (Operation &operation) noexcept(operation_is_noexcept< Operation >())
 Find a pointer to an item in the container according to a searching criteria.
 
const T * find_ptr (Operation &operation) const noexcept(operation_is_noexcept< Operation >())
 Const overload of find_ptr(Operation&).
 
const T * find_ptr (Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
 Overload of find_ptr(Operation&) const that accepts rvalues.
 
T * find_ptr (Operation &&operation) noexcept(operation_is_noexcept< Operation >())
 Overload of find_ptr(Operation&) that accepts rvalues.
 
size_t find_index (Operation &operation) const noexcept(operation_is_noexcept< Operation >())
 Find the position of an item in the container according to a searching criteria.
 
size_t find_index (Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
 Overload of find_index(Operation&) that accepts rvalues.
 
std::tuple< bool, T > find_item (Operation &operation) noexcept(operation_is_noexcept< Operation >())
 Safe sequential searching of an item matching a criteria.
 
std::tuple< bool, T > find_item (Operation &operation) const noexcept(operation_is_noexcept< Operation >())
 
std::tuple< bool, T > find_item (Operation &&operation) noexcept(operation_is_noexcept< Operation >())
 
std::tuple< bool, T > find_item (Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
 
- Public Member Functions inherited from FunctionalMethods< DynMatrix< T >, T >
void emplace (Args &&... args)
 Appends a new element into the container by constructing it in-place with the given args.
 
void emplace_end (Args &&... args)
 
void emplace_ins (Args &&... args)
 Insert a new element into the container by constructing it in-place with the given args.
 
size_t ninsert (Args ... args)
 Insert n variadic items.
 
size_t nappend (Args ... args)
 Append n variadic items.
 
void for_each (Operation &operation)
 Traverse all the container and performs an operation on each element.
 
void for_each (Operation &operation) const
 Const overload of for_each(Operation&).
 
void for_each (Operation &&operation) const
 Overload of for_each(Operation&) const that accepts rvalues.
 
void for_each (Operation &&operation)
 Overload of for_each(Operation&) that accepts rvalues.
 
void each (Operation &operation)
 Alias of for_each(Operation&).
 
void each (Operation &operation) const
 Const alias of for_each(Operation&).
 
void each (Operation &&operation) const
 Const alias of for_each(Operation&) that accepts rvalues.
 
void each (Operation &&operation)
 Alias of for_each(Operation&) that accepts rvalues.
 
void each (size_t pos, const size_t slice, Operation &operation) const
 Traverse the container starting at pos taking one item every slice, performing a mutable operation on each visited element.
 
void each (const size_t pos, const size_t slice, Operation &&operation) const
 
void mutable_for_each (Operation &operation)
 
void mutable_for_each (Operation &&operation)
 
bool all (Operation &operation) const
 Check if all the elements of container satisfy a condition.
 
bool all (Operation &&operation) const
 Overload of all(Operation&) that accepts rvalues.
 
bool exists (Operation &op) const
 Test for existence in the container of an element satisfying a criteria.
 
bool exists (Operation &&op) const
 Overload of exists(Operation&) that accepts rvalues.
 
Aleph::DynList< __T > maps (Operation &op) const
 Map the elements of the container.
 
Aleph::DynList< __T > maps (Operation &&op) const
 Overload of maps(Operation&) that accepts rvalues.
 
Aleph::DynList< __Tmaps_if (Prop prop, Operation &op) const
 Conditional mapping of the elements of the container.
 
Aleph::DynList< __Tmaps_if (Prop prop, Operation &&op) const
 Overload of maps_if(Prop, Operation&) that accepts rvalues.
 
Aleph::DynList< T > to_dynlist () const
 Convert container to DynList.
 
std::vector< T > to_vector () const
 Convert container to std::vector.
 
__T foldl (const __T &init, Op &op) const
 Fold the elements of the container to a specific result.
 
__T foldl (const __T &init, Op &&op=Op()) const
 Overload of foldl(const __T&, Op&) that accepts rvalues.
 
__T fold_left (const __T &init, Op &op) const
 Alias for foldl with the same accumulator type.
 
__T fold_left (const __T &init, Op &&op=Op()) const
 Overload of fold_left(const __T&, Op&) that accepts rvalues.
 
fold (const T &init, Operation &operation) const
 Simplified version of foldl() where the folded type is the same type of elements stored in the container.
 
fold (const T &init, Operation &&operation) const
 Overload of fold(const T&, Operation&) that accepts rvalues.
 
Aleph::DynList< T > filter (Operation &operation) const
 Filter the elements of a container according to a matching criteria.
 
Aleph::DynList< T > filter (Operation &&operation) const
 Overload of filter(Operation&) that accepts rvalues.
 
Aleph::DynList< const T * > ptr_filter (Operation &operation) const
 Filter the elements of a container according to a matching criteria and return a pointer to the matched items in the container.
 
Aleph::DynList< const T * > ptr_filter (Operation &&operation) const
 Overload of ptr_filter(Operation&) that accepts rvalues.
 
Aleph::DynList< std::tuple< T, size_t > > pfilter (Operation &operation) const
 Filter the elements of a container according to a matching criteria and determine its positions respect to the traversal of container.
 
Aleph::DynList< std::tuple< T, size_t > > pfilter (Operation &&operation) const
 Overload of pfilter(Operation&) that accepts rvalues.
 
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition (Operation &op) const
 Exclusive partition of container according to a filter criteria.
 
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition (Operation &&op) const
 Overload of partition(Operation&) that accepts rvalues.
 
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition (size_t n) const
 Exclusive partition of container in the nth item.
 
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > split_half () const
 Split the container into two halves by alternating elements.
 
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition (Operation &op) const
 Exclusive partition of container according to a filter criteria.
 
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition (Operation &&op) const
 Overload of tpartition(Operation&) that accepts rvalues.
 
size_t length () const noexcept
 Count the number of elements of a container.
 
Aleph::DynList< T > rev () const
 Return a list with the elements of container in reverse order respect to its traversal order.
 
Aleph::DynList< T > take (const size_t n) const
 Return a list with the first n elements seen in the container during its traversal.
 
Aleph::DynList< T > take (size_t i, const size_t j, const size_t step=1) const
 Return a list with elements seen in the container between i and j position respect to its traversal.
 
Aleph::DynList< T > drop (const size_t n) const
 Drop the first n elements seen in the container during its traversal.
 
void mutable_drop (const size_t n)
 Drop the first n elements seen from container.
 

Private Member Functions

const Tread_array_entry (const size_t i) const noexcept
 
Twrite_array_entry (const size_t i, const T &data)
 
Twrite_array_entry (const size_t i, T &&data)
 
constexpr size_t get_index (const size_t i, const size_t j) const noexcept
 
void check_indices (const size_t i, const size_t j) const
 

Private Attributes

size_t n = 0
 Number of rows.
 
size_t m = 0
 Number of columns.
 
DynArray< T > * array_ptr = nullptr
 
T default_value = T()
 

Additional Inherited Members

Detailed Description

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

Dynamic matrix with sparse storage.

DynMatrix<T> implements a two-dimensional matrix of generic type T with dynamic, sparse storage. Only entries that are explicitly written consume memory; unwritten entries return the default "zero" value.

Features

  • Sparse storage: Only written entries consume memory
  • Dynamic dimensions: Can be resized at runtime
  • Row-major order: Elements are stored in row-major order for cache efficiency
  • Functional interface: Supports traverse, maps, filter, foldl, etc.
  • Customizable zero value: Default value for unwritten entries

Example Usage

// Create a 3x4 matrix with default value 0.0
DynMatrix<double> mat(3, 4, 0.0);
// Write some entries
mat.write(0, 0, 1.0);
mat.write(1, 2, 5.0);
// Read entries (unwritten returns 0.0)
double a = mat.read(0, 0); // 1.0
double b = mat.read(0, 1); // 0.0 (default)
// Using operator() for allocated entries
mat.allocate(); // Allocate all entries
mat(2, 3) = 7.0;
// Traverse all written entries
mat.traverse([](double& val) {
std::cout << val << " ";
return true;
});
Dynamic matrix with sparse storage.
Definition tpl_dynMat.H:120

Memory Model

The matrix uses a DynArray<T> internally, which provides:

  • O(1) access to any entry (amortized)
  • Memory allocation only for written entries
  • Efficient traversal of all written entries

Thread Safety

This class is not thread-safe. External synchronization is required for concurrent access from multiple threads.

Template Parameters
TType of elements stored in the matrix. Must be default-constructible.
See also
DynArray The underlying storage container

Definition at line 117 of file tpl_dynMat.H.

Member Typedef Documentation

◆ Item_Type

The type of elements stored in the matrix.

Definition at line 166 of file tpl_dynMat.H.

◆ Key_Type

template<typename T >
using Aleph::DynMatrix< T >::Key_Type = T

Alias for Item_Type, required by functional mixins.

Definition at line 169 of file tpl_dynMat.H.

◆ Set_Type

template<typename T >
using Aleph::DynMatrix< T >::Set_Type = DynMatrix<T>

The container type (self-reference for generic programming).

Definition at line 163 of file tpl_dynMat.H.

Constructor & Destructor Documentation

◆ DynMatrix() [1/4]

template<typename T >
Aleph::DynMatrix< T >::DynMatrix ( const size_t  num_rows,
const size_t  num_cols,
const T zero = T() 
)
inline

Construct a matrix with specified dimensions.

Creates a matrix with num_rows rows and num_cols columns. All entries are initialized to zero (default: T()).

Parameters
[in]num_rowsNumber of rows (must be > 0).
[in]num_colsNumber of columns (must be > 0).
[in]zeroDefault value for unwritten entries.
Exceptions
std::bad_allocIf memory allocation fails.
std::invalid_argumentIf num_rows or num_cols is zero.

Definition at line 266 of file tpl_dynMat.H.

References ah_invalid_argument_if, Aleph::DynMatrix< T >::m, FunctionalMethods< DynMatrix< T >, T >::maps(), Aleph::DynMatrix< T >::n, and Aleph::DynMatrix< T >::set_dimension().

◆ DynMatrix() [2/4]

template<typename T >
Aleph::DynMatrix< T >::DynMatrix ( )
defaultnoexcept

Default constructor - creates an invalid matrix.

Creates a matrix with zero dimensions. The matrix must be initialized with set_dimension() before use.

Note
This constructor is provided primarily for container compatibility. Most operations will fail on an uninitialized matrix.

◆ ~DynMatrix()

template<typename T >
Aleph::DynMatrix< T >::~DynMatrix ( )
inline

Destructor - releases all allocated memory.

Definition at line 286 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::array_ptr.

◆ DynMatrix() [3/4]

template<typename T >
Aleph::DynMatrix< T >::DynMatrix ( const DynMatrix< T > &  mat)
inline

Copy constructor.

Creates a deep copy of mat.

Parameters
[in]matThe matrix to copy.
Exceptions
std::bad_allocIf memory allocation fails.

Definition at line 299 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::m, Aleph::DynMatrix< T >::n, and Aleph::DynMatrix< T >::set_dimension().

◆ DynMatrix() [4/4]

template<typename T >
Aleph::DynMatrix< T >::DynMatrix ( DynMatrix< T > &&  mat)
inlinenoexcept

Move constructor.

Transfers ownership of resources from mat to this matrix. After this operation, mat is left in a valid but unspecified state.

Parameters
[in,out]matThe matrix to move from.

Definition at line 316 of file tpl_dynMat.H.

Member Function Documentation

◆ access() [1/2]

template<typename T >
T & Aleph::DynMatrix< T >::access ( const size_t  i,
const size_t  j 
)
inline

Direct access to an allocated entry.

Returns a reference to the entry at position (i, j). The entry must have been previously written or the matrix must have been allocated with allocate().

Time complexity: O(1).

Parameters
[in]iRow index (0-based).
[in]jColumn index (0-based).
Returns
A modifiable reference to the entry.
Warning
Behavior is undefined if the entry has not been allocated. Call allocate() first or use write() for safe access.

Definition at line 514 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::array_ptr, and Aleph::DynMatrix< T >::get_index().

Referenced by Aleph::DynMatrix< T >::operator()(), Aleph::DynMatrix< T >::operator()(), and Aleph::Floyd_All_Shortest_Paths< GT, Distance, SA >::print().

◆ access() [2/2]

template<typename T >
const T & Aleph::DynMatrix< T >::access ( const size_t  i,
const size_t  j 
) const
inline

Direct const access to an allocated entry.

Parameters
[in]iRow index.
[in]jColumn index.
Returns
A const reference to the entry.

Definition at line 525 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::array_ptr, and Aleph::DynMatrix< T >::get_index().

◆ allocate()

template<typename T >
void Aleph::DynMatrix< T >::allocate ( )
inline

Pre-allocate memory for the entire matrix.

Allocates memory for all n*m entries, allowing O(1) access via operator() without triggering additional allocations.

Exceptions
std::bad_allocIf there is not enough memory.
Note
After calling allocate(), operator() can be used safely for any valid index without checking for allocation.

Definition at line 249 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.

Referenced by Aleph::Floyd_All_Shortest_Paths< GT, Distance, SA >::Floyd_All_Shortest_Paths(), Aleph::DynMatrix< T >::fill(), TEST(), and TEST().

◆ check_indices()

◆ cols()

template<typename T >
constexpr size_t Aleph::DynMatrix< T >::cols ( ) const
inlineconstexprnoexcept

Get the number of columns.

Returns
The number of columns in the matrix.

Definition at line 419 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::m.

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ fill()

template<typename T >
void Aleph::DynMatrix< T >::fill ( const T value)
inline

Fill all entries with a value.

Sets all entries to value. This allocates memory for all entries.

Parameters
[in]valueThe value to fill with.
Exceptions
std::bad_allocIf memory allocation fails.

Definition at line 562 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::allocate(), Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.

Referenced by TEST().

◆ get_default_value()

template<typename T >
const T & Aleph::DynMatrix< T >::get_default_value ( ) const
inlinenoexcept

Get the default value for unwritten entries.

Returns
The current default value.

Definition at line 192 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::default_value.

Referenced by TEST().

◆ get_index()

◆ get_it()

template<typename T >
Iterator Aleph::DynMatrix< T >::get_it ( ) const
inline

Get an iterator positioned at the first element.

Returns
An iterator at position (0, 0).

Definition at line 687 of file tpl_dynMat.H.

◆ is_empty()

template<typename T >
constexpr bool Aleph::DynMatrix< T >::is_empty ( ) const
inlineconstexprnoexcept

Check if the matrix is empty (uninitialized).

Returns
true if dimensions are zero, false otherwise.

Definition at line 437 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.

Referenced by TEST(), TEST(), and TEST().

◆ is_square()

template<typename T >
constexpr bool Aleph::DynMatrix< T >::is_square ( ) const
inlineconstexprnoexcept

Check if the matrix is square.

Returns
true if rows() == cols(), false otherwise.

Definition at line 431 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ operator!=()

template<typename T >
bool Aleph::DynMatrix< T >::operator!= ( const DynMatrix< T > &  mat) const
inline

Inequality comparison.

Parameters
[in]matThe matrix to compare with.
Returns
true if matrices are not equal, false otherwise.

Definition at line 404 of file tpl_dynMat.H.

◆ operator()() [1/2]

template<typename T >
T & Aleph::DynMatrix< T >::operator() ( const size_t  i,
const size_t  j 
)
inline

Subscript operator for allocated entries.

Equivalent to access(i, j).

Parameters
[in]iRow index.
[in]jColumn index.
Returns
A modifiable reference to the entry.

Definition at line 538 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::access().

◆ operator()() [2/2]

template<typename T >
const T & Aleph::DynMatrix< T >::operator() ( const size_t  i,
const size_t  j 
) const
inline

Const subscript operator for allocated entries.

Parameters
[in]iRow index.
[in]jColumn index.
Returns
A const reference to the entry.

Definition at line 549 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::access().

◆ operator=() [1/2]

template<typename T >
DynMatrix< T > & Aleph::DynMatrix< T >::operator= ( const DynMatrix< T > &  mat)
inline

Copy assignment operator.

Replaces the contents of this matrix with a copy of mat.

Parameters
[in]matThe matrix to copy.
Returns
Reference to this matrix.
Exceptions
std::bad_allocIf memory allocation fails.

Definition at line 336 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::default_value, Aleph::DynMatrix< T >::m, Aleph::DynMatrix< T >::n, and Aleph::DynMatrix< T >::set_dimension().

◆ operator=() [2/2]

template<typename T >
DynMatrix< T > & Aleph::DynMatrix< T >::operator= ( DynMatrix< T > &&  mat)
inlinenoexcept

Move assignment operator.

Transfers ownership of resources from mat to this matrix.

Parameters
[in,out]matThe matrix to move from.
Returns
Reference to this matrix.

Definition at line 359 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::default_value, Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.

◆ operator==()

template<typename T >
bool Aleph::DynMatrix< T >::operator== ( const DynMatrix< T > &  mat) const
inline

Equality comparison.

Returns true if this matrix has the same dimensions as mat and all corresponding entries are equal (using T::operator==).

Parameters
[in]matThe matrix to compare with.
Returns
true if matrices are equal, false otherwise.

Definition at line 386 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::m, N, Aleph::DynMatrix< T >::n, and Aleph::DynMatrix< T >::read_array_entry().

◆ read()

template<typename T >
const T & Aleph::DynMatrix< T >::read ( const size_t  i,
const size_t  j 
) const
inline

Read the entry at position (i, j).

Returns the value at row i and column j. If the entry has not been written, returns the default value.

Time complexity: O(1) amortized.

Parameters
[in]iRow index (0-based).
[in]jColumn index (0-based).
Returns
The value at position (i, j).
Exceptions
std::out_of_rangeIf i >= rows() or j >= cols().

Definition at line 452 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::check_indices(), Aleph::DynMatrix< T >::get_index(), and Aleph::DynMatrix< T >::read_array_entry().

Referenced by main(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ read_array_entry()

◆ read_ne()

template<typename T >
const T & Aleph::DynMatrix< T >::read_ne ( const size_t  i,
const size_t  j 
) const
inlinenoexcept

Read entry without bounds checking.

Parameters
[in]iRow index.
[in]jColumn index.
Returns
The value at position (i, j).
Warning
Behavior is undefined if indices are out of bounds.

Definition at line 466 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::get_index(), and Aleph::DynMatrix< T >::read_array_entry().

◆ rows()

template<typename T >
constexpr size_t Aleph::DynMatrix< T >::rows ( ) const
inlineconstexprnoexcept

Get the number of rows.

Returns
The number of rows in the matrix.

Definition at line 413 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::n.

Referenced by Aleph::Floyd_All_Shortest_Paths< GT, Distance, SA >::print(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ set_default_initial_value()

template<typename T >
void Aleph::DynMatrix< T >::set_default_initial_value ( const T value)
inline

Set the default value for unwritten entries.

Changes the value returned for entries that have not been explicitly written. This also affects new entries created by touch().

Parameters
[in]valueThe new default value.
Note
This does not modify existing entries; it only affects reads of unwritten positions and newly allocated entries.

Definition at line 181 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::array_ptr, and Aleph::DynMatrix< T >::default_value.

Referenced by TEST().

◆ set_dimension()

template<typename T >
void Aleph::DynMatrix< T >::set_dimension ( const size_t  num_rows,
const size_t  num_cols 
)
inline

Change the matrix dimensions.

Resizes the matrix to have num_rows rows and num_cols columns. All existing data is discarded.

Parameters
[in]num_rowsThe new number of rows.
[in]num_colsThe new number of columns.
Exceptions
std::bad_allocIf memory allocation fails.
Warning
This operation discards all existing data. If you need to preserve data, copy it before resizing.

Definition at line 225 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::array_ptr, Aleph::DynArray< T >::compute_sizes(), Aleph::DynMatrix< T >::default_value, Aleph::DynMatrix< T >::m, FunctionalMethods< DynMatrix< T >, T >::maps(), N, and Aleph::DynMatrix< T >::n.

Referenced by Aleph::DynMatrix< T >::DynMatrix(), Aleph::DynMatrix< T >::DynMatrix(), and Aleph::DynMatrix< T >::operator=().

◆ size()

template<typename T >
constexpr size_t Aleph::DynMatrix< T >::size ( ) const
inlineconstexprnoexcept

Get the total number of entries.

Returns
rows() * cols()

Definition at line 425 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.

Referenced by Aleph::DynMatrix< T >::Iterator::has_curr(), TEST(), TEST(), and TEST().

◆ swap()

template<typename T >
void Aleph::DynMatrix< T >::swap ( DynMatrix< T > &  mat)
inlinenoexcept

Swap the contents of this matrix with another.

Exchanges the contents of this matrix with those of mat in constant time O(1). No elements are copied or moved individually.

Parameters
[in,out]matThe matrix to swap with.

Definition at line 204 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::default_value, Aleph::DynMatrix< T >::m, and Aleph::DynMatrix< T >::n.

◆ transpose()

template<typename T >
DynMatrix< T > Aleph::DynMatrix< T >::transpose ( ) const
inline

Create a transposed copy of the matrix.

Returns a new matrix where entry (i,j) contains this->read(j,i).

Returns
The transposed matrix.
Exceptions
std::bad_allocIf memory allocation fails.

Definition at line 577 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::default_value, Aleph::DynMatrix< T >::get_index(), Aleph::DynMatrix< T >::m, Aleph::DynMatrix< T >::n, Aleph::DynMatrix< T >::read_array_entry(), and Aleph::DynMatrix< T >::write().

Referenced by TEST().

◆ traverse() [1/4]

template<typename T >
template<class Operation >
bool Aleph::DynMatrix< T >::traverse ( Operation &&  operation)
inline

Definition at line 723 of file tpl_dynMat.H.

References FunctionalMethods< DynMatrix< T >, T >::maps().

◆ traverse() [2/4]

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

Definition at line 716 of file tpl_dynMat.H.

References FunctionalMethods< DynMatrix< T >, T >::maps().

◆ traverse() [3/4]

template<typename T >
template<class Operation >
Aleph::DynMatrix< T >::traverse ( Operation operation)
inline

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

Definition at line 709 of file tpl_dynMat.H.

References FunctionalMethods< DynMatrix< T >, T >::maps(), and Aleph::DynMatrix< T >::traverse().

◆ traverse() [4/4]

template<typename T >
template<class Operation >
bool Aleph::DynMatrix< T >::traverse ( Operation operation) const
inline

Traverse all elements in row-major order.

Executes operation on each element. The traversal stops early if operation returns false.

Template Parameters
OperationA callable with signature bool(const T&).
Parameters
[in]operationThe operation to perform.
Returns
true if all elements were visited, false if stopped early.

Definition at line 699 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::m, FunctionalMethods< DynMatrix< T >, T >::maps(), Aleph::DynMatrix< T >::n, and Aleph::DynMatrix< T >::read_array_entry().

Referenced by Aleph::DynMatrix< T >::traverse().

◆ traverse_allocated() [1/2]

template<typename T >
template<class Operation >
Aleph::DynMatrix< T >::traverse_allocated ( Operation &&  operation)
inline

Traverse entries in allocated memory blocks.

Visits all entries within allocated memory blocks. This is more efficient than traverse() when the matrix is very sparse, but note that it visits all entries in each allocated block, not just those that were explicitly written.

Template Parameters
OperationA callable with signature bool(T&).
Parameters
[in]operationThe operation to perform.
Returns
true if all entries were visited, false if stopped early.
Note
Due to the block-based allocation of DynArray, this function may visit entries that contain the default value but happen to be in the same block as a written entry.

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

Definition at line 744 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::array_ptr, Aleph::DynMatrix< T >::m, FunctionalMethods< DynMatrix< T >, T >::maps(), and Aleph::DynMatrix< T >::n.

◆ traverse_allocated() [2/2]

template<typename T >
template<class Operation >
bool Aleph::DynMatrix< T >::traverse_allocated ( Operation &&  operation) const
inline

◆ write() [1/2]

template<typename T >
Aleph::DynMatrix< T >::write ( const size_t  i,
const size_t  j,
const T data 
)
inline

Write a value to position (i, j).

Sets the value at row i and column j. Allocates memory for the entry if not already allocated.

Time complexity: O(1) amortized.

Parameters
[in]iRow index (0-based).
[in]jColumn index (0-based).
[in]dataThe value to write.
Returns
A modifiable reference to the written value.
Exceptions
std::out_of_rangeIf i >= rows() or j >= cols().
std::bad_allocIf memory allocation fails.

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

Definition at line 486 of file tpl_dynMat.H.

References Aleph::DynMatrix< T >::check_indices(), Aleph::DynMatrix< T >::get_index(), and Aleph::DynMatrix< T >::write_array_entry().

Referenced by FilledMatrix::FilledMatrix(), SquareMatrix::SquareMatrix(), main(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and Aleph::DynMatrix< T >::transpose().

◆ write() [2/2]

◆ write_array_entry() [1/2]

template<typename T >
T & Aleph::DynMatrix< T >::write_array_entry ( const size_t  i,
const T data 
)
inlineprivate

◆ write_array_entry() [2/2]

template<typename T >
T & Aleph::DynMatrix< T >::write_array_entry ( const size_t  i,
T &&  data 
)
inlineprivate

Member Data Documentation

◆ array_ptr

◆ default_value

◆ m

◆ n


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