Template Class LocalHashmap

Class Documentation

template <typename KTYPE, typename VTYPE, typename KEY_COMPARE = MemCmp<KTYPE>, typename INSERTER = Overwriter<VTYPE>>
class LocalHashmap

The LocalHashmap data structure.

SHAD’s LocalHashmap is a “local”, thread-safe, associative container. LocalHashmaps can be used ONLY on the Locality on which they are created.

Template Parameters
  • KTYPE: type of the hashmap keys.
  • VTYPE: type of the hashmap values.
  • KEY_COMPARE: key comparison function; default is MemCmp<KTYPE>.
  • INSERTER: default is Overwriter (i.e. insertions overwrite previous values associated to the same key, if any).

Public Types

template<>
using value_type = std::pair<KTYPE, VTYPE>
template<>
using iterator = lmap_iterator<LocalHashmap<KTYPE, VTYPE, KEY_COMPARE, INSERTER>, const std::pair<KTYPE, VTYPE>>
template<>
using const_iterator = lmap_iterator<LocalHashmap<KTYPE, VTYPE, KEY_COMPARE, INSERTER>, const std::pair<KTYPE, VTYPE>>

Public Functions

LocalHashmap(const size_t numInitBuckets)

Constructor.

Parameters
  • numInitBuckets: initial number of Buckets.

size_t Size() const

Size of the hashmap (number of entries).

Return
the size of the hashmap.

std::pair<typename LocalHashmap<KTYPE, VTYPE, KEY_COMPARE, INSERTER>::iterator, bool> Insert(const KTYPE &key, const VTYPE &value)

Insert a key-value pair in the hashmap.

Return
an iterator to the inserted value
Parameters
  • key: the key.
  • value: the value to copy into the hashMap.

template <typename ELTYPE>
std::pair<iterator, bool> Insert(const KTYPE &key, const ELTYPE &value)
void AsyncInsert(rt::Handle &handle, const KTYPE &key, const VTYPE &value)

Asynchronously Insert a key-value pair in the hashmap.

Warning
Asynchronous operations are guaranteed to have completed only after calling the rt::waitForCompletion(rt::Handle &handle) method.
Return
a pointer to the value if the the key-value was inserted or a pointer to a previously inserted value.
Parameters
  • handle: Reference to the handle to be used to wait for completion.
  • key: the key.
  • value: the value to copy into the hashMap.

template <typename ELTYPE>
void AsyncInsert(rt::Handle &handle, const KTYPE &key, const ELTYPE &value)
void Erase(const KTYPE &key)

Remove a key-value pair from the hashmap.

Parameters
  • key: the key.

void AsyncErase(rt::Handle &handle, const KTYPE &key)

Asynchronously remove a key-value pair from the hashmap.

Warning
Asynchronous operations are guaranteed to have completed. only after calling the rt::waitForCompletion(rt::Handle &handle) method.
Parameters
  • handle: Reference to the handle. to be used to wait for completion.
  • key: the key.

void Clear()

Clear the content of the hashmap.

bool Lookup(const KTYPE &key, VTYPE *res)

Get the value associated to a key.

Return
true if the entry is found, false otherwise.
Parameters
  • key: the key.
  • res: the address where to store the value, if the the key-value is found.

VTYPE *Lookup(const KTYPE &key)

Get the value associated to a key.

Return
a pointer to the value if the the key-value is found and nullptr if it does not exists.
Parameters
  • key: the key.

void AsyncLookup(rt::Handle &handle, const KTYPE &key, VTYPE **res)

Asynchronously get the value associated to a key.

Warning
Asynchronous operations are guaranteed to have completed only after calling the rt::waitForCompletion(rt::Handle &handle) method.
Parameters
  • handle: Reference to the handle to be used to wait for completion.
  • key: the key.
  • res: the address where to storethe pointer to the value if the the key-value was found, or a nullptr otherwise.

void Lookup(const KTYPE &key, LookupResult *res)

Lookup method.

Parameters
  • key: The key.
  • res: The result of the lookup operation.

void AsyncLookup(rt::Handle &handle, const KTYPE &key, LookupResult *res)

Asynchronous lookup method.

Warning
Asynchronous operations are guaranteed to have completed. only after calling the rt::waitForCompletion(rt::Handle &handle) method.
Parameters
  • handle: Reference to the handle. to be used to wait for completion.
  • key: The key.
  • res: The result of the lookup operation.

template <typename ApplyFunT, typename... Args>
void Apply(const KTYPE &key, ApplyFunT &&function, Args&... args)

Apply a user-defined function to a key-value pair.

Template Parameters
  • ApplyFunT: User-defined function type. The function prototype should be:
    void(const KTYPE&, VTYPE&, Args&);
    
  • ...Args: Types of the function arguments.
Parameters
  • key: The key.
  • function: The function to apply.
  • args: The function arguments.

template <typename ApplyFunT, typename... Args>
void AsyncApply(rt::Handle &handle, const KTYPE &key, ApplyFunT &&function, Args&... args)

Asynchronously apply a user-defined function to a key-value pair.

Template Parameters
  • ApplyFunT: User-defined function type. The function prototype should be:
    void(rt::Handle &handle, const KTYPE&, VTYPE&, Args&);
    
  • ...Args: Types of the function arguments.
Parameters
  • handle: Reference to the handle.
  • key: The key.
  • function: The function to apply.
  • args: The function arguments.

template <typename ApplyFunT, typename... Args>
void ForEachEntry(ApplyFunT &&function, Args&... args)

Apply a user-defined function to each key-value pair.

Template Parameters
  • ApplyFunT: User-defined function type. The function prototype should be:
    void(const KTYPE&, VTYPE&, Args&);
    
  • ...Args: Types of the function arguments.
Parameters
  • function: The function to apply.
  • args: The function arguments.

template <typename ApplyFunT, typename... Args>
void AsyncForEachEntry(rt::Handle &handle, ApplyFunT &&function, Args&... args)

Asynchronously apply a user-defined function to each key-value pair.

Warning
Asynchronous operations are guaranteed to have completed. only after calling the rt::waitForCompletion(rt::Handle &handle) method.
Template Parameters
  • ApplyFunT: User-defined function type. The function prototype should be:
    void(shad::rt::Handle&, const KTYPE&, VTYPE&, Args&);
    
  • ...Args: Types of the function arguments.
Parameters
  • handle: Reference to the handle. to be used to wait for completion.
  • function: The function to apply.
  • args: The function arguments.

template <typename ApplyFunT, typename... Args>
void ForEachKey(ApplyFunT &&function, Args&... args)

Apply a user-defined function to each key.

Template Parameters
  • ApplyFunT: User-defined function type. The function prototype should be:
    void(const KTYPE&, Args&);
    
  • ...Args: Types of the function arguments.
Parameters
  • function: The function to apply.
  • args: The function arguments.

template <typename ApplyFunT, typename... Args>
void AsyncForEachKey(rt::Handle &handle, ApplyFunT &&function, Args&... args)

Asynchronously apply a user-defined function to each key.

Warning
Asynchronous operations are guaranteed to have completed. only after calling the rt::waitForCompletion(rt::Handle &handle) method.
Template Parameters
  • ApplyFunT: User-defined function type. The function prototype should be:
    void(shad::rt::Handle&, const KTYPE&, Args&);
    
  • ...Args: Types of the function arguments.
Parameters
  • handle: Reference to the handle. to be used to wait for completion.
  • function: The function to apply.
  • args: The function arguments.

void PrintAllEntries()

Print all the entries in the hashmap.

Warning
std::ostream & operator<< must be defined for both KTYPE and VTYPE

iterator begin()
iterator end()
const_iterator cbegin()
const_iterator cend()
template <typename ELTYPE>
std::pair<typename LocalHashmap<KTYPE, VTYPE, KEY_COMPARE, INSERTER>::iterator, bool> Insert(const KTYPE &key, const ELTYPE &value)

Friends

friend shad::LocalHashmap::lmap_iterator< LocalHashmap< KTYPE, VTYPE, KEY_COMPARE, INSERTER >, const std::pair< KTYPE, VTYPE > >
struct LookupResult

Result for the Lookup(const KTYPE&, LookupResult*) and AsyncLookup(rt::Handle&, const KTYPE&, LookupResult*) methods.

Public Members

template<>
bool found

True if the key has been found in the Hashmap.

template<>
VTYPE value

The value associated with the key.