ModErn Text Analysis
META Enumerates Textual Applications
Public Types | Public Member Functions | Private Attributes | List of all members
meta::caching::locking_map< Key, Value > Class Template Reference

A simple wrapper around a std::unordered_map that uses an internal mutex for synchronization safety. More...

#include <locking_map.h>

Public Types

using iterator = typename std::unordered_map< Key, Value >::iterator
 iterator type for locking_maps
 
using const_iterator = typename std::unordered_map< Key, Value >::const_iterator
 const_iterator type for locking_maps
 

Public Member Functions

 locking_map ()=default
 Default constructable.
 
 locking_map (locking_map &&)
 locking_map may be move constructed.
 
locking_mapoperator= (locking_map rhs)
 Locking map may be assigned. More...
 
void swap (locking_map &other)
 Swaps the current instance of locking_map with the paramter. More...
 
void insert (const Key &key, const Value &value)
 Inserts a given (key, value) pair into the map. More...
 
template<class... Args>
void emplace (Args &&...args)
 Inserts a (key, value) pair into the map, using in-place construction. More...
 
util::optional< Value > find (const Key &key) const
 Finds a value in the map. More...
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 

Private Attributes

std::unordered_map< Key, Value > map_
 the underlying map used for storage
 
std::mutex mutables_
 the mutex that synchronizes accesses into the map
 

Detailed Description

template<class Key, class Value>
class meta::caching::locking_map< Key, Value >

A simple wrapper around a std::unordered_map that uses an internal mutex for synchronization safety.

Member Function Documentation

template<class Key , class Value >
locking_map< Key, Value > & meta::caching::locking_map< Key, Value >::operator= ( locking_map< Key, Value >  rhs)

Locking map may be assigned.

Returns
the current locking_map
template<class Key , class Value >
void meta::caching::locking_map< Key, Value >::swap ( locking_map< Key, Value > &  other)

Swaps the current instance of locking_map with the paramter.

Parameters
otherthe map to swap with
template<class Key , class Value >
void meta::caching::locking_map< Key, Value >::insert ( const Key &  key,
const Value &  value 
)

Inserts a given (key, value) pair into the map.

Parameters
key
value
template<class Key , class Value >
template<class... Args>
void meta::caching::locking_map< Key, Value >::emplace ( Args &&...  args)

Inserts a (key, value) pair into the map, using in-place construction.

Parameters
argsthe parameters to be used for creating the (key, value) pair
template<class Key , class Value >
util::optional< Value > meta::caching::locking_map< Key, Value >::find ( const Key &  key) const

Finds a value in the map.

If it exists, the optional will be engaged, otherwise, it will be disengaged.

Parameters
keythe key to find the corresponding value for
Returns
an optional that may contain the value, if found
template<class Key , class Value >
auto meta::caching::locking_map< Key, Value >::begin ( )
Returns
an iterator to the beginning of the map
template<class Key , class Value >
auto meta::caching::locking_map< Key, Value >::end ( )
Returns
an iterator to the end of the map
template<class Key , class Value >
auto meta::caching::locking_map< Key, Value >::begin ( ) const
Returns
a const_iterator to the beginning of the map
template<class Key , class Value >
auto meta::caching::locking_map< Key, Value >::end ( ) const
Returns
a const_iterator to the end of the map

The documentation for this class was generated from the following files: