Isle
Loading...
Searching...
No Matches
MxHashTable< T > Class Template Reference

[AI] Generic hash table collection implementing chained (bucketed) hashing, used for efficient lookup and storage of objects by key or value. More...

#include <mxhashtable.h>

Inheritance diagram for MxHashTable< T >:
Collaboration diagram for MxHashTable< T >:

Public Types

enum  Option { e_noExpand = 0 , e_expandAll , e_expandMultiply }
 [AI] Enum describing the strategy for resizing the hash table when load increases. More...
 

Public Member Functions

 MxHashTable ()
 [AI] Default constructor. More...
 
 ~MxHashTable () override
 [AI] Destructor. More...
 
void Resize ()
 [AI] Expand/recreates the hash table according to the current resizing policy. More...
 
void Add (T)
 [AI] Inserts a new item into the hash table, possibly resizing if automatic resize is enabled and load threshold is exceeded. More...
 
void DeleteAll ()
 [AI] Removes and destructs all nodes in all hash buckets, clearing the table. More...
 
virtual MxU32 Hash (T)
 [AI] Computes the hash of the given object. More...
 

Protected Member Functions

void NodeInsert (MxHashTableNode< T > *)
 [AI] Inserts a given node into the relevant hash bucket according to the node's hash value. More...
 
- Protected Member Functions inherited from MxCollection< T >
 MxCollection ()
 [AI] Constructs an empty collection, initializing count and default element destructor. More...
 
virtual MxS8 Compare (T a, T b)
 [AI] Compares two elements of the collection (default implementation returns zero; override in subclasses for meaningful comparison). More...
 
 ~MxCollection () override
 [AI] Virtual destructor for proper polymorphic destruction. More...
 
void SetDestroy (void(*p_customDestructor)(T))
 [AI] Assigns a custom destructor function to be used for elements of this collection. More...
 
- Protected Member Functions inherited from MxCore
 MxCore ()
 [AI] Constructs a new MxCore object and assigns it a unique id. More...
 
virtual ~MxCore ()
 [AI] Virtual destructor. Required for correct polymorphic cleanup in derived classes. More...
 
virtual MxLong Notify (MxParam &p_param)
 [AI] Virtual callback notification mechanism. More...
 
virtual MxResult Tickle ()
 [AI] Called by tickle managers to allow the object to update itself. More...
 
virtual const char * ClassName () const
 [AI] Returns the runtime class name of this object. More...
 
virtual MxBool IsA (const char *p_name) const
 [AI] Checks whether this object's class type or parents match the given name. More...
 
MxU32 GetId ()
 [AI] Gets the unique (per-process) id assigned to this object instance. More...
 

Protected Attributes

MxHashTableNode< T > ** m_slots
 [AI] Array of pointers to bucket heads; each slot is a chain of nodes (linked list) holding objects with equal (modulo table size) hashes. More...
 
MxU32 m_numSlots
 [AI] Number of hash buckets in the table; controls how hash values are mapped to buckets. More...
 
MxU32 m_autoResizeRatio
 [AI] Ratio at which the table will auto-resize (load factor denominator). More...
 
Option m_resizeOption
 [AI] Strategy currently in use for resizing the table when needed. More...
 
union {
   MxU32   m_increaseAmount
 
   double   m_increaseFactor
 
}; 
 [AI] Union holding the setting for table expansion: More...
 
- Protected Attributes inherited from MxCollection< T >
MxU32 m_count
 [AI] Number of elements currently stored in the collection. More...
 
void(* m_customDestructor )(T)
 [AI] Function pointer to the custom element destructor used for cleanup of elements. More...
 

Friends

class MxHashTableCursor< T >
 

Additional Inherited Members

- Static Protected Member Functions inherited from MxCollection< T >
static void Destroy (T obj)
 [AI] Static no-op destroy function; suitable for types that do not need destruction. More...
 

Detailed Description

template<class T>
class MxHashTable< T >

[AI] Generic hash table collection implementing chained (bucketed) hashing, used for efficient lookup and storage of objects by key or value.

[AI] Inherits collection semantics from MxCollection<T> but also manages resizing, hash calculation, and separate chaining (via MxHashTableNode). Provides insert, deletion, and all-bucket purge operations. Resizing policies can be controlled via Option.

Template Parameters
T[AI] Type of object managed by the hash table.

Definition at line 57 of file mxhashtable.h.

Member Enumeration Documentation

◆ Option

template<class T >
enum MxHashTable::Option

[AI] Enum describing the strategy for resizing the hash table when load increases.

Enumerator
e_noExpand 

[AI] Never resize (table will not expand regardless of load).

e_expandAll 

[AI] Fixed amount of slots added on resize.

e_expandMultiply 

[AI] Table size is multiplied by a factor on resize.

Definition at line 62 of file mxhashtable.h.

Constructor & Destructor Documentation

◆ MxHashTable()

template<class T >
MxHashTable< T >::MxHashTable ( )
inline

[AI] Default constructor.

Initializes hash table with HASH_TABLE_INIT_SIZE slots and configures resizing behavior.

Definition at line 71 of file mxhashtable.h.

◆ ~MxHashTable()

template<class T >
MxHashTable< T >::~MxHashTable
override

[AI] Destructor.

Purges all contained nodes and releases bucket array.

Definition at line 238 of file mxhashtable.h.

Member Function Documentation

◆ Add()

template<class T >
void MxHashTable< T >::Add ( p_newobj)
inline

[AI] Inserts a new item into the hash table, possibly resizing if automatic resize is enabled and load threshold is exceeded.

Parameters
[AI]p_newobj The item to insert.

Definition at line 309 of file mxhashtable.h.

◆ DeleteAll()

template<class T >
void MxHashTable< T >::DeleteAll

[AI] Removes and destructs all nodes in all hash buckets, clearing the table.

Definition at line 245 of file mxhashtable.h.

◆ Hash()

template<class T >
virtual MxU32 MxHashTable< T >::Hash ( )
inlinevirtual

[AI] Computes the hash of the given object.

Should be overridden for meaningful hash computation.

Parameters
[AI](unnamed) The object to compute the hash for.
Returns
[AI] Hash value appropriate for placing the object in a bucket.

Reimplemented in MxVariableTable.

Definition at line 107 of file mxhashtable.h.

◆ NodeInsert()

template<class T >
void MxHashTable< T >::NodeInsert ( MxHashTableNode< T > *  p_node)
inlineprotected

[AI] Inserts a given node into the relevant hash bucket according to the node's hash value.

Parameters
p_node[AI] Node (already allocated) to insert into appropriate bucket.

Definition at line 294 of file mxhashtable.h.

◆ Resize()

template<class T >
void MxHashTable< T >::Resize
inline

[AI] Expand/recreates the hash table according to the current resizing policy.

[AI] Moves nodes from the old bucket array to a newly sized one based on m_resizeOption, re-bucketing all nodes.

Definition at line 261 of file mxhashtable.h.

Friends And Related Function Documentation

◆ MxHashTableCursor< T >

template<class T >
friend class MxHashTableCursor< T >
friend

Definition at line 107 of file mxhashtable.h.

Member Data Documentation

◆ 

union { ... } MxHashTable< T >::@178

[AI] Union holding the setting for table expansion:

  • m_increaseAmount (when using e_expandAll): slots to add on resize.
  • m_increaseFactor (when using e_expandMultiply): multiplicative factor for resizing (e.g. double the table). Purpose is determined by m_resizeOption.

◆ m_autoResizeRatio

template<class T >
MxU32 MxHashTable< T >::m_autoResizeRatio
protected

[AI] Ratio at which the table will auto-resize (load factor denominator).

Definition at line 125 of file mxhashtable.h.

◆ m_increaseAmount

template<class T >
MxU32 MxHashTable< T >::m_increaseAmount

Definition at line 137 of file mxhashtable.h.

◆ m_increaseFactor

template<class T >
double MxHashTable< T >::m_increaseFactor

Definition at line 138 of file mxhashtable.h.

◆ m_numSlots

template<class T >
MxU32 MxHashTable< T >::m_numSlots
protected

[AI] Number of hash buckets in the table; controls how hash values are mapped to buckets.

Definition at line 122 of file mxhashtable.h.

◆ m_resizeOption

template<class T >
Option MxHashTable< T >::m_resizeOption
protected

[AI] Strategy currently in use for resizing the table when needed.

Definition at line 128 of file mxhashtable.h.

◆ m_slots

template<class T >
MxHashTableNode<T>** MxHashTable< T >::m_slots
protected

[AI] Array of pointers to bucket heads; each slot is a chain of nodes (linked list) holding objects with equal (modulo table size) hashes.

Definition at line 119 of file mxhashtable.h.


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