https://mooseframework.inl.gov
Loading...
Searching...
No Matches
HashMap.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
13#include "libmesh/threads.h"
14
15#include <unordered_map>
16
17template <typename Key, typename T>
18class HashMap : public std::unordered_map<Key, T>
19{
20public:
21 inline T & operator[](const Key & k)
22 {
24 return std::unordered_map<Key, T>::operator[](k);
25 }
26
27 inline std::size_t erase(const Key & k)
28 {
30 return std::unordered_map<Key, T>::erase(k);
31 }
32
33 using typename std::unordered_map<Key, T>::const_iterator;
34 using typename std::unordered_map<Key, T>::iterator;
35
36 inline iterator find(const Key & k)
37 {
39 return std::unordered_map<Key, T>::find(k);
40 }
41
42 inline const_iterator find(const Key & k) const
43 {
45 return std::unordered_map<Key, T>::find(k);
46 }
47
48 inline bool contains(const Key & key) const { return this->find(key) != this->end(); }
49
50private:
52};
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts.
Definition HashMap.h:19
iterator find(const Key &k)
Definition HashMap.h:36
bool contains(const Key &key) const
Definition HashMap.h:48
const_iterator find(const Key &k) const
Definition HashMap.h:42
std::size_t erase(const Key &k)
Definition HashMap.h:27
libMesh::Threads::spin_mutex spin_mutex
Definition HashMap.h:51
T & operator[](const Key &k)
Definition HashMap.h:21