Tervel
1.0.0
A collection of wait-free containers and algorithms.
|
A wait-free hash map implementation. More...
#include <wf_hash_map_no_delete.h>
Classes | |
class | ArrayNode |
This class is used to hold the secondary array structure. More... | |
class | DataNode |
This class is used to hold a key and value pair. More... | |
class | Node |
This class is used to differentiate between data_nodes and array_nodes/. More... | |
class | ValueAccessor |
This class is used to safe guard access to values. More... | |
Public Member Functions | |
HashMapNoDelete (uint64_t capacity, uint64_t expansion_rate=3) | |
~HashMapNoDelete () | |
Not Thread Safe! If it is a node type then the node will be freed If it is an array node then the destructor of the array node will free any nodes that are referenced it. More... | |
bool | at (Key key, ValueAccessor &va) |
This function returns true and initializes the passed ValueAccessor if the key exists in the hash map. More... | |
bool | insert (Key key, Value value) |
This function returns true if the key value pair was successfully inserted. More... | |
size_t | size () |
uint64_t | get_position (Key &key, size_t depth) |
uint64_t | max_depth () |
void | print_key (Key &key) |
Outputs the positions a key belongs in at each depth. More... | |
Private Types | |
typedef std::atomic< Node * > | Location |
Private Member Functions | |
void | expand_map (Location *loc, Node *&curr_value, uint64_t next_position) |
Increases the capacity of the hash map by replacing a data node reference with a reference to an array node containing a reference to that data node. More... | |
Private Attributes | |
const size_t | primary_array_size_ |
const size_t | primary_array_pow_ |
const size_t | secondary_array_size_ |
const size_t | secondary_array_pow_ |
std::atomic< uint64_t > | size_ |
std::unique_ptr< Location[]> | primary_array_ |
Friends | |
class | Node |
A wait-free hash map implementation.
TODO(steven): Provide general overview
Functor should have the following functions: -Key hash(Key k) (where hash(a) == (hash(b) implies a == b -bool key_equals (Key a, Key b) Important Note: the hashed value of keys will be passed in.
|
private |
|
inline |
|
inline |
Not Thread Safe! If it is a node type then the node will be freed If it is an array node then the destructor of the array node will free any nodes that are referenced it.
This may cause more array node's to be freed. Stack can reach max_depth() in size.
bool tervel::containers::wf::HashMapNoDelete< Key, Value, Functor >::at | ( | Key | key, |
ValueAccessor & | va | ||
) |
This function returns true and initializes the passed ValueAccessor if the key exists in the hash map.
Initializing the ValueAccessor consists of assigning storing a reference to the associated value and a reference to the access counter. The access counter will have been increased by one. Upon the destruction or re-initialization of the ValueAccessor, the access counter will be decremented.
The sequential complexity of this operation is O(max_depth()).
key | the key to look up |
va | the location to store the address of the value/access_counter |
|
private |
Increases the capacity of the hash map by replacing a data node reference with a reference to an array node containing a reference to that data node.
loc | The location to expand at |
curr_value | The current value (data node) at the location |
next_position | The position the data node belongs at the next depth. |
uint64_t tervel::containers::wf::HashMapNoDelete< Key, Value, Functor >::get_position | ( | Key & | key, |
size_t | depth | ||
) |
key | The key |
depth | The depth |
bool tervel::containers::wf::HashMapNoDelete< Key, Value, Functor >::insert | ( | Key | key, |
Value | value | ||
) |
This function returns true if the key value pair was successfully inserted.
Otherwise it returns false.
A key can fail to insert in the event the key is already present.
The sequential complexity of this operation is O(max_depth()).
key | The key to insert |
value | The key's associated value |
uint64_t tervel::containers::wf::HashMapNoDelete< Key, Value, Functor >::max_depth | ( | ) |
void tervel::containers::wf::HashMapNoDelete< Key, Value, Functor >::print_key | ( | Key & | key | ) |
Outputs the positions a key belongs in at each depth.
Used for Debugging
key | The Key |
|
inline |
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |