hashMap.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 
22 #ifndef __hashMap_hpp__
23 #define __hashMap_hpp__
24 
25 #include <unordered_map>
26 
27 #include "types.hpp"
28 #include "typeInfo.hpp"
29 #include "iOstream.hpp"
30 
31 
32 namespace pFlow
33 {
34 
35 template<class Key, class T, class Hash = std::hash<Key> >
36 class hashMap
37 :
38  public std::unordered_map<Key, T, Hash>
39 {
40 public:
41 
43 
44  using hashmapType = std::unordered_map<Key, T, Hash>;
45 
46  using iterator = typename hashmapType::iterator;
47 
48  using constIterator = typename hashmapType::const_iterator;
49 
50  using reference = typename hashmapType::reference;
51 
52  using constReference= typename hashmapType::const_reference ;
53 
54  using initList = typename std::initializer_list<T>;
55 
56  using keyType = typename hashmapType::key_type;
57 
58  using mappedType = typename hashmapType::mapped_type;
59 
60  using valueType = typename hashmapType::value_type;
61 
62 
63  TypeInfoTemplateNV("hashMap", Key);
64 
66 
67  // Empty hashMap
69  {}
70 
71  // - with initList
73  :
74  hashmapType(lst)
75  {}
76 
77  // - Copy construct
78  hashMap(const hashMapType & src)
79  :
80  hashmapType(src)
81  {}
82 
83  // - Move construct
85  :
86  hashmapType(std::move(src))
87  {}
88 
89  // - Copy assignment
91  {
92  hashmapType::operator=(rhs);
93  return *this;
94  }
95 
96  // - Move assignment
98  {
99  hashmapType::operator=( std::move(rhs));
100  return *this;
101  }
102 
104  {
105  return makeUnique<hashMapType>(*this);
106  }
107 
109  {
110  return new hashMapType(*this);
111  }
112 
114  {
115  this->clear();
116  }
117 
118 
120 
121  // Insert an item with copy operation
122  bool insertIf(const keyType& k, const mappedType & v);
123 
124  // insert an item with move operation
125  bool insertIf( keyType&& k, mappedType && v);
126 
127  // search for a key
128  bool search(const keyType k) const;
129 
130 
131  std::pair<iterator, bool> findIf(const keyType& k);
132 
133 
134  const std::pair<constIterator, bool> findIf(const keyType& k) const;
135 
136 };
137 
138 
139 template<typename T>
141 
142 template<typename T>
144 
145 template<typename T>
147 
148 template<typename T>
150 
151 template<typename T>
153 
154 template<typename T>
155 inline iOstream& printKeys(iOstream& os, const wordHashMap<T> & m);
156 
157 template<typename T>
158 inline iOstream& printKeys(iOstream& os, const labelHashMap<T> & m);
159 
160 template<typename T>
161 inline iOstream& printKeys(iOstream& os, const uint32HashMap<T> & m);
162 
163 template<typename T>
164 inline iOstream& printKeys(iOstream& os, const int64HashMap<T> & m);
165 
166 template<typename T>
167 inline iOstream& printKeys(iOstream& os, const int32HashMap<T> & m);
168 
169 
170 #include "hashMapI.hpp"
171 
172 } // pFlow
173 
174 #endif
pFlow::hashMap::TypeInfoTemplateNV
TypeInfoTemplateNV("hashMap", Key)
pFlow::hashMap::operator=
hashMapType & operator=(const hashMapType &rhs)
Definition: hashMap.hpp:90
pFlow::hashMap::clonePtr
hashMapType * clonePtr() const
Definition: hashMap.hpp:108
pFlow::hashMap< void * >::valueType
typename hashmapType::value_type valueType
Definition: hashMap.hpp:60
pFlow::hashMap< void * >::mappedType
typename hashmapType::mapped_type mappedType
Definition: hashMap.hpp:58
pFlow::hashMap::hashMap
hashMap()
Definition: hashMap.hpp:68
types.hpp
pFlow::hashMap
Definition: hashMap.hpp:36
pFlow::printKeys
iOstream & printKeys(iOstream &os, const wordHashMap< T > &m)
pFlow::hashMap::~hashMap
~hashMap()
Definition: hashMap.hpp:113
pFlow::hashMap::hashMap
hashMap(hashMapType &&src)
Definition: hashMap.hpp:84
pFlow
Definition: demComponent.hpp:28
pFlow::hashMap::findIf
std::pair< iterator, bool > findIf(const keyType &k)
Definition: hashMapI.hpp:48
pFlow::hashMap< void * >::iterator
typename hashmapType::iterator iterator
Definition: hashMap.hpp:46
pFlow::hashMap::clone
uniquePtr< hashMapType > clone() const
Definition: hashMap.hpp:103
pFlow::hashMap::operator=
hashMapType & operator=(hashMapType &&rhs)
Definition: hashMap.hpp:97
pFlow::hashMap::search
bool search(const keyType k) const
Definition: hashMapI.hpp:40
pFlow::hashMap< void * >::reference
typename hashmapType::reference reference
Definition: hashMap.hpp:50
pFlow::hashMap< void * >::hashmapType
std::unordered_map< void *, T, std::hash< void * > > hashmapType
Definition: hashMap.hpp:44
pFlow::hashMap< void * >::constReference
typename hashmapType::const_reference constReference
Definition: hashMap.hpp:52
pFlow::hashMap::hashMap
hashMap(initList lst)
Definition: hashMap.hpp:72
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::hashMap::hashMapType
hashMap< Key, T, Hash > hashMapType
Definition: hashMap.hpp:42
typeInfo.hpp
iOstream.hpp
pFlow::hashMap< void * >::initList
typename std::initializer_list< T > initList
Definition: hashMap.hpp:54
pFlow::iOstream
Definition: iOstream.hpp:53
hashMapI.hpp
m
int32 m
Definition: NBSCrossLoop.hpp:22
pFlow::hashMap< void * >::keyType
typename hashmapType::key_type keyType
Definition: hashMap.hpp:56
pFlow::hashMap::hashMap
hashMap(const hashMapType &src)
Definition: hashMap.hpp:78
pFlow::hashMap< void * >::constIterator
typename hashmapType::const_iterator constIterator
Definition: hashMap.hpp:48
pFlow::hashMap::insertIf
bool insertIf(const keyType &k, const mappedType &v)
Definition: hashMapI.hpp:23