15 #if !defined(KRATOS_POINTER_VECTOR_MAP_H_INCLUDED )
16 #define KRATOS_POINTER_VECTOR_MAP_H_INCLUDED
65 template<
class TKeyType,
class TDataType,
67 class TCompareType = std::less<TKeyType>,
69 class TContainerType = std::vector<std::pair<TKeyType, TPointerType> > >
96 typedef typename TContainerType::size_type
size_type;
114 std::unique(mData.begin(), mData.end(), EqualKeyTo());
127 mData = rOther.mData;
128 mSortedPartSize = rOther.mSortedPartSize;
137 if(mData.size() - mSortedPartSize >= mMaxBufferSize)
140 sorted_part_end = mData.end();
143 sorted_part_end = mData.begin() + mSortedPartSize;
145 pair_iterator i(std::lower_bound(mData.begin(), sorted_part_end, Key, CompareKey()));
146 if (
i == sorted_part_end)
149 return *(mData.insert(sorted_part_end,
value_type(Key, TPointerType(
new TDataType)))->second);
153 if((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(Key))) == mData.end())
155 mData.push_back(
value_type(Key, TPointerType(
new TDataType)));
156 return *((--mData.end())->second);
166 if(mData.size() - mSortedPartSize >= mMaxBufferSize)
169 sorted_part_end = mData.end();
172 sorted_part_end = mData.begin() + mSortedPartSize;
174 pair_iterator i(std::lower_bound(mData.begin(), sorted_part_end, Key, CompareKey()));
175 if (
i == sorted_part_end)
178 return (mData.insert(sorted_part_end,
value_type(Key, TPointerType(
new TDataType)))->second);
182 if((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(Key))) == mData.end())
184 mData.push_back(
value_type(Key, TPointerType(
new TDataType)));
185 return ((--mData.end())->second);
230 return mData.begin();
234 return mData.begin();
246 return mData.rbegin();
250 return mData.rbegin();
264 return *(mData.front()->second);
269 return *(mData.front()->second);
274 return *(mData.back()->second);
279 return *(mData.back()->second);
289 return mData.max_size();
294 return TCompareType();
299 mData.swap(rOther.mData);
311 if(mData.size() - mSortedPartSize >= mMaxBufferSize)
314 sorted_part_end = mData.end();
317 sorted_part_end = mData.begin() + mSortedPartSize;
319 pair_iterator i(std::lower_bound(mData.begin(), sorted_part_end, Key, CompareKey()));
320 if (
i == sorted_part_end)
323 return (mData.insert(sorted_part_end,
value_type(Key, TPointerType(
new TDataType(rData)))));
327 if((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(Key))) == mData.end())
329 mData.push_back(
value_type(Key, TPointerType(
new TDataType)));
332 *(
i->second) = rData;
340 if(mData.size() - mSortedPartSize >= mMaxBufferSize)
343 sorted_part_end = mData.end();
346 sorted_part_end = mData.begin() + mSortedPartSize;
348 pair_iterator i(std::lower_bound(mData.begin(), sorted_part_end, Key, CompareKey()));
349 if (
i == sorted_part_end)
352 return mData.insert(sorted_part_end,
value_type(Key, pData));
356 if((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(Key))) == mData.end())
362 *(
i->second) = *pData;
368 return iterator(mData.erase(pos.base()));
373 return iterator( mData.erase( first.base(), last.base() ) );
390 if(mData.size() - mSortedPartSize >= mMaxBufferSize)
393 sorted_part_end = mData.end();
396 sorted_part_end = mData.begin() + mSortedPartSize;
398 pair_iterator i(std::lower_bound(mData.begin(), sorted_part_end, Key, CompareKey()));
399 if (
i == sorted_part_end || (Key !=
i->first))
400 if((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(Key))) == mData.end())
411 if (
i == sorted_part_end || (Key !=
i->first))
412 if((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(Key))) == mData.end())
420 return find(Key) == mData.end() ? 0 : 1;
428 if(mData.size() - mSortedPartSize >= mMaxBufferSize)
431 sorted_part_end = mData.end();
434 sorted_part_end = mData.begin() + mSortedPartSize;
436 pair_iterator i(std::lower_bound(mData.begin(), sorted_part_end, Key, CompareKey()));
437 if (
i == sorted_part_end){
438 if((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(Key))) == mData.end())
440 KRATOS_ERROR << Key <<
" not found in this map" << std::endl;
450 sorted_part_end = mData.begin() + mSortedPartSize;
452 pair_iterator i(std::lower_bound(mData.begin(), sorted_part_end, Key, CompareKey()));
453 if (
i == sorted_part_end){
454 if((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(Key))) == mData.end())
456 KRATOS_ERROR << Key <<
" not found in this map" << std::endl;
466 std::sort(mData.begin(), mData.end(), CompareKey());
467 mSortedPartSize = mData.size();
491 return mMaxBufferSize;
501 mMaxBufferSize = NewSize;
509 return mSortedPartSize;
518 mSortedPartSize = NewSize;
527 return mData.empty();
532 return (mSortedPartSize == mData.size());
542 std::stringstream buffer;
543 buffer <<
"Pointer vector map (size = " <<
size() <<
") : ";
557 for(
typename TContainerType::const_iterator
i = mData.begin() ;
i != mData.end() ;
i++)
558 rOStream <<
"(" <<
i->first <<
" , " << *(
i->second) <<
")" << std::endl;
612 return TCompareType()(
a.first,
b);
616 return TCompareType()(
a,
b.first);
620 return TCompareType()(
a.first,
b.first);
635 return a.first ==
b.first;
639 return a.first == mKey;
651 TContainerType mData;
670 virtual void save(
Serializer& rSerializer)
const
677 rSerializer.
save(
"Key", mData[
i].first);
678 rSerializer.
save(
"Data", mData[
i].second);
681 rSerializer.
save(
"Sorted Part Size",mSortedPartSize);
682 rSerializer.
save(
"Max Buffer Size",mMaxBufferSize);
694 rSerializer.load(
"Key", mData[
i].first);
695 rSerializer.load(
"Data", mData[
i].second);
698 rSerializer.load(
"Sorted Part Size",mSortedPartSize);
699 rSerializer.load(
"Max Buffer Size",mMaxBufferSize);
735 template<
class TDataType,
739 class TContainerType>
744 template<
class TDataType,
748 class TContainerType>
753 rOStream << std::endl;
PointerVectorMap is a sorted associative container like stl map but using a vector to store pointers ...
Definition: pointer_vector_map.h:71
reverse_iterator rbegin()
Definition: pointer_vector_map.h:212
~PointerVectorMap()
Destructor.
Definition: pointer_vector_map.h:118
TContainerType & GetContainer()
Definition: pointer_vector_map.h:475
const_iterator end() const
Definition: pointer_vector_map.h:208
void swap(PointerVectorMap &rOther)
Definition: pointer_vector_map.h:297
TContainerType::size_type size_type
Definition: pointer_vector_map.h:96
void Sort()
Definition: pointer_vector_map.h:464
bool IsSorted() const
Definition: pointer_vector_map.h:530
size_type count(const key_type &Key)
Definition: pointer_vector_map.h:418
iterator erase(const key_type &k)
Definition: pointer_vector_map.h:376
PointerVectorMapIterator< typename TContainerType::const_iterator, TDataType > const_iterator
Definition: pointer_vector_map.h:92
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: pointer_vector_map.h:549
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: pointer_vector_map.h:555
TDataType & reference
Definition: pointer_vector_map.h:87
TDataType & at(const key_type &Key) const
Definition: pointer_vector_map.h:447
const TContainerType & GetContainer() const
Definition: pointer_vector_map.h:481
iterator erase(iterator first, iterator last)
Definition: pointer_vector_map.h:371
TContainerType::const_reverse_iterator pair_const_reverse_iterator
Definition: pointer_vector_map.h:100
TDataType & at(const key_type &Key)
Definition: pointer_vector_map.h:424
iterator erase(iterator pos)
Definition: pointer_vector_map.h:366
pair_iterator pair_end()
Definition: pointer_vector_map.h:236
pair_reverse_iterator pair_rbegin()
Definition: pointer_vector_map.h:244
reference back()
Definition: pointer_vector_map.h:271
PointerVectorMapIterator< typename TContainerType::iterator, TDataType > iterator
Definition: pointer_vector_map.h:91
const TDataType & const_reference
Definition: pointer_vector_map.h:88
iterator insert(key_type const &Key, const TPointerType pData)
Definition: pointer_vector_map.h:336
TDataType data_type
data type stores in this container.
Definition: pointer_vector_map.h:83
TContainerType::const_iterator pair_const_iterator
Definition: pointer_vector_map.h:98
pair_const_iterator pair_end() const
Definition: pointer_vector_map.h:240
bool empty() const
Definition: pointer_vector_map.h:525
pair_const_reverse_iterator pair_rbegin() const
Definition: pointer_vector_map.h:248
TCompareType key_compare
Definition: pointer_vector_map.h:85
PointerVectorMap & operator=(const PointerVectorMap &rOther)
Definition: pointer_vector_map.h:125
size_type size() const
Definition: pointer_vector_map.h:282
size_type GetSortedPartSize() const
Get the sorted part size of buffer used in the container.
Definition: pointer_vector_map.h:507
PointerVectorMap()
Default constructor.
Definition: pointer_vector_map.h:107
TContainerType ContainerType
Definition: pointer_vector_map.h:89
TPointerType pointer
Definition: pointer_vector_map.h:86
size_type max_size() const
Definition: pointer_vector_map.h:287
void clear()
Definition: pointer_vector_map.h:381
std::pair< TKeyType, TPointerType > value_type
Definition: pointer_vector_map.h:84
key_compare key_comp() const
Definition: pointer_vector_map.h:292
std::string Info() const
Turn back information as a string.
Definition: pointer_vector_map.h:540
void push_back(value_type x)
Definition: pointer_vector_map.h:302
TKeyType key_type
Key type for searching in this container.
Definition: pointer_vector_map.h:80
KRATOS_CLASS_POINTER_DEFINITION(PointerVectorMap)
Pointer definition of PointerVectorMap.
TContainerType::reverse_iterator pair_reverse_iterator
Definition: pointer_vector_map.h:99
pair_iterator pair_begin()
Definition: pointer_vector_map.h:228
iterator end()
Definition: pointer_vector_map.h:204
const_reverse_iterator rend() const
Definition: pointer_vector_map.h:224
iterator insert(key_type const &Key, const TDataType &rData)
Definition: pointer_vector_map.h:307
pair_const_iterator pair_begin() const
Definition: pointer_vector_map.h:232
reference front()
Definition: pointer_vector_map.h:261
const_reverse_iterator rbegin() const
Definition: pointer_vector_map.h:216
PointerVectorMapIterator< typename TContainerType::reverse_iterator, TDataType > reverse_iterator
Definition: pointer_vector_map.h:93
pair_const_reverse_iterator pair_rend() const
Definition: pointer_vector_map.h:256
PointerVectorMapIterator< typename TContainerType::const_reverse_iterator, TDataType > const_reverse_iterator
Definition: pointer_vector_map.h:94
size_type GetMaxBufferSize() const
Get the maximum size of buffer used in the container.
Definition: pointer_vector_map.h:489
TContainerType::iterator pair_iterator
Definition: pointer_vector_map.h:97
iterator begin()
Definition: pointer_vector_map.h:196
const_reference back() const
Definition: pointer_vector_map.h:276
friend class Serializer
Definition: pointer_vector_map.h:668
pointer operator()(const key_type &Key)
Definition: pointer_vector_map.h:162
reverse_iterator rend()
Definition: pointer_vector_map.h:220
const_reference front() const
Definition: pointer_vector_map.h:266
const_iterator begin() const
Definition: pointer_vector_map.h:200
PointerVectorMap(const TContainerType &rContainer)
Definition: pointer_vector_map.h:111
PointerVectorMap(const PointerVectorMap &rOther)
Definition: pointer_vector_map.h:109
TDataType & operator[](const key_type &Key)
Definition: pointer_vector_map.h:133
void SetSortedPartSize(const size_type NewSize)
Set the sorted part size of buffer used in the container.
Definition: pointer_vector_map.h:516
pair_reverse_iterator pair_rend()
Definition: pointer_vector_map.h:252
void SetMaxBufferSize(const size_type NewSize)
Set the maximum size of buffer used in the container.
Definition: pointer_vector_map.h:499
const_iterator find(const key_type &Key) const
Definition: pointer_vector_map.h:406
iterator find(const key_type &Key)
Definition: pointer_vector_map.h:386
Short class definition.
Definition: pointer_vector_map_iterator.h:63
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
#define KRATOS_ERROR
Definition: exception.h:161
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::shared_ptr< T > shared_ptr
Definition: smart_pointers.h:27
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
a
Definition: generate_stokes_twofluid_element.py:77
int local_size
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:17
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
def load(f)
Definition: ode_solve.py:307
tuple const
Definition: ode_solve.py:403
int k
Definition: quadrature.py:595
x
Definition: sensitivityMatrix.py:49
integer i
Definition: TensorModule.f:17