ORIGINAL
Loading...
Searching...
No Matches
original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator Class Reference

Forward iterator for hashTable. More...

#include <hashTable.h>

Inheritance diagram for original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator:
Inheritance graph
Collaboration diagram for original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator:
Collaboration graph

Public Member Functions

bool hasNext () const
 Checks if more elements are available.
 
void next () const
 Advances to the next element.
 
void operator+= (integer steps) const
 Advances iterator by steps positions.
 
couple< const K_TYPE, V_TYPE > & get ()
 Gets current key-value pair (non-const)
 
couple< const K_TYPE, V_TYPE > get () const
 Gets current key-value pair (const)
 
bool isValid () const
 Checks if iterator points to valid element.
 

Protected Member Functions

 Iterator (vector< hashNode *, rebind_alloc_pointer > *buckets=nullptr, u_integer bucket=0, hashNode *node=nullptr)
 Constructs an iterator pointing to specific position.
 
 Iterator (const Iterator &other)
 Copy constructor.
 
Iteratoroperator= (const Iterator &other)
 Copy assignment operator.
 

Static Protected Member Functions

static u_integer findNextValidBucket (vector< hashNode *, rebind_alloc_pointer > *buckets, u_integer bucket)
 Finds the next non-empty bucket.
 
static u_integer findPrevValidBucket (vector< hashNode *, rebind_alloc_pointer > *buckets, u_integer bucket)
 Finds the previous non-empty bucket.
 

Protected Attributes

vector< hashNode *, rebind_alloc_pointer > * p_buckets
 
u_integer cur_bucket
 
hashNodep_node
 

Detailed Description

template<typename K_TYPE, typename V_TYPE, typename ALLOC = allocator<K_TYPE>, typename HASH = hash<K_TYPE>>
class original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator

Forward iterator for hashTable.

Provides forward iteration over hashTable elements with:

  • Consistent traversal order (bucket by bucket, then chain order)
  • Safe invalidation detection
  • Const-correct access to elements

Iterator Characteristics:

  • Forward iteration only (throws on reverse operations)
  • Invalidates on rehash operations
  • Lightweight copy semantics
  • STL-style iteration interface
Note
Iterators remain valid unless the table is rehashed

Constructor & Destructor Documentation

◆ Iterator() [1/2]

template<typename K_TYPE, typename V_TYPE, typename ALLOC, typename HASH>
original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator::Iterator ( vector< hashNode *, rebind_alloc_pointer > * buckets = nullptr,
u_integer bucket = 0,
hashNode * node = nullptr )
explicitprotected

Constructs an iterator pointing to specific position.

Parameters
bucketsPointer to buckets vector
bucketCurrent bucket index
nodeCurrent node pointer
Note
Protected constructor for use by hashTable only

◆ Iterator() [2/2]

template<typename K_TYPE, typename V_TYPE, typename ALLOC, typename HASH>
original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator::Iterator ( const Iterator & other)
protected

Copy constructor.

Parameters
otherIterator to copy

Member Function Documentation

◆ findNextValidBucket()

template<typename K_TYPE, typename V_TYPE, typename ALLOC, typename HASH>
original::u_integer original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator::findNextValidBucket ( vector< hashNode *, rebind_alloc_pointer > * buckets,
u_integer bucket )
staticprotected

Finds the next non-empty bucket.

Parameters
bucketsReference to buckets vector
bucketStarting bucket index
Returns
Index of next non-empty bucket or buckets.size() if none

◆ findPrevValidBucket()

template<typename K_TYPE, typename V_TYPE, typename ALLOC, typename HASH>
original::u_integer original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator::findPrevValidBucket ( vector< hashNode *, rebind_alloc_pointer > * buckets,
u_integer bucket )
staticprotected

Finds the previous non-empty bucket.

Parameters
bucketsReference to buckets vector
bucketStarting bucket index
Returns
Index of previous non-empty bucket or buckets.size() if none

◆ get() [1/2]

template<typename K_TYPE, typename V_TYPE, typename ALLOC, typename HASH>
original::couple< const K_TYPE, V_TYPE > & original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator::get ( )

Gets current key-value pair (non-const)

Returns
Reference to current pair
Exceptions
outOfBoundErrorif iterator is invalid

◆ get() [2/2]

template<typename K_TYPE, typename V_TYPE, typename ALLOC, typename HASH>
original::couple< const K_TYPE, V_TYPE > original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator::get ( ) const

Gets current key-value pair (const)

Returns
Copy of current pair
Exceptions
outOfBoundErrorif iterator is invalid

◆ hasNext()

template<typename K_TYPE, typename V_TYPE, typename ALLOC, typename HASH>
bool original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator::hasNext ( ) const
nodiscard

Checks if more elements are available.

Returns
true if more elements can be traversed

◆ isValid()

template<typename K_TYPE, typename V_TYPE, typename ALLOC, typename HASH>
bool original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator::isValid ( ) const
nodiscard

Checks if iterator points to valid element.

Returns
true if iterator is valid

◆ next()

template<typename K_TYPE, typename V_TYPE, typename ALLOC, typename HASH>
void original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator::next ( ) const

Advances to the next element.

Exceptions
outOfBoundErrorif already at end

◆ operator+=()

template<typename K_TYPE, typename V_TYPE, typename ALLOC, typename HASH>
void original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator::operator+= ( integer steps) const

Advances iterator by steps positions.

Parameters
stepsNumber of positions to advance (must be >= 0)
Exceptions
unSupportedMethodErrorif steps is negative

◆ operator=()

template<typename K_TYPE, typename V_TYPE, typename ALLOC, typename HASH>
original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator & original::hashTable< K_TYPE, V_TYPE, ALLOC, HASH >::Iterator::operator= ( const Iterator & other)
protected

Copy assignment operator.

Parameters
otherIterator to copy from
Returns
Reference to this iterator

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