Reference Guide: Hash Tables

HashTable

Class that implements a Hash Table data structure

Signature

template <typename T> class HashTable

Methods

Method Signature Description
HashTable HashTable (int (*comparator)(const T&,const T&), std::size_t (*hasher)(const T&)) Creates a hash table of unknown initial size by comparator and hashing function
HashTable HashTable (int (*comparator)(const T&,const T&), std::size_t (*hasher)(const T&), const std::size_t& reservedSize) Creates a hash table of known initial size by comparator and hashing function
~HashTable ~HashTable () Deallocates all elements in hash table from heap
clear void clear () Clears hash table of all elements
contains bool contains (const T& value) const Checks if hash table contains element by value
contains bool contains (const T& value, int (*customCompare)(const T&,const T&)) const Checks if hash table contains element by value and comparator
isEmpty bool isEmpty () const Checks if hash table is empty
size const std::size_t& size () const Gets number of elements in hash table
get T* get (const T& value) const Gets value in hash table matching that of input
set void set (const T& value) Adds element to hash table by value
remove void remove (const T& value) Removes element from hash table by value
remove void remove (const T& value, int (*customCompare)(const T&,const T&)) Removes element from hash table by value and comparator
getMinBucket std::size_t getMinBucket () const Gets bucket number to start iteration from
getCurrentNode HashTableEntry<T>* getCurrentNode (const std::size_t& bucket_number, const std::size_t& position) const Gets current element while iterating
nextNode void nextNode (std::size_t& bucket_number, std::size_t& position) Gets next node for iterating

LinkedHashTable

Class that implements a Linked Hash Table data structure

Signature

template <typename T> class LinkedHashTable

Methods

Method Signature Description
LinkedHashTable LinkedHashTable (int (*comparator)(const T&,const T&), std::size_t (*hasher)(const T&)) Creates a linked hash table by comparator and hashing function of unknown initial size
LinkedHashTable LinkedHashTable (int (*comparator)(const T&,const T&), std::size_t (*hasher)(const T&), const std::size_t& reservedSize) Creates a linked hash table by comparator and hashing function of known initial size
~LinkedHashTable ~LinkedHashTable () Deallocates all elements in linked hash table from heap
clear void clear () Clears linked hash table of all elements
contains bool contains (const T& value) const Checks if linked hash table contains element by value
contains bool contains (const T& value, int (*customCompare)(const T&,const T&)) const Checks if linked hash table contains element by value and comparator
isEmpty bool isEmpty () const Checks if linked hash table is empty
size const std::size_t& size () const Gets number of elements in linked hash table
get T* get (const T& value) const Gets value in linked hash table matching that of input
set void set (const T& value) Adds element to linked hash table by value
remove void remove (const T& value) Removes element from linked hash table by value
remove void remove (const T& value, int (*customCompare)(const T&,const T&)) Removes element from linked hash table by value and comparator
getHead LinkedHashTableEntry<T>*& getHead () Gets head to start iterating from
getTail LinkedHashTableEntry<T>*& getTail () Gets tail to stop iterating at

HashTableEntry

Struct that defines an entry in a Hash Table

Signature

template <typename T> struct HashTableEntry

Fields

Name Type Description
hash; std::size_t Value of hash calculation for entry data
data; T Data stored in entry
next; HashTableEntry<T>* Next entry in bucket

LinkedHashTableEntry

Struct that defines an entry in a Linked Hash Table

Signature

template <typename T> struct LinkedHashTableEntry

Fields

Name Type Description
hash; std::size_t Value of hash calculation for entry data
data; T Data stored in entry
nextInBucket; LinkedHashTableEntry<T>* Next entry in bucket
previous; LinkedHashTableEntry<T>* Previous entry by insertion order
next; LinkedHashTableEntry<T>* Next entry by insertion order