www.cemf.ir
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 hasher = typename hashmapType::hasher;
47 
48  using iterator = typename hashmapType::iterator;
49 
50  using constIterator = typename hashmapType::const_iterator;
51 
52  using reference = typename hashmapType::reference;
53 
54  using constReference= typename hashmapType::const_reference ;
55 
56  using initList = typename std::initializer_list<T>;
57 
58  using keyType = typename hashmapType::key_type;
59 
60  using mappedType = typename hashmapType::mapped_type;
61 
62  using valueType = typename hashmapType::value_type;
63 
64 
65  TypeInfoTemplateNV11("hashMap", Key);
66 
68 
69  // Empty hashMap
71  {}
72 
73  // - with initList
75  :
76  hashmapType(lst)
77  {}
78 
79  // - Copy construct
80  hashMap(const hashMapType & src) = default;
81 
82  // - Move construct
83  hashMap( hashMapType&& src) = default;
84 
85  // - Copy assignment
86  hashMapType& operator=(const hashMapType& rhs) = default;
87 
88  // - Move assignment
89  hashMapType& operator=(hashMapType&& rhs) = default;
90 
92  {
93  return makeUnique<hashMapType>(*this);
94  }
95 
96  ~hashMap() = default;
97 
98 
100 
101  // Insert an item with copy operation
102  bool insertIf(const keyType& k, const mappedType & v);
103 
104  // insert an item with move operation
105  bool insertIf( keyType&& k, mappedType && v);
106 
107  // search for a key
108  bool search(const keyType k) const;
109 
110 
111  std::pair<iterator, bool> findIf(const keyType& k);
112 
113 
114  const std::pair<constIterator, bool> findIf(const keyType& k) const;
115 
116 };
117 
118 
119 template<typename T>
121 
122 template<typename T>
124 
125 template<typename T>
127 
128 template<typename T>
130 
131 template<typename T>
133 
134 template<typename T>
135 inline iOstream& printKeys(iOstream& os, const wordHashMap<T> & m);
136 
137 template<typename T>
138 inline iOstream& printKeys(iOstream& os, const uint64HashMap<T> & m);
139 
140 template<typename T>
141 inline iOstream& printKeys(iOstream& os, const uint32HashMap<T> & m);
142 
143 template<typename T>
144 inline iOstream& printKeys(iOstream& os, const int64HashMap<T> & m);
145 
146 template<typename T>
147 inline iOstream& printKeys(iOstream& os, const int32HashMap<T> & m);
148 
149 
150 #include "hashMapI.hpp"
151 
152 } // pFlow
153 
154 #endif
pFlow::hashMap< void * >::valueType
typename hashmapType::value_type valueType
Definition: hashMap.hpp:62
pFlow::hashMap< void * >::mappedType
typename hashmapType::mapped_type mappedType
Definition: hashMap.hpp:60
pFlow::hashMap::hashMap
hashMap()
Definition: hashMap.hpp:70
types.hpp
pFlow::hashMap
Definition: hashMap.hpp:36
pFlow::printKeys
iOstream & printKeys(iOstream &os, const wordHashMap< T > &m)
pFlow::hashMap< void * >::hasher
typename hashmapType::hasher hasher
Definition: hashMap.hpp:46
pFlow::hashMap::TypeInfoTemplateNV11
TypeInfoTemplateNV11("hashMap", Key)
pFlow::hashMap::~hashMap
~hashMap()=default
pFlow
Definition: demGeometry.hpp:27
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:48
pFlow::hashMap::clone
uniquePtr< hashMapType > clone() const
Definition: hashMap.hpp:91
pFlow::hashMap::search
bool search(const keyType k) const
Definition: hashMapI.hpp:40
pFlow::hashMap< void * >::reference
typename hashmapType::reference reference
Definition: hashMap.hpp:52
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:54
pFlow::hashMap::hashMap
hashMap(initList lst)
Definition: hashMap.hpp:74
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
pFlow::hashMap::hashMapType
hashMap< Key, T, Hash > hashMapType
Definition: hashMap.hpp:42
typeInfo.hpp
iOstream.hpp
pFlow::hashMap::operator=
hashMapType & operator=(const hashMapType &rhs)=default
pFlow::hashMap< void * >::initList
typename std::initializer_list< T > initList
Definition: hashMap.hpp:56
m
uint32 m
Definition: NBSLoop.hpp:22
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
hashMapI.hpp
pFlow::hashMap< void * >::keyType
typename hashmapType::key_type keyType
Definition: hashMap.hpp:58
pFlow::hashMap< void * >::constIterator
typename hashmapType::const_iterator constIterator
Definition: hashMap.hpp:50
pFlow::hashMap::insertIf
bool insertIf(const keyType &k, const mappedType &v)
Definition: hashMapI.hpp:23