SleakEngine 1.0.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 (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
 Looks up key and writes its value into outValue; returns false if not found.
size_t getCapacity () const
size_t getSize () const
void insert (const Key &key, const Value &value)
 Inserts or updates the value for key, resizing first if over the load factor.
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 using chaining or open addressing (specify which one you used).
  • Provides methods for inserting, deleting, and retrieving key-value pairs.

Definition at line 31 of file HashTable.hpp.

Constructor & Destructor Documentation

◆ HashTable()

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

Definition at line 84 of file HashTable.hpp.

◆ ~HashTable()

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

Definition at line 90 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 172 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 157 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 141 of file HashTable.hpp.

◆ getCapacity()

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

Definition at line 180 of file HashTable.hpp.

◆ getSize()

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

Definition at line 179 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 96 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 124 of file HashTable.hpp.