www.mooseframework.org
HashMap.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef HASHMAP_H
16 #define HASHMAP_H
17 
19 #include "libmesh/threads.h"
20 
21 #include <unordered_map>
22 
23 template <typename Key, typename T>
24 class HashMap : public std::unordered_map<Key, T>
25 {
26 public:
27  inline T & operator[](const Key & k)
28  {
29  libMesh::Threads::spin_mutex::scoped_lock lock(spin_mutex);
30 
31  return std::unordered_map<Key, T>::operator[](k);
32  }
33 
34  inline bool contains(const Key & key) { return this->find(key) != this->end(); }
35 
36 private:
37  libMesh::Threads::spin_mutex spin_mutex;
38 };
39 
40 #endif /* HASHMAP_H */
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts...
Definition: HashMap.h:24
T & operator[](const Key &k)
Definition: HashMap.h:27
bool contains(const Key &key)
Definition: HashMap.h:34
libMesh::Threads::spin_mutex spin_mutex
Definition: HashMap.h:37