ModErn Text Analysis
META Enumerates Textual Applications
locking_map.h
Go to the documentation of this file.
1 
9 #ifndef META_LOCKING_MAP_H_
10 #define META_LOCKING_MAP_H_
11 
12 #include <unordered_map>
13 #include <memory>
14 #include <mutex>
15 
16 #include "util/optional.h"
17 
18 namespace meta
19 {
20 namespace caching
21 {
22 
27 template <class Key, class Value>
29 {
30  public:
34  locking_map() = default;
35 
40 
46 
51  void swap(locking_map& other);
52 
58  void insert(const Key& key, const Value& value);
59 
66  template <class... Args>
67  void emplace(Args&&... args);
68 
76  util::optional<Value> find(const Key& key) const;
77 
79  using iterator = typename std::unordered_map<Key, Value>::iterator;
81  using const_iterator =
82  typename std::unordered_map<Key, Value>::const_iterator;
83 
87  iterator begin();
88 
92  iterator end();
93 
97  const_iterator begin() const;
98 
102  const_iterator end() const;
103 
104  private:
106  std::unordered_map<Key, Value> map_;
108  mutable std::mutex mutables_;
109 };
110 }
111 }
112 
114 #endif
std::mutex mutables_
the mutex that synchronizes accesses into the map
Definition: locking_map.h:108
void swap(locking_map &other)
Swaps the current instance of locking_map with the paramter.
Definition: locking_map.tcc:26
util::optional< Value > find(const Key &key) const
Finds a value in the map.
Definition: locking_map.tcc:47
typename std::unordered_map< Key, Value >::const_iterator const_iterator
const_iterator type for locking_maps
Definition: locking_map.h:82
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
locking_map & operator=(locking_map rhs)
Locking map may be assigned.
Definition: locking_map.tcc:19
A simple wrapper around a std::unordered_map that uses an internal mutex for synchronization safety...
Definition: locking_map.h:28
void emplace(Args &&...args)
Inserts a (key, value) pair into the map, using in-place construction.
Definition: locking_map.tcc:40
iterator begin()
Definition: locking_map.tcc:57
void insert(const Key &key, const Value &value)
Inserts a given (key, value) pair into the map.
Definition: locking_map.tcc:32
typename std::unordered_map< Key, Value >::iterator iterator
iterator type for locking_maps
Definition: locking_map.h:79
iterator end()
Definition: locking_map.tcc:63
std::unordered_map< Key, Value > map_
the underlying map used for storage
Definition: locking_map.h:106
locking_map()=default
Default constructable.