25 #include <boost/iterator/indirect_iterator.hpp>
65 template<
class TDataType,
66 class TGetKeyType = SetIdentityFunction<TDataType>,
67 class TCompareType = std::less<decltype(std::declval<TGetKeyType>()(std::declval<TDataType>()))>,
68 class TEqualType = std::equal_to<decltype(std::declval<TGetKeyType>()(std::declval<TDataType>()))>,
69 class TPointerType =
typename TDataType::Pointer,
70 class TContainerType = std::vector<TPointerType>>
81 using key_type =
typename std::remove_reference<decltype(std::declval<TGetKeyType>()(std::declval<TDataType>()))>
::type;
95 using iterator = boost::indirect_iterator<typename TContainerType::iterator>;
96 using const_iterator = boost::indirect_iterator<typename TContainerType::const_iterator>;
97 using reverse_iterator = boost::indirect_iterator<typename TContainerType::reverse_iterator>;
125 template <
class TInputIteratorType>
127 : mSortedPartSize(
size_type()), mMaxBufferSize(NewMaxBufferSize)
129 for (; First != Last; ++First)
138 : mData(rOther.mData), mSortedPartSize(rOther.mSortedPartSize), mMaxBufferSize(rOther.mMaxBufferSize) {}
148 std::unique(mData.begin(), mData.end(), EqualKeyTo());
166 mData = rOther.mData;
167 mSortedPartSize = rOther.mSortedPartSize;
183 if (mData.size() - mSortedPartSize >= mMaxBufferSize) {
185 sorted_part_end = mData.end();
187 sorted_part_end = mData.begin() + mSortedPartSize;
190 ptr_iterator i(std::lower_bound(mData.begin(), sorted_part_end, Key, CompareKey()));
191 if (
i == sorted_part_end) {
193 return **mData.insert(sorted_part_end, TPointerType(
new TDataType(Key)));
196 if (!EqualKeyTo(Key)(*
i)) {
197 if ((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(Key))) == mData.end()) {
198 mData.push_back(TPointerType(
new TDataType(Key)));
199 return **(mData.end() - 1);
218 if (mData.size() - mSortedPartSize >= mMaxBufferSize) {
220 sorted_part_end = mData.end();
222 sorted_part_end = mData.begin() + mSortedPartSize;
224 ptr_iterator i(std::lower_bound(mData.begin(), sorted_part_end, Key, CompareKey()));
225 if (
i == sorted_part_end) {
227 return *mData.insert(sorted_part_end, TPointerType(
new TDataType(Key)));
230 if (!EqualKeyTo(Key)(*
i))
231 if ((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(Key))) == mData.end()) {
232 mData.push_back(TPointerType(
new TDataType(Key)));
233 return *(mData.end() - 1);
250 if (
size() != r.size())
253 return std::equal(mData.begin(), mData.end(), r.mData.begin(), EqualKeyTo());
267 return std::lexicographical_compare(mData.begin(), mData.end(), r.mData.begin(), r.mData.end(), CompareKey());
388 return mData.begin();
397 return mData.begin();
424 return mData.rbegin();
433 return mData.rbegin();
462 return *(mData.front());
473 return *(mData.front());
484 return *(mData.back());
495 return *(mData.back());
513 return mData.max_size();
523 return TCompareType();
534 std::swap(mSortedPartSize, rOther.mSortedPartSize);
535 std::swap(mMaxBufferSize, rOther.mMaxBufferSize);
536 mData.swap(rOther.mData);
557 if (mSortedPartSize > mData.size())
558 mSortedPartSize = mData.size();
575 if (mData.size() - mSortedPartSize >= mMaxBufferSize) {
577 sorted_part_end = mData.end();
579 sorted_part_end = mData.begin() + mSortedPartSize;
581 ptr_iterator i(std::lower_bound(mData.begin(), sorted_part_end, key, CompareKey()));
582 if (
i == sorted_part_end) {
584 return mData.insert(sorted_part_end, pData);
587 if (!EqualKeyTo(key)(*
i))
588 if ((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(key))) == mData.end()) {
589 mData.push_back(pData);
604 template <
class InputIterator>
605 void insert(InputIterator First, InputIterator Last)
607 for (; First != Last; ++First)
622 if (pos.base() == mData.end())
625 mSortedPartSize = mData.size();
641 mSortedPartSize = mData.size();
682 if (mData.size() - mSortedPartSize >= mMaxBufferSize) {
684 sorted_part_end = mData.end();
686 sorted_part_end = mData.begin() + mSortedPartSize;
688 ptr_iterator i(std::lower_bound(mData.begin(), sorted_part_end, Key, CompareKey()));
689 if (
i == sorted_part_end || (!EqualKeyTo(Key)(*
i)))
690 if ((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(Key))) == mData.end())
709 if (
i == sorted_part_end || (!EqualKeyTo(Key)(*
i)))
710 if ((
i = std::find_if(sorted_part_end, mData.end(), EqualKeyTo(Key))) == mData.end())
725 return find(Key) == mData.end() ? 0 : 1;
735 mData.reserve(reservedsize);
745 return mData.capacity();
755 std::sort(mData.begin(), mData.end(), CompareKey());
756 mSortedPartSize = mData.size();
766 typename TContainerType::iterator end_it = mData.end();
767 std::sort(mData.begin(), mData.end(), CompareKey());
768 typename TContainerType::iterator new_end_it = std::unique(mData.begin(), mData.end(), EqualKeyTo());
769 mData.erase(new_end_it, end_it);
770 mSortedPartSize = mData.size();
794 return mMaxBufferSize;
804 mMaxBufferSize = NewSize;
812 return mSortedPartSize;
821 mSortedPartSize = NewSize;
835 return mData.empty();
845 return (mSortedPartSize == mData.size());
855 std::stringstream buffer;
856 buffer <<
"Pointer vector set (size = " <<
size() <<
") : ";
871 std::copy(
begin(),
end(), std::ostream_iterator<TDataType>(rOStream,
"\n "));
899 return TCompareType()(
a, TGetKeyType()(*b));
911 return TCompareType()(TGetKeyType()(*a),
b);
923 return TCompareType()(TGetKeyType()(*a), TGetKeyType()(*b));
940 EqualKeyTo() : mKey() {}
947 explicit EqualKeyTo(
key_type Key) : mKey(Key) {}
957 return TEqualType()(mKey, TGetKeyType()(*a));
969 return TEqualType()(TGetKeyType()(*a), TGetKeyType()(*b));
982 TContainerType mData;
1006 return TGetKeyType()(*i);
1017 return TGetKeyType()(**i);
1028 return TGetKeyType()(
i);
1045 virtual void save(
Serializer& rSerializer)
const
1052 rSerializer.
save(
"E", mData[
i]);
1054 rSerializer.
save(
"Sorted Part Size",mSortedPartSize);
1055 rSerializer.
save(
"Max Buffer Size",mMaxBufferSize);
1071 rSerializer.
load(
"E", mData[
i]);
1073 rSerializer.
load(
"Sorted Part Size",mSortedPartSize);
1074 rSerializer.
load(
"Max Buffer Size",mMaxBufferSize);
1103 template<
class TDataType,
1108 class TContainerType>
1113 template<
class TDataType,
1118 class TContainerType>
1123 rOStream << std::endl;
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
void Unique()
Remove duplicate elements from the set.
Definition: pointer_vector_set.h:764
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: pointer_vector_set.h:869
TDataType & reference
Definition: pointer_vector_set.h:88
typename TContainerType::reverse_iterator ptr_reverse_iterator
Definition: pointer_vector_set.h:106
ptr_reverse_iterator ptr_rbegin()
Returns a reverse iterator pointing to the beginning of the underlying data container.
Definition: pointer_vector_set.h:422
bool empty() const
Check if the data container is empty.
Definition: pointer_vector_set.h:833
bool IsSorted() const
Check if the data container is sorted.
Definition: pointer_vector_set.h:843
const_iterator cend() const
Returns a constant iterator pointing to the end of the container.
Definition: pointer_vector_set.h:341
TCompareType key_compare
Definition: pointer_vector_set.h:86
const_iterator cbegin() const
Returns a constant iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:305
iterator erase(iterator pos)
Erase an element at the specified position.
Definition: pointer_vector_set.h:620
const_iterator end() const
Returns a constant iterator pointing to the end of the container.
Definition: pointer_vector_set.h:323
const TDataType & const_reference
Definition: pointer_vector_set.h:89
typename TContainerType::const_reverse_iterator ptr_const_reverse_iterator
Definition: pointer_vector_set.h:107
size_type max_size() const
Returns the maximum possible number of elements the container can hold.
Definition: pointer_vector_set.h:511
typename TContainerType::const_iterator ptr_const_iterator
Definition: pointer_vector_set.h:105
int capacity()
Get the current capacity of the underlying data container.
Definition: pointer_vector_set.h:743
void SetSortedPartSize(const size_type NewSize)
Set the sorted part size of buffer used in the container.
Definition: pointer_vector_set.h:819
ptr_iterator ptr_end()
Returns an iterator pointing to the end of the underlying data container.
Definition: pointer_vector_set.h:404
void clear()
Clear the set, removing all elements.
Definition: pointer_vector_set.h:663
ptr_const_iterator ptr_end() const
Returns a constant iterator pointing to the end of the underlying data container.
Definition: pointer_vector_set.h:413
reference front() noexcept
Returns a reference to the first element in the container.
Definition: pointer_vector_set.h:459
reference back() noexcept
Returns a reference to the last element in the container.
Definition: pointer_vector_set.h:481
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
ptr_iterator ptr_begin()
Returns an iterator pointing to the beginning of the underlying data container.
Definition: pointer_vector_set.h:386
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
void swap(PointerVectorSet &rOther)
Swaps the contents of this PointerVectorSet with another.
Definition: pointer_vector_set.h:532
typename TContainerType::difference_type difference_type
Definition: pointer_vector_set.h:108
const TContainerType & GetContainer() const
Definition: pointer_vector_set.h:784
void pop_back()
Removes the last element from the set.
Definition: pointer_vector_set.h:554
const_reference front() const noexcept
Returns a constant reference to the first element in the container.
Definition: pointer_vector_set.h:470
ptr_const_reverse_iterator ptr_rend() const
Returns a constant reverse iterator pointing to the end of the underlying data container.
Definition: pointer_vector_set.h:449
TDataType data_type
Definition: pointer_vector_set.h:84
boost::indirect_iterator< typename TContainerType::reverse_iterator > reverse_iterator
Definition: pointer_vector_set.h:97
void Sort()
Sort the elements in the set.
Definition: pointer_vector_set.h:753
const_iterator begin() const
Returns a constant iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:287
~PointerVectorSet()
Destructor.
Definition: pointer_vector_set.h:152
ptr_const_iterator ptr_begin() const
Returns a constant iterator pointing to the beginning of the underlying data container.
Definition: pointer_vector_set.h:395
void insert(InputIterator First, InputIterator Last)
Insert elements from a range of iterators.
Definition: pointer_vector_set.h:605
reverse_iterator rend()
Returns a reverse iterator pointing to the end of the container.
Definition: pointer_vector_set.h:368
TDataType & operator[](const key_type &Key)
Accesses an element by key and returns a reference.
Definition: pointer_vector_set.h:179
const_reverse_iterator rend() const
Returns a constant reverse iterator pointing to the end of the container.
Definition: pointer_vector_set.h:377
iterator insert(iterator Position, const TPointerType pData)
Inserts a pointer at the specified position.
Definition: pointer_vector_set.h:569
size_type count(const key_type &Key)
Count the number of elements with the specified key.
Definition: pointer_vector_set.h:723
boost::indirect_iterator< typename TContainerType::const_reverse_iterator > const_reverse_iterator
Definition: pointer_vector_set.h:98
size_type GetMaxBufferSize() const
Get the maximum size of buffer used in the container.
Definition: pointer_vector_set.h:792
void push_back(TPointerType x)
Adds a pointer to the end of the set.
Definition: pointer_vector_set.h:544
TContainerType & GetContainer()
Definition: pointer_vector_set.h:778
const_iterator cend()
Returns a constant iterator pointing to the end of the container.
Definition: pointer_vector_set.h:332
typename TContainerType::size_type size_type
Definition: pointer_vector_set.h:103
bool operator<(const PointerVectorSet &r) const noexcept
Less than comparison operator for two PointerVectorSet objects.
Definition: pointer_vector_set.h:264
KRATOS_CLASS_POINTER_DEFINITION(PointerVectorSet)
Pointer definition of PointerVectorSet.
TContainerType ContainerType
Definition: pointer_vector_set.h:90
ptr_reverse_iterator ptr_rend()
Returns a reverse iterator pointing to the end of the underlying data container.
Definition: pointer_vector_set.h:440
PointerVectorSet()
Default constructor.
Definition: pointer_vector_set.h:115
size_type GetSortedPartSize() const
Get the sorted part size of buffer used in the container.
Definition: pointer_vector_set.h:810
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
PointerVectorSet(const PointerVectorSet &rOther)
Copy constructor for PointerVectorSet.
Definition: pointer_vector_set.h:137
boost::indirect_iterator< typename TContainerType::const_iterator > const_iterator
Definition: pointer_vector_set.h:96
iterator find(const key_type &Key)
Find an element with the specified key.
Definition: pointer_vector_set.h:678
PointerVectorSet & operator=(const PointerVectorSet &rOther)
Assignment operator for PointerVectorSet.
Definition: pointer_vector_set.h:164
PointerVectorSet(TInputIteratorType First, TInputIteratorType Last, size_type NewMaxBufferSize=1)
Constructs a PointerVectorSet from a range of elements.
Definition: pointer_vector_set.h:126
ptr_const_reverse_iterator ptr_rbegin() const
Returns a constant reverse iterator pointing to the beginning of the underlying data container.
Definition: pointer_vector_set.h:431
std::string Info() const
Turn back information as a string.
Definition: pointer_vector_set.h:853
const_reference back() const noexcept
Returns a constant reference to the last element in the container.
Definition: pointer_vector_set.h:492
reverse_iterator rbegin()
Returns a reverse iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:350
bool operator==(const PointerVectorSet &r) const noexcept
Equality comparison operator for two PointerVectorSet objects.
Definition: pointer_vector_set.h:247
void reserve(int reservedsize)
Reserves memory for a specified number of elements.
Definition: pointer_vector_set.h:733
const_iterator cbegin()
Returns a constant iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:296
const_iterator find(const key_type &Key) const
Find an element with the specified key (const version).
Definition: pointer_vector_set.h:704
TDataType value_type
Definition: pointer_vector_set.h:85
iterator erase(const key_type &k)
Erase an element with the specified key.
Definition: pointer_vector_set.h:653
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
iterator erase(iterator first, iterator last)
Erase a range of elements defined by iterators.
Definition: pointer_vector_set.h:637
PointerVectorSet(const TContainerType &rContainer)
Constructs a PointerVectorSet from a container.
Definition: pointer_vector_set.h:145
pointer & operator()(const key_type &Key)
Function for inserting or retrieving a pointer associated with a key.
Definition: pointer_vector_set.h:214
void SetMaxBufferSize(const size_type NewSize)
Set the maximum size of buffer used in the container.
Definition: pointer_vector_set.h:802
typename TContainerType::iterator ptr_iterator
Definition: pointer_vector_set.h:104
key_compare key_comp() const
Returns the key comparison function used for ordering elements in the container.
Definition: pointer_vector_set.h:521
const_reverse_iterator rbegin() const
Returns a constant reverse iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:359
TPointerType pointer
Definition: pointer_vector_set.h:87
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: pointer_vector_set.h:863
typename std::remove_reference< decltype(std::declval< TGetKeyType >()(std::declval< TDataType >()))>::type key_type
Key type for searching in this container.
Definition: pointer_vector_set.h:81
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
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
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
type
Definition: generate_gid_list_file.py:35
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