AlgoPlus v0.1.0
Loading...
Searching...
No Matches
hash_table< KeyType, ValueType >::Iterator Class Reference

Iterator class. More...

#include <hash_table.h>

Public Types

using BucketType
 

Public Member Functions

 Iterator (BucketIterator start, BucketIterator end)
 Construct a new Iterator object.
 
Iteratoroperator= (const std::unordered_map< size_t, std::list< std::pair< KeyType, ValueType > > > &bucket)
 operator = for hash table iterator class
 
Iteratoroperator++ ()
 operator ++ for type Iterator
 
Iterator operator++ (int)
 operator ++ for type Iterator
 
Iteratoroperator-- ()
 operator – for type Iterator
 
Iterator operator-- (int)
 operator – for type Iterator
 
bool operator!= (const Iterator &it) const
 operator != for Type Iterator
 
std::pair< KeyType, ValueType > & operator* ()
 operator * for Type Iterator
 
 hash_table (std::vector< std::pair< KeyType, ValueType > > v={})
 Construct a new hash table object.
 
 hash_table (const hash_table &h)
 Copy constructor of the hash_table.
 
hash_tableoperator= (const hash_table &h)
 operator = for the hash_table class
 
 ~hash_table ()
 Destroy the hash table object.
 
void insert (const KeyType &key, const ValueType &value)
 Inserts a key-value pair into the hash table.
 
std::optional< ValueType > retrieve (const KeyType &key)
 Retrieves the value associated with the given key.
 
void remove (const KeyType &key)
 Removes the key-value pair associated with the given key from the hash table.
 
Iterator begin ()
 
Iterator end ()
 

Friends

std::ostream & operator<< (std::ostream &out, hash_table< KeyType, ValueType > &h)
 << operator for hash_table class
 

Detailed Description

template<typename KeyType, typename ValueType>
class hash_table< KeyType, ValueType >::Iterator

Iterator class.

Constructor & Destructor Documentation

◆ Iterator()

template<typename KeyType, typename ValueType>
hash_table< KeyType, ValueType >::Iterator::Iterator ( BucketIterator start,
BucketIterator end )
inlineexplicit

Construct a new Iterator object.

Parameters
bucketthe bucket list

Member Function Documentation

◆ hash_table() [1/2]

hash_table< KeyType, ValueType >::hash_table ( const hash_table & h)
inline

Copy constructor of the hash_table.

Parameters
hthe hash table we want to copy

◆ hash_table() [2/2]

hash_table< KeyType, ValueType >::hash_table ( std::vector< std::pair< KeyType, ValueType > > v = {})
inlineexplicit

Construct a new hash table object.

Parameters
vthe initializer vector

◆ insert()

void hash_table< KeyType, ValueType >::insert ( const KeyType & key,
const ValueType & value )
inline

Inserts a key-value pair into the hash table.

This function inserts a key-value pair into the hash table. If a pair with the same key already exists, it updates the value.

Parameters
keyThe key to insert.
valueThe value to insert.

◆ operator!=()

template<typename KeyType, typename ValueType>
bool hash_table< KeyType, ValueType >::Iterator::operator!= ( const Iterator & it) const
inline

operator != for Type Iterator

Parameters
itthe iterator we want to make the check
Returns
true if the current list that exist in the index is not equal to the it.list that exist in the it.index
false otherwise

◆ operator*()

template<typename KeyType, typename ValueType>
std::pair< KeyType, ValueType > & hash_table< KeyType, ValueType >::Iterator::operator* ( )
inline

operator * for Type Iterator

Returns
std::list<std::pair<KeyType, ValueType>> the list of the current index

◆ operator++() [1/2]

template<typename KeyType, typename ValueType>
Iterator & hash_table< KeyType, ValueType >::Iterator::operator++ ( )
inline

operator ++ for type Iterator

Returns
Iterator&

◆ operator++() [2/2]

template<typename KeyType, typename ValueType>
Iterator hash_table< KeyType, ValueType >::Iterator::operator++ ( int )
inline

operator ++ for type Iterator

Returns
Iterator&

◆ operator--() [1/2]

template<typename KeyType, typename ValueType>
Iterator & hash_table< KeyType, ValueType >::Iterator::operator-- ( )
inline

operator – for type Iterator

Returns
Iterator&

◆ operator--() [2/2]

template<typename KeyType, typename ValueType>
Iterator hash_table< KeyType, ValueType >::Iterator::operator-- ( int )
inline

operator – for type Iterator

Returns
Iterator

◆ operator=() [1/2]

hash_table & hash_table< KeyType, ValueType >::operator= ( const hash_table & h)
inline

operator = for the hash_table class

Parameters
hthe hash table we want to copy
Returns
hash_table&

◆ operator=() [2/2]

template<typename KeyType, typename ValueType>
Iterator & hash_table< KeyType, ValueType >::Iterator::operator= ( const std::unordered_map< size_t, std::list< std::pair< KeyType, ValueType > > > & bucket)
inline

operator = for hash table iterator class

Parameters
bucketthe bucket list
Returns
Iterator&

◆ remove()

void hash_table< KeyType, ValueType >::remove ( const KeyType & key)
inline

Removes the key-value pair associated with the given key from the hash table.

This function removes the key-value pair associated with the given key from the hash table.

Parameters
keyThe key to remove.

◆ retrieve()

std::optional< ValueType > hash_table< KeyType, ValueType >::retrieve ( const KeyType & key)
inline

Retrieves the value associated with the given key.

Parameters
keyThe key to retrieve the value for.
Returns
The value associated with the given key, if it exists. Otherwise, returns std::nullopt.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
hash_table< KeyType, ValueType > & h )
friend

<< operator for hash_table class

Returns
std::ostream&

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