16 #if !defined(KRATOS_POINTER_HASH_MAP_SET_H_INCLUDED )
17 #define KRATOS_POINTER_HASH_MAP_SET_H_INCLUDED
26 #include <type_traits>
27 #include <unordered_map>
65 template<
class TDataType,
66 class THashType = std::hash<TDataType>,
67 class TGetKeyType = SetIdentityFunction<TDataType>,
81 typedef decltype(std::declval<TGetKeyType>()(std::declval<TDataType>()))
key_type;
102 class iterator_adaptor
106 using iterator_category = std::forward_iterator_tag;
113 iterator_adaptor(
const iterator_adaptor& it) : map_iterator(it.map_iterator) {}
114 iterator_adaptor& operator++() { map_iterator++;
return *
this; }
115 iterator_adaptor operator++(
int) { iterator_adaptor
tmp(*
this); operator++();
return tmp; }
116 bool operator==(
const iterator_adaptor&
rhs)
const {
return map_iterator ==
rhs.map_iterator; }
117 bool operator!=(
const iterator_adaptor&
rhs)
const {
return map_iterator !=
rhs.map_iterator; }
119 pointer_type operator->()
const {
return map_iterator->second; }
121 ptr_iterator const& base()
const {
return map_iterator; }
124 class const_iterator_adaptor
128 using iterator_category = std::forward_iterator_tag;
135 const_iterator_adaptor(
const const_iterator_adaptor& it) : map_iterator(it.map_iterator) {}
136 const_iterator_adaptor& operator++() { map_iterator++;
return *
this; }
137 const_iterator_adaptor operator++(
int) { const_iterator_adaptor
tmp(*
this); operator++();
return tmp; }
138 bool operator==(
const const_iterator_adaptor&
rhs)
const {
return map_iterator ==
rhs.map_iterator; }
139 bool operator!=(
const const_iterator_adaptor&
rhs)
const {
return map_iterator !=
rhs.map_iterator; }
141 pointer_type operator->()
const {
return map_iterator->second; }
163 template <
class TInputIteratorType>
167 for(; First != Last; ++First)
172 : mData(rOther.mData) {}
188 mData = rOther.mData;
195 KRATOS_DEBUG_ERROR_IF(mData.find(Key) == mData.end()) <<
"The key: " << Key <<
" is not available in the map" << std::endl;
196 return *(mData.find(Key)->second);
201 KRATOS_DEBUG_ERROR_IF(mData.find(Key) == mData.end()) <<
"The key: " << Key <<
" is not available in the map" << std::endl;
202 return mData.find(Key)->second;
207 return (mData == r.mData);
212 return (mData != r.mData);
238 return mData.begin();
242 return mData.begin();
256 return *(mData.front().second);
261 return *(mData.front().second);
266 return *(mData.back().second);
271 return *(mData.back().second);
291 mData.swap(rOther.mData);
294 template<
class TOtherDataType>
297 TDataType* p_new_data =
new TDataType(rData);
298 return mData.insert(ContainerType::value_type(TGetKeyOf(rData), p_new_data));
304 typename ContainerType::value_type item(key, pData);
305 std::pair<typename ContainerType::iterator, bool> result = mData.insert(item);
312 template <
class InputIterator>
313 void insert(InputIterator First, InputIterator Last)
315 for(; First != Last; ++First)
322 return mData.erase(pos.base());
327 return mData.erase(Key);
332 return mData.erase( first.base(), last.base() );
342 return mData.find(Key);
347 return mData.find(Key);
352 return find(Key) == mData.end() ? 0 : 1;
357 mData.reserve(reservedsize);
361 return mData.capacity();
389 return mData.empty();
400 std::stringstream buffer;
401 buffer <<
"Pointer hash map set (size = " <<
size() <<
") : ";
416 std::copy(
begin(),
end(), std::ostream_iterator<TDataType>(rOStream,
"\n "));
488 return TGetKeyType()(*i);
493 return TGetKeyType()(**i);
498 return TGetKeyType()(
i);
509 virtual void save(
Serializer& rSerializer)
const
516 rSerializer.
save(
"E",
i->second);
528 rSerializer.
load(
"E",
p);
575 template<
class TDataType,
585 rOStream << std::endl;
PointerHashMapSet is a hash implemenetation of the PointerVectorSet.
Definition: pointer_hash_map_set.h:70
void clear()
Definition: pointer_hash_map_set.h:335
void reserve(int reservedsize)
Definition: pointer_hash_map_set.h:355
ContainerType::iterator ptr_iterator
Definition: pointer_hash_map_set.h:93
ContainerType::difference_type difference_type
Definition: pointer_hash_map_set.h:95
void swap(PointerHashMapSet &rOther)
Definition: pointer_hash_map_set.h:289
PointerHashMapSet & operator=(const PointerHashMapSet &rOther)
Definition: pointer_hash_map_set.h:186
iterator end()
Definition: pointer_hash_map_set.h:228
const_iterator end() const
Definition: pointer_hash_map_set.h:232
bool operator!=(const PointerHashMapSet &r) const
Definition: pointer_hash_map_set.h:210
TDataType value_type
Definition: pointer_hash_map_set.h:85
~PointerHashMapSet()
Destructor.
Definition: pointer_hash_map_set.h:179
bool operator==(const PointerHashMapSet &r) const
Definition: pointer_hash_map_set.h:205
PointerHashMapSet(const ContainerType &rContainer)
Definition: pointer_hash_map_set.h:174
TPointerType pointer_type
Definition: pointer_hash_map_set.h:86
TDataType & reference
Definition: pointer_hash_map_set.h:87
iterator_adaptor iterator
Definition: pointer_hash_map_set.h:153
pointer_type & operator()(const key_type &Key)
Definition: pointer_hash_map_set.h:199
const_iterator find(const key_type &Key) const
Definition: pointer_hash_map_set.h:345
std::string Info() const
Turn back information as a string.
Definition: pointer_hash_map_set.h:398
iterator begin()
Definition: pointer_hash_map_set.h:220
ContainerType & GetContainer()
Definition: pointer_hash_map_set.h:370
ptr_iterator ptr_begin()
Definition: pointer_hash_map_set.h:236
ContainerType::const_iterator ptr_const_iterator
Definition: pointer_hash_map_set.h:94
TDataType & operator[](const key_type &Key)
Definition: pointer_hash_map_set.h:193
const_reference back() const
Definition: pointer_hash_map_set.h:268
const_reference front() const
Definition: pointer_hash_map_set.h:258
iterator find(const key_type &Key)
Definition: pointer_hash_map_set.h:340
reference back()
Definition: pointer_hash_map_set.h:263
iterator erase(iterator first, iterator last)
Definition: pointer_hash_map_set.h:330
const ContainerType & GetContainer() const
Definition: pointer_hash_map_set.h:376
const_iterator_adaptor const_iterator
Definition: pointer_hash_map_set.h:154
ContainerType::size_type size_type
Definition: pointer_hash_map_set.h:92
int capacity()
Definition: pointer_hash_map_set.h:359
bool empty() const
Definition: pointer_hash_map_set.h:387
KRATOS_CLASS_POINTER_DEFINITION(PointerHashMapSet)
Pointer definition of PointerHashMapSet.
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: pointer_hash_map_set.h:414
PointerHashMapSet(const PointerHashMapSet &rOther)
Definition: pointer_hash_map_set.h:171
size_type count(const key_type &Key)
Definition: pointer_hash_map_set.h:350
const TDataType & const_reference
Definition: pointer_hash_map_set.h:88
reference front()
Definition: pointer_hash_map_set.h:253
decltype(std::declval< TGetKeyType >()(std::declval< TDataType >())) typedef key_type
Key type for searching in this container.
Definition: pointer_hash_map_set.h:81
void insert(InputIterator First, InputIterator Last)
Definition: pointer_hash_map_set.h:313
iterator insert(const TOtherDataType &rData)
Definition: pointer_hash_map_set.h:295
PointerHashMapSet(TInputIteratorType First, TInputIteratorType Last, size_type NewMaxBufferSize=1)
Definition: pointer_hash_map_set.h:165
size_type size() const
Definition: pointer_hash_map_set.h:274
size_type erase(key_type const &Key)
Definition: pointer_hash_map_set.h:325
ptr_iterator ptr_end()
Definition: pointer_hash_map_set.h:244
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: pointer_hash_map_set.h:408
std::unordered_map< typename std::remove_reference< key_type >::type, TPointerType, THashType > ContainerType
Definition: pointer_hash_map_set.h:90
iterator insert(TPointerType pData)
Definition: pointer_hash_map_set.h:301
iterator erase(iterator pos)
Definition: pointer_hash_map_set.h:320
TDataType data_type
Data type stores in this container.
Definition: pointer_hash_map_set.h:84
ptr_const_iterator ptr_end() const
Definition: pointer_hash_map_set.h:248
PointerHashMapSet()
Default constructor.
Definition: pointer_hash_map_set.h:161
const_iterator begin() const
Definition: pointer_hash_map_set.h:224
ptr_const_iterator ptr_begin() const
Definition: pointer_hash_map_set.h:240
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void load(std::string const &rTag, TDataType &rObject)
Definition: serializer.h:207
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Expression::Pointer operator*(const Expression::ConstPointer &rpLeft, const double Right)
std::shared_ptr< T > shared_ptr
Definition: smart_pointers.h:27
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
rhs
Definition: generate_frictional_mortar_condition.py:297
type
Definition: generate_gid_list_file.py:35
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98
def load(f)
Definition: ode_solve.py:307
tuple const
Definition: ode_solve.py:403
p
Definition: sensitivityMatrix.py:52
namespace
Definition: array_1d.h:793
integer i
Definition: TensorModule.f:17
Configure::ContainerType ContainerType
Definition: transfer_utility.h:247