An open source method of characteristics neutron transport code.
|
A fixed-size hash map supporting insertion and lookup operations. More...
#include "src/ParallelHashMap.h"
Public Member Functions | |
FixedHashMap (size_t M=64) | |
Constructor initializes fixed-size table of buckets filled with empty linked lists. More... | |
virtual | ~FixedHashMap () |
Destructor deletes all nodes in the linked lists associated with each bucket in the fixed-size table and their pointers. | |
bool | contains (K &key) |
Determine whether the fixed-size table contains a given key. More... | |
V & | at (K &key) |
Determine the value associated with a given key in the fixed-size table. More... | |
void | insert (K key, V value) |
Inserts a key/value pair into the fixed-size table. More... | |
long | insert_and_get_count (K key, V value) |
Inserts a key/value pair into the fixed-size table and returns the order number with which it was inserted. More... | |
size_t | size () |
Returns the number of key/value pairs in the fixed-size table. More... | |
size_t | bucket_count () |
Returns the number of buckets in the fixed-size table. More... | |
K * | keys () |
Returns an array of the keys in the fixed-size table. More... | |
V * | values () |
Returns an array of the values in the fixed-size table. More... | |
void | clear () |
Clears all key/value pairs form the hash table. | |
void | print_buckets () |
Prints the contents of each bucket to the screen. More... | |
A fixed-size hash map supporting insertion and lookup operations.
The FixedHashMap class supports insertion and lookup operations but not deletion as deletion is not needed in the OpenMOC application. This hash table uses chaining for collisions and does not incorporate concurrency objects except for tracking the number of entries in the table for which an atomic increment is used. This hash table is not thread safe but is used as a building block for the ParallelHashMap class. This table guarantees O(1) insertions and lookups on average.
FixedHashMap< K, V >::FixedHashMap | ( | size_t | M = 64 | ) |
Constructor initializes fixed-size table of buckets filled with empty linked lists.
The constructor initializes a fixed-size hash map with the size as an input parameter. If no size is given the default size (64) is used. Buckets are filled with empty linked lists presented as NULL pointers.
M | size of fixed hash map |
V & FixedHashMap< K, V >::at | ( | K & | key | ) |
Determine the value associated with a given key in the fixed-size table.
The linked list in the bucket associated with the key is searched and once the key is found, the corresponding value is returned. An exception is thrown if the key is not present in the map.
key | key whose corresponding value is desired |
size_t FixedHashMap< K, V >::bucket_count | ( | ) |
Returns the number of buckets in the fixed-size table.
bool FixedHashMap< K, V >::contains | ( | K & | key | ) |
Determine whether the fixed-size table contains a given key.
The linked list in the bucket associated with the key is searched to determine whether the key is present.
key | key to be searched |
void FixedHashMap< K, V >::insert | ( | K | key, |
V | value | ||
) |
Inserts a key/value pair into the fixed-size table.
The specified key value pair is inserted into the fixed-size table. If the key already exists in the table, the pair is not inserted and the function returns.
key | key of the key/value pair to be inserted |
value | value of the key/value pair to be inserted |
long FixedHashMap< K, V >::insert_and_get_count | ( | K | key, |
V | value | ||
) |
Inserts a key/value pair into the fixed-size table and returns the order number with which it was inserted.
The specified key value pair is inserted into the fixed-size table. If the key already exists in the table, the pair is not inserted and the function returns -1.
key | key of the key/value pair to be inserted |
value | value of the key/value pair to be inserted |
K * FixedHashMap< K, V >::keys | ( | ) |
Returns an array of the keys in the fixed-size table.
All buckets are scanned in order to form a list of all keys present in the table and then the list is returned. WARNING: The user is responsible for freeing the allocated memory once the array is no longer needed.
void FixedHashMap< K, V >::print_buckets | ( | ) |
Prints the contents of each bucket to the screen.
All buckets are scanned and the contents of the buckets are printed, which are pointers to linked lists. If the pointer is NULL suggesting that the linked list is empty, NULL is printed to the screen.
size_t FixedHashMap< K, V >::size | ( | ) |
Returns the number of key/value pairs in the fixed-size table.
V * FixedHashMap< K, V >::values | ( | ) |
Returns an array of the values in the fixed-size table.
All buckets are scanned in order to form a list of all values present in the table and then the list is returned. WARNING: The user is responsible for freeing the allocated memory once the array is no longer needed.