|
OpenTTD Source 20260304-master-g1baaa74679
|
class HashTable<Titem, HASH_BITS> - simple hash table of pointers allocated elsewhere. More...
#include <hashtable.hpp>
Public Types | |
| typedef Titem::Key | Tkey |
| Make Titem::Key a property of HashTable. | |
Public Member Functions | |
| int | Count () const |
| Get the number of elements. | |
| void | Clear () |
| Clear all items. | |
| const Titem * | Find (const Tkey &key) const |
| Try to find an item by key. | |
| Titem * | Find (const Tkey &key) |
| Try to find an item by key. | |
| Titem * | TryPop (const Tkey &key) |
| Remove an item by key if found. | |
| Titem & | Pop (const Tkey &key) |
| Remove an item by key that must exist. | |
| bool | TryPop (Titem &item) |
| Remove an item if found. | |
| void | Pop (Titem &item) |
| Remove an item that must exist. | |
| void | Push (Titem &new_item) |
| Add an item that may not exist. | |
Static Public Attributes | |
| static constexpr int | HASH_BITS = Thash_bits_ |
| Publish num of hash bits. | |
| static constexpr int | CAPACITY = 1 << HASH_BITS |
| And num of slots 2^bits. | |
Protected Types | |
| using | Slot = HashTableSlot<Titem> |
| each slot contains pointer to the first item in the list, Titem contains pointer to the next item - GetHashNext(), SetHashNext() | |
Static Protected Member Functions | |
| static int | CalcHash (const Tkey &key) |
| Return hash for the given key modulo number of slots. | |
| static int | CalcHash (const Titem &item) |
| Return hash for the given item modulo number of slots. | |
Protected Attributes | |
| Slot | slots [CAPACITY] |
| Data storage (array of blobs). | |
| int | number_of_items = 0 |
| Item counter. | |
class HashTable<Titem, HASH_BITS> - simple hash table of pointers allocated elsewhere.
Supports: Add/Find/Remove of Titems.
Your Titem must meet some extra requirements to be HashTable compliant:
In addition, the Titem::Key class must support:
Definition at line 149 of file hashtable.hpp.
|
protected |
each slot contains pointer to the first item in the list, Titem contains pointer to the next item - GetHashNext(), SetHashNext()
Definition at line 160 of file hashtable.hpp.
| typedef Titem::Key HashTable< Titem, Thash_bits_ >::Tkey |
Make Titem::Key a property of HashTable.
Definition at line 151 of file hashtable.hpp.
|
inlinestaticprotected |
Return hash for the given item modulo number of slots.
| item | The item to consider. |
Definition at line 184 of file hashtable.hpp.
References CalcHash().
|
inlinestaticprotected |
Return hash for the given key modulo number of slots.
| key | The key to consider. |
Definition at line 170 of file hashtable.hpp.
References HASH_BITS.
Referenced by CalcHash(), Find(), Find(), Push(), TryPop(), and TryPop().
|
inline |
Clear all items.
Definition at line 200 of file hashtable.hpp.
References CAPACITY, and Clear().
Referenced by Clear(), and CSegmentCostCacheT< CachedData >::Flush().
|
inline |
Get the number of elements.
Definition at line 194 of file hashtable.hpp.
Referenced by NodeList< CYapfRailNode, 8, 10 >::ClosedCount(), and NodeList< CYapfRailNode, 8, 10 >::OpenCount().
|
inline |
Try to find an item by key.
| key | The key to find. |
nullptr. Definition at line 224 of file hashtable.hpp.
References CalcHash(), and HashTableSlot< TItem >::Find().
|
inline |
Try to find an item by key.
| key | The key to find. |
nullptr. Definition at line 211 of file hashtable.hpp.
References CalcHash(), and HashTableSlot< TItem >::Find().
Referenced by NodeList< CYapfRailNode, 8, 10 >::FindClosedNode(), NodeList< CYapfRailNode, 8, 10 >::FindOpenNode(), NodeList< CYapfRailNode, 8, 10 >::InsertClosedNode(), and NodeList< CYapfRailNode, 8, 10 >::InsertOpenNode().
|
inline |
Remove an item by key that must exist.
| key | The key to search for. |
nullptr. Definition at line 253 of file hashtable.hpp.
References TryPop().
Referenced by NodeList< CYapfRailNode, 8, 10 >::PopBestOpenNode(), and NodeList< CYapfRailNode, 8, 10 >::PopOpenNode().
|
inline |
Remove an item that must exist.
| item | The item to remove. |
Definition at line 281 of file hashtable.hpp.
References TryPop().
|
inline |
Add an item that may not exist.
| new_item | The item to add. |
Definition at line 291 of file hashtable.hpp.
References HashTableSlot< TItem >::Attach(), CalcHash(), and HashTableSlot< TItem >::Find().
Referenced by NodeList< CYapfRailNode, 8, 10 >::InsertClosedNode(), and NodeList< CYapfRailNode, 8, 10 >::InsertOpenNode().
|
inline |
Remove an item by key if found.
| key | The key to search for. |
nullptr. Definition at line 237 of file hashtable.hpp.
References CalcHash(), and HashTableSlot< TItem >::Detach().
|
inline |
Remove an item if found.
| item | The item to remove. |
true iff the item existed. Definition at line 265 of file hashtable.hpp.
References CalcHash(), and HashTableSlot< TItem >::Detach().
|
staticconstexpr |
|
protected |
Item counter.
Definition at line 163 of file hashtable.hpp.
|
protected |
Data storage (array of blobs).
Definition at line 162 of file hashtable.hpp.