data.hash_table ≡
A data structure that maps keys to values using hashing.
template <typename Hash, typename Key> inline Hash toeplitz_hash(Key key) §
Computes a hash of input keys using an instance of the
toeplitz class.
Parameters
-
typename HashOutput hash type
-
typename KeyInput key type
template < typename Key, typename Value, auto Depth, auto Associativity, (Key) -> index_t<(Depth / Associativity)> hash_fn = toeplitz_hash<index_t<(Depth / Associativity)>, Key>, auto GenerationBits = 4, auto MaxIterations = Depth, auto DataBanks = 1, auto HistorySize = 1, auto MaxThreads = 512 > class hash_table §
A mapping from Key to Value. Use
insert_or_update to insert, lookup, modify, and reset the
mapping. The only way to remove entries from the table is to reset the
entire table to the initial empty state.
Parameters
-
typename Key -
typename Value -
auto DepthMaximum number of elements that can be stored.
-
auto AssociativityNumber of locations to consider on each search iteration. Larger values lead to more resource consumption and higher throughput.
-
(Key) -> index_t<(Depth / Associativity)> hash_fn = toeplitz_hash<index_t<(Depth / Associativity)>, Key>
Function that maps a key to a location in the hash table.
-
auto GenerationBits = 4
Number of bits to ammortize reset costs. Higher values lead to more resource consumption, and lower the average cost of reset.
-
auto MaxIterations = DepthMaximum number of search iterations before returning an error
-
auto DataBanks = 1
Number of banks to store values. If
Depthis high, then increasingDataBankscan improve clock frequency. -
auto HistorySize = 1
Size of arrays used to detect hazards. Larger values increase frequency and resource usage.
-
auto MaxThreads = 512
Maximum number of threads that can be present inside of
insert_or_updateconcurrently. Caller does not need to ensure this limit is respected. Higher values enable more concurrency which can improve performance if the allocation function compiles to a deep pipeline or ifDataBanksis set to a large value. Lower values save resources by using narrower counters to track in-flight threads.
Types
-
struct result §
Return value on a successful
insert_or_update
Methods
-
inline bool test_thread_count(bool reset) §
Used to block the first thread of each generation until
_threads_in_flightis zero -
inline optional<hash_table::result> insert_or_update( Key key, bool reset, bool insert_on_miss, () -> Value allocate_fn, (Value, bool) -> Value access_fn ) §
Combined function that can be used to:
- Insert a new
(Key, Value)pair. - Lookup the
Valueassociated with aKeythat is already present in the table. - Modify the
Valueassociated with aKeythat is already present in the table. - Reset the table to the initial state.
Inserts, lookups, and modifications use an iterative search. A hash of the input key is used to determine the starting location for the search. On each iteration,
Associativitylocations are checked in parallel. If a matching key is found then the hash table runs at full throughput. Otherwise, the search loop proceeds, searchingAssociativitynew locations on each iteration. Callers must ensure there are never concurrent calls to this function from separate call sites. Calls toallocate_fnoccur in the same order as calls toinsert_or_update.Arguments
-
Key keyKey used to find a location to store the value
-
bool reset
True if all elements in the hash table should be removed before performing the search.
-
bool insert_on_miss
True if a new
(Key, Value)pair should be inserted into the table if a pair with a matchingkeyis not already present. -
() -> Value allocate_fnFunction that is called when a key is inserted into the hash table. Returns a value that is passed to
access_fn. -
(Value, bool) -> Value access_fn
Function that accepts a previous value and a bool indicating if an insert occured. Returns a new value to store in the hash table associated with the key. If
keywas not already present in the table then, the first parameter is the value returned byallocate_fnand the second parameter istrue. Otherwise, the first parameter is the value currently stored in the table and the second parameter isfalse.
- Insert a new
Invariants
-
(0 == (Depth % Associativity))All sets must have the same number of elements
-
(0 == (hash_table::NumSets & (hash_table::NumSets - 1)))
Set count must be a power of 2
-
(MaxIterations > 0)MaxIterations must be positive, otherwise no lookup operation could ever succeed