CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Hash Table Iteration

Functions

_htiInitAnno bool htiInit (htiter *iter, hashtable htbl)
 
_htiNextAnno bool htiNext (htiter *iter)
 
void htiFinish (htiter *iter)
 
bool htiValid (htiter *iter)
 

Detailed Description

Iteration allows traversing all key-value pairs in the hash table. The order of iteration is the same as the order that the elements were inserted into the table.

Usage pattern:

htiter iter;
htiInit(&iter, ht);
while (htiValid(&iter)) {
string key = htiKey(string, iter);
int32 val = htiVal(int32, iter);
// process key and val
htiNext(&iter)
}
htiFinish(&iter);
#define htiKey(type, iter)
Definition hashtable.h:187
#define htiVal(type, iter)
Definition hashtable.h:195
void htiFinish(htiter *iter)
bool htiValid(htiter *iter)
Definition hashtable.h:676
_htiInitAnno bool htiInit(htiter *iter, hashtable htbl)
_htiNextAnno bool htiNext(htiter *iter)

Function Documentation

◆ htiFinish()

void htiFinish ( htiter *  iter)

Finalizes an iterator after iteration is complete

This must be called after iteration is complete (when htiNext returns false) to properly clean up the iterator state.

Parameters
iterIterator to finalize

◆ htiInit()

_htiInitAnno bool htiInit ( htiter *  iter,
hashtable  htbl 
)

Initializes an iterator and positions it at the first element

If this returns false, do not call htiNext(), but htiValid() can be used regardless and is often more convenient. htiFinish() is also safe to call regardless of the return value.

Parameters
iterIterator to initialize
htblHash table to iterate over
Returns
true if the table has at least one element (iterator is valid), false if the table is empty or NULL (iterator is invalid)

◆ htiNext()

_htiNextAnno bool htiNext ( htiter *  iter)

Advances the iterator to the next element

After this returns false, the iterator is invalid and htiFinish() should be called.

Parameters
iterIterator to advance
Returns
true if advanced to a valid element, false if there are no more elements (iteration complete)

◆ htiValid()

bool htiValid ( htiter *  iter)
inline

Checks if an iterator is currently positioned at a valid element

Parameters
iterIterator to check
Returns
true if the iterator is valid and can be used to access data, false if the iterator is invalid (uninitialized or past the end)

Definition at line 676 of file hashtable.h.