SleakEngine 0.1.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::HashTable< Key, Value > Class Template Reference

Implements a hash table (or map) for efficient key-value storage and retrieval. More...

#include <HashTable.hpp>

Public Member Functions

 HashTable (const HashTable &other)
 Deep-copies other's slots, including its capacity and load factor.
 HashTable (size_t initCapacity=DEFAULT_CAPACITY, float loadFactor=DEFAULT_LOAD_FACTOR)
 ~HashTable ()
void clear ()
 Drops every entry and reallocates the table at its current capacity.
bool contains (const Key &key) const
 True if key currently has a live entry.
bool get (const Key &key, Value &outValue) const
size_t getCapacity () const
size_t getSize () const
void insert (const Key &key, const Value &value)
HashTable & operator= (const HashTable &other)
 Replaces this table with a deep copy of other.
bool remove (const Key &key)
 Tombstones the entry for key; returns false if it wasn't present.

Detailed Description

template<typename Key, typename Value>
class Sleak::HashTable< Key, Value >

Implements a hash table (or map) for efficient key-value storage and retrieval.

The HashTable class provides fast access to values based on their associated keys. It is suitable for scenarios where you need to quickly look up data using unique identifiers. Use this class when you need to store and retrieve data based on keys, such as symbol tables, dictionaries, or caching systems.

Example Use Cases:

  • Implementing a symbol table in a compiler.
  • Creating a dictionary or vocabulary lookup system.
  • Caching frequently accessed data.
  • Storing user preferences or configuration settings.

Implementation Details:

  • Uses a hash function to map keys to indices in an internal array.
  • Handles collisions with linear-probing open addressing and tombstones.
  • Provides methods for inserting, deleting, and retrieving key-value pairs.

Definition at line 34 of file HashTable.hpp.

Constructor & Destructor Documentation

◆ HashTable() [1/2]

template<typename Key, typename Value>
Sleak::HashTable< Key, Value >::HashTable ( size_t initCapacity = DEFAULT_CAPACITY,
float loadFactor = DEFAULT_LOAD_FACTOR )
inline

Definition at line 106 of file HashTable.hpp.

◆ HashTable() [2/2]

template<typename Key, typename Value>
Sleak::HashTable< Key, Value >::HashTable ( const HashTable< Key, Value > & other)
inline

Deep-copies other's slots, including its capacity and load factor.

Definition at line 118 of file HashTable.hpp.

◆ ~HashTable()

template<typename Key, typename Value>
Sleak::HashTable< Key, Value >::~HashTable ( )
inline

Definition at line 142 of file HashTable.hpp.

Member Function Documentation

◆ clear()

template<typename Key, typename Value>
void Sleak::HashTable< Key, Value >::clear ( )
inline

Drops every entry and reallocates the table at its current capacity.

Definition at line 201 of file HashTable.hpp.

◆ contains()

template<typename Key, typename Value>
bool Sleak::HashTable< Key, Value >::contains ( const Key & key) const
inline

True if key currently has a live entry.

Definition at line 198 of file HashTable.hpp.

◆ get()

template<typename Key, typename Value>
bool Sleak::HashTable< Key, Value >::get ( const Key & key,
Value & outValue ) const
inline

Looks up key and writes its value into outValue; returns false if not found.

Definition at line 188 of file HashTable.hpp.

◆ getCapacity()

template<typename Key, typename Value>
size_t Sleak::HashTable< Key, Value >::getCapacity ( ) const
inline

Definition at line 210 of file HashTable.hpp.

◆ getSize()

template<typename Key, typename Value>
size_t Sleak::HashTable< Key, Value >::getSize ( ) const
inline

Definition at line 209 of file HashTable.hpp.

◆ insert()

template<typename Key, typename Value>
void Sleak::HashTable< Key, Value >::insert ( const Key & key,
const Value & value )
inline

Inserts or updates the value for key, resizing first if over the load factor.

Definition at line 146 of file HashTable.hpp.

◆ operator=()

template<typename Key, typename Value>
HashTable & Sleak::HashTable< Key, Value >::operator= ( const HashTable< Key, Value > & other)
inline

Replaces this table with a deep copy of other.

Definition at line 130 of file HashTable.hpp.

◆ remove()

template<typename Key, typename Value>
bool Sleak::HashTable< Key, Value >::remove ( const Key & key)
inline

Tombstones the entry for key; returns false if it wasn't present.

Definition at line 173 of file HashTable.hpp.