Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
OhashCommon< HashTbl, Key >::Iterator Class Reference

Bidirectional iterator for traversing hash table entries. More...

#include <hashDry.H>

Public Member Functions

void reset_first () noexcept
 Positions the iterator at the first entry.
 
void reset_last () noexcept
 Positions the iterator at the last entry.
 
void end () noexcept
 Positions the iterator at the end (past-the-last element).
 
constexpr long get_pos () const noexcept
 Returns the current logical position.
 
Key & get_curr_ne () noexcept
 Returns a reference to the current entry without checking.
 
const Key & get_curr_ne () const noexcept
 Returns a const reference to the current entry without checking.
 
Key & get_curr ()
 Returns a reference to the current entry with bounds checking.
 
const Key & get_curr () const
 Returns a const reference to the current entry with bounds checking.
 
bool has_curr () const noexcept
 Checks if the iterator is at a valid position.
 
constexpr bool is_last () const noexcept
 Checks if the iterator is at the last entry.
 
void next ()
 Advances to the next entry with bounds checking.
 
void next_ne () noexcept
 Advances to the next entry without bounds checking.
 
void prev_ne ()
 Moves to the previous entry without bounds checking.
 
void prev ()
 Moves to the previous entry with bounds checking.
 
 Iterator () noexcept=default
 Default constructor creates an "end" iterator.
 
 Iterator (const HashTbl &table) noexcept
 Constructs an iterator positioned at the first entry.
 
void del ()
 Deletes the current entry and advances to the next.
 

Private Member Functions

bool check () const noexcept
 Validates iterator state (debug only).
 
void locate_next_available_entry_ne () noexcept
 Advances to next entry without bounds checking.
 
void locate_prev_available_entry_ne ()
 Moves to previous entry without bounds checking.
 
void locate_next_available_entry ()
 Advances to next entry with bounds checking.
 
void locate_prev_available_entry ()
 Moves to previous entry with bounds checking.
 

Private Attributes

HashTbltable_ptr = nullptr
 Pointer to the hash table being iterated.
 
long curr_idx = 0
 Current bucket index.
 
long ordinal = 0
 Logical position (0-based count of visited entries).
 

Detailed Description

template<class HashTbl, typename Key>
class OhashCommon< HashTbl, Key >::Iterator

Bidirectional iterator for traversing hash table entries.

This iterator provides sequential access to all BUSY (occupied) buckets in the hash table. Iteration order is based on internal bucket positions and is not related to key ordering.

Supported Operations:
Example:
for (auto it = table.get_it(); it.has_curr(); it.next())
std::cout << it.get_curr() << "\n";
Warning
Modifying the table (except via del()) during iteration invalidates the iterator.

Definition at line 646 of file hashDry.H.

Constructor & Destructor Documentation

◆ Iterator() [1/2]

template<class HashTbl , typename Key >
OhashCommon< HashTbl, Key >::Iterator::Iterator ( )
defaultnoexcept

Default constructor creates an "end" iterator.

◆ Iterator() [2/2]

template<class HashTbl , typename Key >
OhashCommon< HashTbl, Key >::Iterator::Iterator ( const HashTbl table)
inlinenoexcept

Constructs an iterator positioned at the first entry.

Parameters
tableThe hash table to iterate over.

Definition at line 859 of file hashDry.H.

References OhashCommon< HashTbl, Key >::Iterator::reset_first().

Member Function Documentation

◆ check()

◆ del()

template<class HashTbl , typename Key >
void OhashCommon< HashTbl, Key >::Iterator::del ( )
inline

Deletes the current entry and advances to the next.

Removes the current entry from the table. After deletion, the iterator is positioned at the next entry (if any).

Exceptions
std::overflow_errorIf not at a valid position.
Warning
After del(), the logical positions of subsequent entries change.

Definition at line 875 of file hashDry.H.

References ah_overflow_error_if, OhashCommon< HashTbl, Key >::Iterator::curr_idx, OhashCommon< HashTbl, Key >::Iterator::has_curr(), Aleph::maps(), and OhashCommon< HashTbl, Key >::Iterator::table_ptr.

◆ end()

template<class HashTbl , typename Key >
void OhashCommon< HashTbl, Key >::Iterator::end ( )
inlinenoexcept

Positions the iterator at the end (past-the-last element).

After calling this, has_curr() will return false.

Definition at line 759 of file hashDry.H.

References put_itor_at_the_end().

◆ get_curr() [1/2]

template<class HashTbl , typename Key >
Key & OhashCommon< HashTbl, Key >::Iterator::get_curr ( )
inline

Returns a reference to the current entry with bounds checking.

Returns
Reference to the current key.
Exceptions
std::overflow_errorIf iterator is past the end.
std::underflow_errorIf iterator is before the beginning.

Definition at line 793 of file hashDry.H.

References ah_overflow_error_if, ah_underflow_error_if, OhashCommon< HashTbl, Key >::Iterator::check(), OhashCommon< HashTbl, Key >::Iterator::get_curr_ne(), Aleph::maps(), OhashCommon< HashTbl, Key >::Iterator::ordinal, and OhashCommon< HashTbl, Key >::Iterator::table_ptr.

Referenced by OhashCommon< HashTbl, Key >::Iterator::get_curr().

◆ get_curr() [2/2]

template<class HashTbl , typename Key >
const Key & OhashCommon< HashTbl, Key >::Iterator::get_curr ( ) const
inline

Returns a const reference to the current entry with bounds checking.

Returns
Const reference to the current key.
Exceptions
std::overflow_errorIf iterator is past the end.
std::underflow_errorIf iterator is before the beginning.

Definition at line 811 of file hashDry.H.

References OhashCommon< HashTbl, Key >::Iterator::get_curr().

◆ get_curr_ne() [1/2]

template<class HashTbl , typename Key >
const Key & OhashCommon< HashTbl, Key >::Iterator::get_curr_ne ( ) const
inlinenoexcept

Returns a const reference to the current entry without checking.

Returns
Const reference to the current key.
Precondition
has_curr() must be true.

Definition at line 783 of file hashDry.H.

References OhashCommon< HashTbl, Key >::Iterator::get_curr_ne().

◆ get_curr_ne() [2/2]

template<class HashTbl , typename Key >
Key & OhashCommon< HashTbl, Key >::Iterator::get_curr_ne ( )
inlinenoexcept

Returns a reference to the current entry without checking.

Returns
Reference to the current key.
Precondition
has_curr() must be true.

Definition at line 773 of file hashDry.H.

References OhashCommon< HashTbl, Key >::Iterator::curr_idx, Aleph::maps(), and OhashCommon< HashTbl, Key >::Iterator::table_ptr.

Referenced by OhashCommon< HashTbl, Key >::Iterator::get_curr(), and OhashCommon< HashTbl, Key >::Iterator::get_curr_ne().

◆ get_pos()

template<class HashTbl , typename Key >
constexpr long OhashCommon< HashTbl, Key >::Iterator::get_pos ( ) const
inlineconstexprnoexcept

Returns the current logical position.

Returns
The 0-based ordinal position of the current entry.

Definition at line 767 of file hashDry.H.

References OhashCommon< HashTbl, Key >::Iterator::ordinal.

◆ has_curr()

template<class HashTbl , typename Key >
bool OhashCommon< HashTbl, Key >::Iterator::has_curr ( ) const
inlinenoexcept

Checks if the iterator is at a valid position.

Returns
true if pointing to a valid entry, false otherwise.

Definition at line 819 of file hashDry.H.

References Aleph::maps(), OhashCommon< HashTbl, Key >::Iterator::ordinal, Aleph::HTList::size(), and OhashCommon< HashTbl, Key >::Iterator::table_ptr.

Referenced by OhashCommon< HashTbl, Key >::Iterator::del().

◆ is_last()

template<class HashTbl , typename Key >
constexpr bool OhashCommon< HashTbl, Key >::Iterator::is_last ( ) const
inlineconstexprnoexcept

Checks if the iterator is at the last entry.

Returns
true if at the last entry, false otherwise.

Definition at line 830 of file hashDry.H.

References OhashCommon< HashTbl, Key >::Iterator::ordinal, Aleph::HTList::size(), and OhashCommon< HashTbl, Key >::Iterator::table_ptr.

◆ locate_next_available_entry()

template<class HashTbl , typename Key >
void OhashCommon< HashTbl, Key >::Iterator::locate_next_available_entry ( )
inlineprivate

Advances to next entry with bounds checking.

Exceptions
std::overflow_errorIf already at end.

Definition at line 689 of file hashDry.H.

References ah_overflow_error_if, OhashCommon< HashTbl, Key >::Iterator::locate_next_available_entry_ne(), OhashCommon< HashTbl, Key >::Iterator::ordinal, and OhashCommon< HashTbl, Key >::Iterator::table_ptr.

Referenced by OhashCommon< HashTbl, Key >::Iterator::next().

◆ locate_next_available_entry_ne()

template<class HashTbl , typename Key >
void OhashCommon< HashTbl, Key >::Iterator::locate_next_available_entry_ne ( )
inlineprivatenoexcept

◆ locate_prev_available_entry()

template<class HashTbl , typename Key >
void OhashCommon< HashTbl, Key >::Iterator::locate_prev_available_entry ( )
inlineprivate

Moves to previous entry with bounds checking.

Exceptions
std::underflow_errorIf already at beginning.

Definition at line 699 of file hashDry.H.

References ah_underflow_error_if, OhashCommon< HashTbl, Key >::Iterator::locate_prev_available_entry_ne(), and OhashCommon< HashTbl, Key >::Iterator::ordinal.

Referenced by OhashCommon< HashTbl, Key >::Iterator::prev().

◆ locate_prev_available_entry_ne()

template<class HashTbl , typename Key >
void OhashCommon< HashTbl, Key >::Iterator::locate_prev_available_entry_ne ( )
inlineprivate

◆ next()

template<class HashTbl , typename Key >
void OhashCommon< HashTbl, Key >::Iterator::next ( )
inline

Advances to the next entry with bounds checking.

Exceptions
std::overflow_errorIf already at end.

Definition at line 835 of file hashDry.H.

References OhashCommon< HashTbl, Key >::Iterator::locate_next_available_entry().

◆ next_ne()

template<class HashTbl , typename Key >
void OhashCommon< HashTbl, Key >::Iterator::next_ne ( )
inlinenoexcept

Advances to the next entry without bounds checking.

Precondition
has_curr() must be true.

Definition at line 840 of file hashDry.H.

References OhashCommon< HashTbl, Key >::Iterator::locate_next_available_entry_ne().

◆ prev()

template<class HashTbl , typename Key >
void OhashCommon< HashTbl, Key >::Iterator::prev ( )
inline

Moves to the previous entry with bounds checking.

Exceptions
std::underflow_errorIf already at beginning.

Definition at line 850 of file hashDry.H.

References OhashCommon< HashTbl, Key >::Iterator::locate_prev_available_entry().

◆ prev_ne()

template<class HashTbl , typename Key >
void OhashCommon< HashTbl, Key >::Iterator::prev_ne ( )
inline

Moves to the previous entry without bounds checking.

Precondition
ordinal > 0.

Definition at line 845 of file hashDry.H.

References OhashCommon< HashTbl, Key >::Iterator::locate_prev_available_entry_ne().

◆ reset_first()

template<class HashTbl , typename Key >
void OhashCommon< HashTbl, Key >::Iterator::reset_first ( )
inlinenoexcept

Positions the iterator at the first entry.

Resets the iterator to point to the first BUSY bucket in the table. If the table is empty, the iterator is positioned at end().

Definition at line 713 of file hashDry.H.

References OhashCommon< HashTbl, Key >::Iterator::check(), OhashCommon< HashTbl, Key >::Iterator::curr_idx, Aleph::maps(), OhashCommon< HashTbl, Key >::Iterator::ordinal, and OhashCommon< HashTbl, Key >::Iterator::table_ptr.

Referenced by OhashCommon< HashTbl, Key >::Iterator::Iterator().

◆ reset_last()

template<class HashTbl , typename Key >
void OhashCommon< HashTbl, Key >::Iterator::reset_last ( )
inlinenoexcept

Positions the iterator at the last entry.

Resets the iterator to point to the last BUSY bucket in the table. If the table is empty, the iterator is positioned before begin().

Definition at line 737 of file hashDry.H.

References OhashCommon< HashTbl, Key >::Iterator::check(), OhashCommon< HashTbl, Key >::Iterator::curr_idx, Aleph::maps(), OhashCommon< HashTbl, Key >::Iterator::ordinal, and OhashCommon< HashTbl, Key >::Iterator::table_ptr.

Member Data Documentation

◆ curr_idx

◆ ordinal

◆ table_ptr


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