8#define HASH_TABLE_INIT_SIZE 128
192 MxU32 hash = m_table->Hash(p_obj);
195 if (t->m_hash == hash && !m_table->Compare(t->m_obj, p_obj)) {
200 return m_match !=
NULL;
207 p_obj = m_match->m_obj;
210 return m_match !=
NULL;
219 if (m_match->m_prev) {
220 m_match->m_prev->m_next = m_match->m_next;
224 m_table->m_slots[m_match->m_hash % m_table->m_numSlots] = m_match->m_next;
227 if (m_match->m_next) {
228 m_match->m_next->m_prev = m_match->m_prev;
231 m_table->m_customDestructor(m_match->m_obj);
247 for (
MxS32 i = 0; i < m_numSlots; i++) {
251 this->m_customDestructor(t->m_obj);
265 MxU32 oldSize = m_numSlots;
268 switch (m_resizeOption) {
270 m_numSlots += m_increaseAmount;
272 case e_expandMultiply:
273 m_numSlots *= m_increaseFactor;
282 for (
MxS32 i = 0; i < oldSize; i++) {
298 p_node->
m_next = m_slots[bucket];
300 if (m_slots[bucket]) {
301 m_slots[bucket]->
m_prev = p_node;
304 m_slots[bucket] = p_node;
311 if (m_resizeOption && ((this->m_count + 1) / m_numSlots) > m_autoResizeRatio) {
315 MxU32 hash = Hash(p_newobj);
323#undef HASH_TABLE_INIT_SIZE
[AI] Template class for a generic collection, providing fundamental storage and comparison facilities...
[AI] Base virtual class for all Mindscape engine (Mx) objects.
[AI] Non-intrusive search-and-edit cursor for navigating, querying, or deleting a specific entry in a...
MxBool Find(T p_obj)
[AI] Finds and focuses the cursor on the first node matching the given object by hash and value; supp...
MxHashTableCursor(MxHashTable< T > *p_table)
[AI] Constructs a cursor operating on the supplied table; initially not referencing any match.
void DeleteMatch()
[AI] If the cursor points to a match, removes it from table and destroys the node.
MxBool Current(T &p_obj)
[AI] Retrieves the object at the current match position, if valid.
[AI] Node used within the MxHashTable to store an individual object and associated hash,...
MxU32 m_hash
[AI] The hash value for m_obj, used for placement/search in the table.
T m_obj
[AI] The actual object value this node represents.
MxHashTableNode * m_prev
[AI] Previous node in the linked list chain within the current bucket.
MxHashTableNode * m_next
[AI] Next node in the linked list chain within the current bucket.
[AI] Generic hash table collection implementing chained (bucketed) hashing, used for efficient lookup...
void NodeInsert(MxHashTableNode< T > *)
[AI] Inserts a given node into the relevant hash bucket according to the node's hash value.
MxU32 m_autoResizeRatio
[AI] Ratio at which the table will auto-resize (load factor denominator).
Option m_resizeOption
[AI] Strategy currently in use for resizing the table when needed.
MxHashTableNode< T > ** m_slots
[AI] Array of pointers to bucket heads; each slot is a chain of nodes (linked list) holding objects w...
~MxHashTable() override
[AI] Destructor.
void Add(T)
[AI] Inserts a new item into the hash table, possibly resizing if automatic resize is enabled and loa...
MxHashTable()
[AI] Default constructor.
MxU32 m_numSlots
[AI] Number of hash buckets in the table; controls how hash values are mapped to buckets.
void DeleteAll()
[AI] Removes and destructs all nodes in all hash buckets, clearing the table.
Option
[AI] Enum describing the strategy for resizing the hash table when load increases.
@ e_expandAll
[AI] Fixed amount of slots added on resize.
@ e_noExpand
[AI] Never resize (table will not expand regardless of load).
@ e_expandMultiply
[AI] Table size is multiplied by a factor on resize.
void Resize()
[AI] Expand/recreates the hash table according to the current resizing policy.
virtual MxU32 Hash(T)
[AI] Computes the hash of the given object.
#define NULL
[AI] Null pointer value (C/C++ semantics).
#define HASH_TABLE_INIT_SIZE