44template <
class T,
class Compare = std::less<T>,
class Alloc = std::allocator<T> >
64 bool eq (
const T & first,
const T &
second ) {
65 return ! m_comp ( first,
second ) && ! m_comp (
second, first );
72 void sort_unique ( ) {
73 std::sort ( m_data.
begin ( ), m_data.
end ( ), m_comp );
115 explicit linear_set (
const Compare& comp = Compare(),
const Alloc& alloc = Alloc()) : m_data ( alloc ), m_comp ( comp ) {
124 explicit linear_set (
const Alloc& alloc) : m_data ( alloc ), m_comp ( Compare ( ) ) {
136 template <
class InputIterator>
137 linear_set (InputIterator first, InputIterator last,
const Compare& comp = Compare(),
const Alloc& alloc = Alloc()) : m_data ( first, last, alloc ), m_comp ( comp ) {
148 template <
class Iterator >
198 linear_set (std::initializer_list<T> il,
const Compare& comp = Compare(),
const Alloc& alloc = Alloc()) : m_data (
std::move ( il ), alloc ), m_comp ( comp ) {
216 return m_data.
begin ( );
226 return m_data.
begin ( );
246 return m_data.cbegin ( );
256 return m_data.
end ( );
266 return m_data.
end ( );
275 auto end ( ) &&
noexcept {
285 const_iterator
cend() const noexcept {
286 return m_data.cend ( );
296 auto endIter =
end ( );
297 auto beginIter =
begin ( );
308 auto endIter =
end ( );
309 auto beginIter =
begin ( );
320 auto endIter = std::move ( * this ).end ( );
321 auto beginIter = std::move ( * this ).begin ( );
340 size_t count (
const T& value )
const {
341 return std::binary_search ( m_data.
begin ( ), m_data.
end ( ), value );
351 return m_data.crbegin ( );
361 return m_data.crend ( );
374 template <
class... Args>
375 std::pair<iterator,bool>
emplace (Args&&... args) {
376 return insert ( T ( std::forward ( args ) ... ) );
390 template <
class... Args>
392 return insert ( position, T ( std::forward ( args ) ... ) );
402 return m_data.empty ( );
413 std::pair<const_iterator,const_iterator>
equal_range (
const T& val)
const {
438 return m_data.
erase ( position );
451 if ( position !=
end ( ) && eq ( * position, val ) )
452 return m_data.
erase ( position ), 1;
467 return m_data.
erase ( first, last );
480 if ( eq ( * position, val ) )
496 if ( eq ( * position, val ) )
509 return m_data.get_allocator ( );
520 std::pair<iterator,bool>
insert (
const T& val) {
521 return insert ( T ( val ) );
532 std::pair<iterator,bool>
insert (T&& val) {
534 if ( position !=
end ( ) && eq ( * position, val ) )
550 return insert ( position, T ( val ) );
563 if ( position !=
end ( ) && eq ( * position, val ) )
566 if ( position !=
end ( ) && m_comp ( val, * position ) && ( position ==
begin ( ) || m_comp ( * std::prev ( position ), val ) ) )
567 return m_data.
emplace ( position, std::move ( val ) );
569 return insert ( std::move ( val ) ).first;
579 template <
class InputIterator>
580 void insert (InputIterator first, InputIterator last) {
581 m_data.
insert ( m_data.
end ( ), first, last );
591 void insert (std::initializer_list<T> il) {
592 insert ( il.begin ( ), il.end ( ) );
614 return std::lower_bound (
begin ( ),
end ( ), val, m_comp );
626 return std::lower_bound (
begin ( ),
end ( ), val, m_comp );
636 return m_data.max_size ( );
662 m_data = std::move ( x.m_data );
663 m_comp = std::move ( x.m_comp );
676 m_data = std::move ( il );
677 std::sort ( m_data.
begin ( ), m_data.
end ( ), m_comp );
688 return m_data.rbegin ( );
698 return m_data.rbegin ( );
708 return m_data.rend ( );
718 return m_data.rend ( );
728 return m_data.size ( );
739 swap ( m_data, x.m_data );
740 swap ( m_comp, x.m_comp );
752 return std::upper_bound (
begin ( ),
end ( ), val, m_comp );
764 return std::upper_bound (
begin ( ),
end ( ), val, m_comp );
786 return this->
count ( key ) != 0U;
801 return this->
count ( key ) != 0U;
815 return lhs.m_data == rhs.m_data;
829 return lhs.m_data <=> rhs.m_data;
845template <
class T,
class Compare,
class Alloc>
862template<
class T,
class ... Ts >
867 for(
const T& item : value) {
868 if(!first) out <<
", ";
Implementation of iterator_range, i.e. pair of iterators. The class provides most notably begin and e...
Definition: range.hpp:24
Implementation of set mimicking the iterface of the standard library set. The inner representation is...
Definition: linear_set.hpp:45
~linear_set()
The destructor of the linear set.
Definition: linear_set.hpp:206
linear_set(InputIterator first, InputIterator last, const Compare &comp=Compare(), const Alloc &alloc=Alloc())
Set constructor from a range of values.
Definition: linear_set.hpp:137
void insert(InputIterator first, InputIterator last)
Insert values from a range speified by pair of iterators.
Definition: linear_set.hpp:580
linear_set(const Compare &comp=Compare(), const Alloc &alloc=Alloc())
Default constructor of the empty set.
Definition: linear_set.hpp:115
ext::vector< T, Alloc >::const_iterator iterator
The type of iterator over values in the set. It is the same as the underling vector's const iterator.
Definition: linear_set.hpp:88
reverse_iterator rbegin() noexcept
Getter of a reverse iterator to the begining of range of values in the container.
Definition: linear_set.hpp:687
std::pair< iterator, bool > emplace(Args &&... args)
Emplace a value to the container. Internaly the method uses insert since the place to put the value r...
Definition: linear_set.hpp:375
bool empty() const noexcept
Tests whether the container is empty.
Definition: linear_set.hpp:401
std::pair< iterator, bool > insert(T &&val)
Inserts a new value to the container.
Definition: linear_set.hpp:532
bool operator==(const linear_set< T, Compare, Alloc > &rhs) const
Compares two set instances for equvalence.
Definition: linear_set.hpp:813
void swap(linear_set &x)
Swaps two instances of linear set.
Definition: linear_set.hpp:737
iterator lower_bound(const T &val)
Returns an iterator pointing to the first element in the range [first,last) which does not compare le...
Definition: linear_set.hpp:613
auto end() &&noexcept
Getter of a move iterator to the end of range of values in the container.
Definition: linear_set.hpp:275
auto operator<=>(const linear_set< T, Compare, Alloc > &rhs) const
Compares two set instances by less relation.
Definition: linear_set.hpp:827
linear_set(const linear_set &x, const Alloc &alloc)
Copy constructor including allocator specification.
Definition: linear_set.hpp:168
linear_set(linear_set &&x, const Alloc &alloc)
Move constructor including allocator specification.
Definition: linear_set.hpp:187
Compare value_comp() const
Getter of the value comparator instance. Actually the value_type is the same as key_type so this is a...
Definition: linear_set.hpp:773
size_t count(const T &value) const
Computes the number of values in the container.
Definition: linear_set.hpp:340
const_iterator lower_bound(const T &val) const
Returns an iterator pointing to the first element in the range [first,last) which does not compare le...
Definition: linear_set.hpp:625
void insert(std::initializer_list< T > il)
Insert values from a range speified by initializer list.
Definition: linear_set.hpp:591
auto range() &&
Make range of move begin to end iterators.
Definition: linear_set.hpp:319
iterator end() &noexcept
Getter of an iterator to the end of range of values in the container.
Definition: linear_set.hpp:255
iterator insert(const_iterator position, const T &val)
Inserts a new value to the container. The method accepts a position hint where to place the new value...
Definition: linear_set.hpp:549
const_reverse_iterator crbegin() const noexcept
Getter of a const revese iterator to the begining of reverse range of values in the container.
Definition: linear_set.hpp:350
const_iterator cbegin() const noexcept
Getter of a const iterator to the begining of range of values in the container.
Definition: linear_set.hpp:245
ext::vector< T, Alloc >::const_reverse_iterator const_reverse_iterator
The type of const reverse iterator over values in the set. It is the same as the underling vector's c...
Definition: linear_set.hpp:106
Alloc get_allocator() const noexcept
Getter of the allocator.
Definition: linear_set.hpp:508
const_iterator upper_bound(const T &val) const
Returns an iterator pointing to the first element in the range [first,last) which compares greater th...
Definition: linear_set.hpp:763
const_reverse_iterator rbegin() const noexcept
Getter of a const reverse iterator to the begining of range of values in the container.
Definition: linear_set.hpp:697
std::pair< iterator, iterator > equal_range(const T &val)
Returns a range of values equal to the val. The range is specified by iterators.
Definition: linear_set.hpp:425
ext::vector< T, Alloc >::const_iterator const_iterator
The type of const iterator over values in the set. It is the same as the underling vector's const ite...
Definition: linear_set.hpp:94
linear_set(linear_set &&x)
Move constructor.
Definition: linear_set.hpp:177
iterator insert(const_iterator position, T &&val)
Inserts a new value to the container. The method accepts a position hint where to place the new value...
Definition: linear_set.hpp:562
auto range() const &
Make range of non-const begin to end iterators.
Definition: linear_set.hpp:307
const_reverse_iterator crend() const noexcept
Getter of a const revese iterator to the end of reverse range of values in the container.
Definition: linear_set.hpp:360
T value_type
The type of values in the set.
Definition: linear_set.hpp:82
const_iterator find(const T &val) const
Function to binary search for given value.
Definition: linear_set.hpp:478
const_iterator end() const &noexcept
Getter of a const iterator to the end of range of values in the container.
Definition: linear_set.hpp:265
iterator upper_bound(const T &val)
Returns an iterator pointing to the first element in the range [first,last) which compares greater th...
Definition: linear_set.hpp:751
std::pair< iterator, bool > insert(const T &val)
Inserts a new value to the container.
Definition: linear_set.hpp:520
linear_set(const ext::iterator_range< Iterator > &range)
Definition: linear_set.hpp:149
linear_set(const Alloc &alloc)
Constructor of the empty set with specified allocator.
Definition: linear_set.hpp:124
linear_set(const linear_set &x)
Copy constructor.
Definition: linear_set.hpp:158
iterator erase(const_iterator first, const_iterator last)
Removes values in the specified range. The range is specified by pair of iterators.
Definition: linear_set.hpp:466
iterator erase(const_iterator position)
Removes value from the container based on the position given by iterator.
Definition: linear_set.hpp:437
const_iterator begin() const &noexcept
Getter of a const iterator to the begining of range of values in the container.
Definition: linear_set.hpp:225
const_reverse_iterator rend() const noexcept
Getter of a const reverse iterator to the end of range of values in the container.
Definition: linear_set.hpp:717
linear_set & operator=(const linear_set &x)
Copy operator of assignmet.
Definition: linear_set.hpp:647
iterator emplace_hint(const_iterator position, Args &&... args)
Emplace a value to the container with provided position as a hint. Internaly the method uses insert s...
Definition: linear_set.hpp:391
iterator begin() &noexcept
Getter of an iterator to the begining of range of values in the container.
Definition: linear_set.hpp:215
auto range() &
Make range of non-const begin to end iterators.
Definition: linear_set.hpp:295
ext::vector< T, Alloc >::const_reverse_iterator reverse_iterator
The type of reverse iterator over values in the set. It is the same as the underling vector's const r...
Definition: linear_set.hpp:100
iterator find(const T &val)
Function to binary search for given value.
Definition: linear_set.hpp:494
reverse_iterator rend() noexcept
Getter of a reverse iterator to the end of range of values in the container.
Definition: linear_set.hpp:707
auto begin() &&noexcept
Getter of a move iterator to the begining of range of values in the container.
Definition: linear_set.hpp:235
bool contains(const T &key) const
Test whether the set contains a given key.
Definition: linear_set.hpp:785
size_t size() const noexcept
Getter of the number of values inside the container.
Definition: linear_set.hpp:727
Compare key_comp() const
Getter of the key comparator instance.
Definition: linear_set.hpp:601
size_t erase(const T &val)
Removes value from the container.
Definition: linear_set.hpp:449
std::pair< const_iterator, const_iterator > equal_range(const T &val) const
Returns a range of values equal to the val. The range is specified by const iterators.
Definition: linear_set.hpp:413
size_t max_size() const noexcept
Returns the maximal number of values possible to store inside the container.
Definition: linear_set.hpp:635
const_iterator cend() const noexcept
Getter of a const iterator to the end of range of values in the container.
Definition: linear_set.hpp:285
linear_set(std::initializer_list< T > il, const Compare &comp=Compare(), const Alloc &alloc=Alloc())
Set constructor from initializer list.
Definition: linear_set.hpp:198
bool contains(const K &key) const
Test whether the set contains a given key.
Definition: linear_set.hpp:800
void clear() noexcept
Removes all values from the conainer,.
Definition: linear_set.hpp:330
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: vector.hpp:125
iterator erase(iterator pos)
Removes element from the container at position given by parameter pos.
Definition: vector.hpp:323
typename std::vector< T, Alloc >::const_iterator const_iterator
The type of constant values iterator.
Definition: vector.hpp:67
reverse_iterator insert(const_reverse_iterator pos, const T &value)
Inserts the value on position given by iterator pos.
Definition: vector.hpp:229
auto end() &
Inherited behavior of end for non-const instance.
Definition: vector.hpp:155
reverse_iterator emplace(const_reverse_iterator pos, Args &&... args)
Inserts a new value to the container at position given by parameter pos. The new value is constructed...
Definition: vector.hpp:306
typename std::vector< T, Alloc >::const_reverse_iterator const_reverse_iterator
The type of constant reverse values iterator.
Definition: vector.hpp:79
p second
Definition: ToRegExpAlgebraic.h:126
Definition: sigHandler.cpp:20
ForwardIterator unique(ForwardIterator first, ForwardIterator last)
Shuffles values in a sequece so that consecutive duplicate values are pushed to the front and others ...
Definition: algorithm.hpp:384
set_move_iterator< Iterator > make_set_move_iterator(Iterator it)
Move from set iterator adaptor construction function.
Definition: iterator.hpp:200
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
std::ostream & operator<<(ext::reference_wrapper< std::ostream > &os, std::ostream &(*const func)(std::ostream &))
Overloaded function allowing same operations on wrapped output stream as on the actual output stream,...
Definition: GlobalData.cpp:33
void swap(ext::linear_set< T, Compare, Alloc > &x, ext::linear_set< T, Compare, Alloc > &y)
Specialisation of swap for linear set.
Definition: linear_set.hpp:846
Definition: FordFulkerson.hpp:16
void swap(ext::managed_linear_set< T, Compare, Alloc > &x, ext::managed_linear_set< T, Compare, Alloc > &y)
Specialisation of swap for linear set.
Definition: managed_linear_set.hpp:864