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

Iterator wrapper for C++ raw arrays. More...

#include <array_it.H>

Inheritance diagram for Aleph::Array_Iterator< T >:
[legend]

Public Types

using Item_Type = T
 The type of elements being iterated.
 

Public Member Functions

T * get_base () noexcept
 Get the base pointer of the array.
 
constexpr const T * get_base () const noexcept
 Get the base pointer of the array (const version).
 
 Array_Iterator ()=default
 Default constructor - creates an invalid iterator.
 
 Array_Iterator (T *p, const size_t sz, const size_t n)
 Construct an iterator over an array.
 
 Array_Iterator (NoExceptionCtor, T *p, const size_t sz, const size_t n)
 Construct an iterator without exception checking.
 
 Array_Iterator (T *p, const size_t sz, const size_t n, const long f, const long l)
 Construct an iterator over a circular array region.
 
 Array_Iterator (NoExceptionCtor, T *p, const size_t sz, const size_t n, const long f, const long l)
 Construct a circular iterator without exception checking.
 
 Array_Iterator (const Array_Container< T > &c)
 Construct an iterator from an Array_Container.
 
bool has_curr () const noexcept
 Check if there is a current valid item.
 
bool is_last () const noexcept
 Check if positioned at the last item.
 
constexpr long get_pos () const noexcept
 Get the current position index.
 
T & get_curr_ne () const noexcept
 Get the current item without bounds checking.
 
T & get_curr () const
 Get the current item with bounds checking.
 
void next_ne () noexcept
 Advance to the next item without bounds checking.
 
void next ()
 Advance to the next item with bounds checking.
 
void prev_ne () noexcept
 Move to the previous item without bounds checking.
 
void prev ()
 Move to the previous item with bounds checking.
 
void reset () noexcept
 Reset the iterator to the first item.
 
void reset_first () noexcept
 Reset the iterator to the first item (alias for reset()).
 
void reset_last () noexcept
 Reset the iterator to the last item.
 
void set_pos (const long new_pos) noexcept
 Move the iterator to the logical position new_pos.
 
void end () noexcept
 Put the iterator at the end (past the last item).
 

Private Attributes

T * ptr = nullptr
 
long dim = 0
 
long num_items = 0
 
long idx = 0
 
long first = 0
 
long last = 0
 
long pos = 0
 

Detailed Description

template<class T>
class Aleph::Array_Iterator< T >

Iterator wrapper for C++ raw arrays.

Provides a full iterator interface for raw C arrays, including support for circular buffers where the logical sequence wraps around the physical array boundaries.

The iterator supports:

  • Forward and backward traversal
  • Bounds checking with exception throwing (or no-exception variants)
  • Circular array regions with arbitrary first/last indices
  • Position tracking
Note
Thread-safety: Array_Iterator is a mutable value type with no shared state; it does not synchronize access to its own state (pos, idx, ...). Reading (e.g. is_last(), has_curr()) and mutating (e.g. next_ne(), reset_last(), set_pos()) the same instance concurrently from different threads without external synchronization is a data race. The usual "distinct objects, distinct threads" rule applies.
Template Parameters
TElement type.

Definition at line 84 of file array_it.H.

Member Typedef Documentation

◆ Item_Type

template<class T >
using Aleph::Array_Iterator< T >::Item_Type = T

The type of elements being iterated.

Definition at line 119 of file array_it.H.

Constructor & Destructor Documentation

◆ Array_Iterator() [1/6]

template<class T >
Aleph::Array_Iterator< T >::Array_Iterator ( )
default

Default constructor - creates an invalid iterator.

◆ Array_Iterator() [2/6]

template<class T >
Aleph::Array_Iterator< T >::Array_Iterator ( T *  p,
const size_t  sz,
const size_t  n 
)
inline

Construct an iterator over an array.

Creates an iterator for elements [0, n) in an array of size sz.

Parameters
pPointer to the array.
szPhysical size of the array.
nNumber of valid items (logical size).
Exceptions
std::invalid_argumentif p is null but sz > 0.
std::domain_errorif n > sz.

Definition at line 151 of file array_it.H.

References Aleph::blossom_maximum_cardinality_matching(), and Aleph::Array_Iterator< T >::ptr.

◆ Array_Iterator() [3/6]

template<class T >
Aleph::Array_Iterator< T >::Array_Iterator ( NoExceptionCtor  ,
T *  p,
const size_t  sz,
const size_t  n 
)
inline

Construct an iterator without exception checking.

Same as the regular constructor but performs assertions instead of throwing exceptions. Use only when you are certain the parameters are valid.

Parameters
pPointer to the array.
szPhysical size of the array.
nNumber of valid items.

Definition at line 168 of file array_it.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::Array_Iterator< T >::dim, Aleph::Array_Iterator< T >::num_items, and Aleph::Array_Iterator< T >::ptr.

◆ Array_Iterator() [4/6]

template<class T >
Aleph::Array_Iterator< T >::Array_Iterator ( T *  p,
const size_t  sz,
const size_t  n,
const long  f,
const long  l 
)
inline

Construct an iterator over a circular array region.

Creates an iterator for a circular array where the logical sequence starts at index f and ends at index l, possibly wrapping around the array boundaries.

Parameters
pPointer to the array.
szPhysical size of the array.
nNumber of valid items.
fFirst index (starting position).
lLast index (ending position).
Exceptions
std::invalid_argumentif p is null but sz > 0.
std::domain_errorif parameters are inconsistent.

Definition at line 190 of file array_it.H.

References ah_domain_error_if, Aleph::and, Aleph::blossom_maximum_cardinality_matching(), Aleph::Array_Iterator< T >::dim, Aleph::Array_Iterator< T >::first, Aleph::Array_Iterator< T >::last, Aleph::Array_Iterator< T >::num_items, and Aleph::Array_Iterator< T >::ptr.

◆ Array_Iterator() [5/6]

template<class T >
Aleph::Array_Iterator< T >::Array_Iterator ( NoExceptionCtor  ,
T *  p,
const size_t  sz,
const size_t  n,
const long  f,
const long  l 
)
inline

Construct a circular iterator without exception checking.

Parameters
pPointer to the array.
szPhysical size of the array.
nNumber of valid items.
fFirst index.
lLast index.

Definition at line 212 of file array_it.H.

References Aleph::and, Aleph::blossom_maximum_cardinality_matching(), Aleph::Array_Iterator< T >::dim, Aleph::Array_Iterator< T >::first, Aleph::Array_Iterator< T >::last, Aleph::Array_Iterator< T >::num_items, and Aleph::Array_Iterator< T >::ptr.

◆ Array_Iterator() [6/6]

template<class T >
Aleph::Array_Iterator< T >::Array_Iterator ( const Array_Container< T > &  c)
inlineexplicit

Construct an iterator from an Array_Container.

Parameters
cContainer to iterate over.

Definition at line 224 of file array_it.H.

Member Function Documentation

◆ end()

template<class T >
void Aleph::Array_Iterator< T >::end ( )
inlinenoexcept

Put the iterator at the end (past the last item).

The end state is defined as the logical position num_items, so that get_pos() distances remain consistent for random-access adapters even when the container is empty (begin and end are both position 0).

Definition at line 363 of file array_it.H.

References Aleph::Array_Iterator< T >::num_items, and Aleph::Array_Iterator< T >::set_pos().

◆ get_base() [1/2]

template<class T >
constexpr const T * Aleph::Array_Iterator< T >::get_base ( ) const
inlineconstexprnoexcept

Get the base pointer of the array (const version).

Returns
Const pointer to the underlying array.

Definition at line 132 of file array_it.H.

References Aleph::Array_Iterator< T >::ptr.

◆ get_base() [2/2]

template<class T >
T * Aleph::Array_Iterator< T >::get_base ( )
inlinenoexcept

Get the base pointer of the array.

Returns
Pointer to the underlying array.

Definition at line 124 of file array_it.H.

References Aleph::Array_Iterator< T >::ptr.

◆ get_curr()

template<class T >
T & Aleph::Array_Iterator< T >::get_curr ( ) const
inline

Get the current item with bounds checking.

Returns
Reference to the current item.
Exceptions
std::underflow_errorif positioned before the first item.
std::overflow_errorif positioned past the last item.

Definition at line 268 of file array_it.H.

References ah_overflow_error_if, ah_underflow_error_if, Aleph::Array_Iterator< T >::idx, Aleph::Array_Iterator< T >::num_items, Aleph::Array_Iterator< T >::pos, and Aleph::Array_Iterator< T >::ptr.

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

◆ get_curr_ne()

template<class T >
T & Aleph::Array_Iterator< T >::get_curr_ne ( ) const
inlinenoexcept

Get the current item without bounds checking.

Returns
Reference to the current item.
Warning
Does not check bounds - use only when you know the iterator is valid.

Definition at line 258 of file array_it.H.

References Aleph::Array_Iterator< T >::idx, and Aleph::Array_Iterator< T >::ptr.

◆ get_pos()

template<class T >
constexpr long Aleph::Array_Iterator< T >::get_pos ( ) const
inlineconstexprnoexcept

Get the current position index.

Returns
Logical position (0 to num_items-1).

Definition at line 249 of file array_it.H.

References Aleph::Array_Iterator< T >::pos.

◆ has_curr()

template<class T >
bool Aleph::Array_Iterator< T >::has_curr ( ) const
inlinenoexcept

Check if there is a current valid item.

Returns
true if positioned at a valid item, false otherwise.

Definition at line 231 of file array_it.H.

References Aleph::and, Aleph::Array_Iterator< T >::num_items, and Aleph::Array_Iterator< T >::pos.

Referenced by Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::build_combinatorial_embedding_bruteforce(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::build_combinatorial_embedding_linear_lr(), Aleph::build_level_graph(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::build_nonplanar_certificate(), Aleph::capacity_scaling_maximum_flow(), Aleph::check_baseball_elimination(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::classify_k33(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::classify_k5(), Aleph::planarity_detail::collect_certificate_nodes(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::compute_faces_from_rotation(), compute_min_cut_capacity(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::count_components(), Aleph::decompose_flow(), Aleph::design_survey(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::fails_component_euler_bound(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::fill_certificate_paths(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::fill_embedding_result(), Aleph::hlpp_maximum_flow(), Aleph::Array_Iterator< T >::is_last(), Aleph::karp_minimum_mean_cycle(), Aleph::karp_minimum_mean_cycle_value(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::make_edge_witness(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::orient_dfs(), Aleph::planar_dual_metadata(), Aleph::planar_geometric_drawing(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::run_lr_planarity_test(), Aleph::segment_image(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::simple_edges_are_planar(), Aleph::MCF_LP_Solver< Net >::solve(), Aleph::solve_assignment(), Aleph::solve_circulation(), Aleph::solve_project_selection(), Aleph::ssp_shortest_path(), TEST(), TEST(), TEST(), TEST(), TEST(), Aleph::planarity_detail::LR_Planarity_Checker< GT, SA >::test_dfs(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), Aleph::validate_nonplanar_certificate(), and verify_flow_conservation().

◆ is_last()

template<class T >
bool Aleph::Array_Iterator< T >::is_last ( ) const
inlinenoexcept

Check if positioned at the last item.

Returns
true only if there is a current item and it is the last one; false for empty or singular iterators.
Note
Complexity: O(1).

Definition at line 241 of file array_it.H.

References Aleph::and, Aleph::Array_Iterator< T >::has_curr(), Aleph::Array_Iterator< T >::num_items, and Aleph::Array_Iterator< T >::pos.

Referenced by TEST().

◆ next()

template<class T >
void Aleph::Array_Iterator< T >::next ( )
inline

Advance to the next item with bounds checking.

Exceptions
std::overflow_errorif already at or past the end.

Definition at line 290 of file array_it.H.

References ah_overflow_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::Array_Iterator< T >::next_ne(), Aleph::Array_Iterator< T >::num_items, and Aleph::Array_Iterator< T >::pos.

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

◆ next_ne()

template<class T >
void Aleph::Array_Iterator< T >::next_ne ( )
inlinenoexcept

Advance to the next item without bounds checking.

Warning
Does not check bounds.

Definition at line 280 of file array_it.H.

References Aleph::Array_Iterator< T >::dim, Aleph::Array_Iterator< T >::idx, and Aleph::Array_Iterator< T >::pos.

Referenced by Aleph::Array_Iterator< T >::next().

◆ prev()

template<class T >
void Aleph::Array_Iterator< T >::prev ( )
inline

Move to the previous item with bounds checking.

Exceptions
std::underflow_errorif already at or before the beginning.

Definition at line 310 of file array_it.H.

References ah_underflow_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::Array_Iterator< T >::num_items, Aleph::Array_Iterator< T >::pos, and Aleph::Array_Iterator< T >::prev_ne().

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

◆ prev_ne()

template<class T >
void Aleph::Array_Iterator< T >::prev_ne ( )
inlinenoexcept

Move to the previous item without bounds checking.

Warning
Does not check bounds.

Definition at line 300 of file array_it.H.

References Aleph::Array_Iterator< T >::dim, Aleph::Array_Iterator< T >::idx, and Aleph::Array_Iterator< T >::pos.

Referenced by Aleph::Array_Iterator< T >::prev().

◆ reset()

template<class T >
void Aleph::Array_Iterator< T >::reset ( )
inlinenoexcept

Reset the iterator to the first item.

Definition at line 317 of file array_it.H.

References Aleph::Array_Iterator< T >::first, Aleph::Array_Iterator< T >::idx, and Aleph::Array_Iterator< T >::pos.

Referenced by Aleph::Array_Iterator< T >::reset_first(), TEST(), TEST(), and TEST_F().

◆ reset_first()

template<class T >
void Aleph::Array_Iterator< T >::reset_first ( )
inlinenoexcept

Reset the iterator to the first item (alias for reset()).

Definition at line 324 of file array_it.H.

References Aleph::Array_Iterator< T >::reset().

Referenced by TEST_F().

◆ reset_last()

template<class T >
void Aleph::Array_Iterator< T >::reset_last ( )
inlinenoexcept

◆ set_pos()

template<class T >
void Aleph::Array_Iterator< T >::set_pos ( const long  new_pos)
inlinenoexcept

Move the iterator to the logical position new_pos.

Sets the logical position and recomputes the physical (possibly circular) index as idx = (first + new_pos) % dim. This mapping is consistent with the wraparound performed by next_ne()/prev_ne() and with the end state produced by end() (pos == num_items), enabling O(1) random-access positioning.

Parameters
[in]new_posLogical position in [0, num_items], where num_items denotes the end state.
Note
Complexity: O(1).
Warning
No bounds checking: new_pos outside [0, num_items] yields an iterator with no current item.

Definition at line 350 of file array_it.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::Array_Iterator< T >::dim, Aleph::Array_Iterator< T >::first, Aleph::Array_Iterator< T >::idx, and Aleph::Array_Iterator< T >::pos.

Referenced by Aleph::Array_Iterator< T >::end().

Member Data Documentation

◆ dim

◆ first

◆ idx

◆ last

◆ num_items

◆ pos

◆ ptr


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