Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
forward_tree.hpp
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <memory>
27#include <string>
28#include <compare>
29
31
32#include "deque.hpp"
33#include "vector.hpp"
34#include "tree_base.hpp"
35
36namespace ext {
37
48template < class T >
54 T m_data;
55
63
64public:
71 T & getData ( ) {
72 return m_data;
73 }
74
81 const T & getData ( ) const {
82 return m_data;
83 }
84
92 return m_children;
93 }
94
102 return m_children;
103 }
104
110
116
128 const forward_tree * node;
129
135
140 bool virtual_node;
141
146 bool isEnd;
147
148 public:
149 using difference_type = std::ptrdiff_t;
150 using value_type = T;
151 using pointer = const T*;
152 using reference = const T&;
153 using iterator_category = std::bidirectional_iterator_tag;
154
161 const_structure_iterator ( const forward_tree * n ) : node ( n ), parents ( ), virtual_node ( false ), isEnd ( false ) {
162 }
163
171 if ( virtual_node ) {
172 ++node;
173 if ( parents.size ( ) ) {
174 const forward_tree * parent = parents.back ( );
175
176 if ( std::distance ( & * parent->getChildren ( ).begin ( ), node ) == std::distance ( parent->getChildren ( ).begin ( ), parent->getChildren ( ).end ( ) ) ) { // just a way to detect node == end_of_children
177 parents.pop_back();
178 node = parent;
179 } else {
180 virtual_node = false;
181 }
182 } else {
183 virtual_node = false;
184 isEnd = true;
185 }
186 } else {
187 if ( ! node->getChildren ( ).empty ( ) ) {
188 parents.push_back ( node );
189 node = & * node->getChildren ( ).begin ( );
190 } else {
191 virtual_node = true;
192 }
193 }
194
195 return * this;
196 }
197
205 const_structure_iterator tmp ( * this );
206
207 operator ++( );
208 return tmp;
209 }
210
218 if ( isEnd ) {
219 --node;
220 virtual_node = true;
221 isEnd = false;
222 } else if ( virtual_node ) {
223 if ( ! node->getChildren ( ).empty ( ) ) {
224 parents.push_back ( node );
225 node = & * -- node->getChildren ( ).end ( );
226 } else {
227 virtual_node = false;
228 }
229 } else {
230 if ( parents.size ( ) ) {
231 const forward_tree * parent = parents.back ( );
232
233 if ( node == & * parent->getChildren ( ).begin ( ) ) {
234 parents.pop_back();
235 node = parent;
236 } else {
237 --node;
238 virtual_node = true;
239 }
240 }
241 }
242
243 return * this;
244 }
245
253 const_structure_iterator tmp ( * this );
254
255 operator --( );
256 return tmp;
257 }
258
267 bool operator ==( const const_structure_iterator & other ) const {
268 return node == other.node && virtual_node == other.virtual_node;
269 }
270
279 bool operator !=( const const_structure_iterator & other ) const {
280 return !( * this == other );
281 }
282
289 const T & operator *( ) const {
290 return node->getData ( );
291 }
292
299 const T * operator ->( ) const {
300 return & node->getData ( );
301 }
302
309 size_t getLevel ( ) const {
310 return parents.size ( );
311 }
312
319 bool getVirtual ( ) const {
320 return virtual_node;
321 }
322
323 template < class F >
324 friend class forward_tree;
325 };
326
339
340 public:
341 using difference_type = std::ptrdiff_t;
342 using value_type = T;
343 using pointer = const T*;
344 using reference = const T&;
345 using iterator_category = std::bidirectional_iterator_tag;
346
354 }
355
363 while ( ( ++node ).getVirtual ( ) );
364
365 return * this;
366 }
367
375 const_prefix_iterator tmp ( * this );
376
377 operator ++( );
378 return tmp;
379 }
380
388 while ( ( --node ).getVirtual ( ) );
389
390 return * this;
391 }
392
400 const_prefix_iterator tmp ( * this );
401
402 operator --( );
403 return tmp;
404 }
405
414 bool operator ==( const const_prefix_iterator & other ) const {
415 return node == other.node;
416 }
417
426 bool operator !=( const const_prefix_iterator & other ) const {
427 return !( * this == other );
428 }
429
436 const T & operator *( ) const {
437 return * node;
438 }
439
446 const T * operator ->( ) const {
447 return & node->getData ( );
448 }
449
456 size_t getLevel ( ) const {
457 return node.getLevel ( );
458 }
459
460 template < class F >
461 friend class forward_tree;
462 };
463
476
477 public:
478 using difference_type = std::ptrdiff_t;
479 using value_type = T;
480 using pointer = const T*;
481 using reference = const T&;
482 using iterator_category = std::bidirectional_iterator_tag;
483
491 }
492
500 while ( !( ++node ).getVirtual ( ) && !node.isEnd );
501
502 return * this;
503 }
504
512 const_postfix_iterator tmp ( * this );
513
514 operator ++( );
515 return tmp;
516 }
517
525 while ( !( --node ).getVirtual ( ) );
526
527 return * this;
528 }
529
537 const_postfix_iterator tmp ( * this );
538
539 operator --( );
540 return tmp;
541 }
542
551 bool operator ==( const const_postfix_iterator & other ) const {
552 return node == other.node;
553 }
554
563 bool operator !=( const const_postfix_iterator & other ) const {
564 return !( * this == other );
565 }
566
573 const T & operator *( ) const {
574 return * node;
575 }
576
583 const T * operator ->( ) const {
584 return & node->getData ( );
585 }
586
593 size_t getLevel ( ) const {
594 return node.getLevel ( );
595 }
596
597 template < class F >
598 friend class forward_tree;
599 };
600
601// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
602
603private:
615 template < typename Iterator >
616 ext::vector < forward_tree > fromIterator ( Iterator begin, Iterator end ) {
618
619 for ( ; begin != end; ++begin )
620 res.push_back ( forward_tree ( * begin, { } ) );
621
622 return res;
623 }
624
625public:
636 ext::vector < forward_tree > & children = const_cast < ext::vector < forward_tree > & > ( getChildren ( ) );
637
638 return children.insert ( position, std::move ( value ) );
639 }
640
651 return insert ( position, forward_tree < T > ( value ) );
652 }
653
665 ext::vector < forward_tree > & children = const_cast < ext::vector < forward_tree > & > ( getChildren ( ) );
666
667 return children.insert ( position, begin, end );
668 }
669
682 template < class Iterator >
684 ext::vector < forward_tree > children = fromIterator ( begin, end );
685
686 return insert ( position, children.cbegin ( ), children.cend ( ) );
687 }
688
689// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
690
698 forward_tree ( T && data, ext::vector < forward_tree > && children ) : m_data ( std::move ( data ) ), m_children ( std::move ( children ) ) {
699 }
700
708 forward_tree ( const T & data, const ext::vector < forward_tree > & subtrees ) : forward_tree ( T ( data ), ext::vector < forward_tree > ( subtrees ) ) {
709 }
710
720 template < typename ... Types >
721 forward_tree ( const T & data, Types ... subtrees ) : forward_tree ( data, ext::vector < forward_tree > { subtrees ... } ) {
722 }
723
733 template < typename ... Types >
734 forward_tree ( T && data, Types ... subtrees ) : forward_tree ( std::move ( data ), ext::vector < forward_tree > { subtrees ... } ) {
735 }
736
745 template < typename Iterator >
746 forward_tree ( const T & data, Iterator begin, Iterator end ) : forward_tree ( data, fromIterator ( begin, end ) ) {
747 }
748
758 }
759
760// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
761
769 return m_children.begin ( );
770 }
771
779 return m_children.begin ( );
780 }
781
789 return m_children.end ( );
790 }
791
799 return m_children.end ( );
800 }
801
802// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
803
811 return const_prefix_iterator ( this );
812 }
813
821 const_prefix_iterator res ( this + 1 );
822
823 res.node.isEnd = true;
824 return res;
825 }
826
827// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
828
837
838 while ( ! res.node.getVirtual ( ) ) ++res.node;
839
840 return res;
841 }
842
850 const_postfix_iterator res ( this + 1 );
851
852 res.node.isEnd = true;
853 return res;
854 }
855
856// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
857
865 return const_structure_iterator ( this );
866 }
867
875 const_structure_iterator res ( this + 1 );
876
877 res.isEnd = true;
878 return res;
879 }
880
881// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
882
890 ext::vector < forward_tree > & children = const_cast < ext::vector < forward_tree > & > ( getChildren ( ) );
891
892 children.push_back ( std::move ( value ) );
893 }
894
901 void push_back ( const ext::forward_tree < T > & value ) {
902 push_back ( forward_tree ( value ) );
903 }
904
911 void push_back ( T && value ) {
912 push_back ( forward_tree ( std::move ( value ) ) );
913 }
914
921 void push_back ( const T & value ) {
922 push_back ( T ( value ) );
923 }
924
925// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
926
934 ext::vector < forward_tree > & children = const_cast < ext::vector < forward_tree > & > ( getChildren ( ) );
935
936 return children.erase ( position );
937 }
938
939// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
940
951 template < class ... Indexes >
952 const T & operator ()( Indexes ... indexes ) const {
953 return this->operator ()( { static_cast < size_t > ( indexes ) ... } );
954 }
955
964 const T & operator ()( std::initializer_list < size_t > indexes ) const {
965 const forward_tree * node = this;
966
967 for ( size_t index : indexes ) {
968 node = & node->getChildren ( )[index];
969 }
970
971 return node->getData ( );
972 }
973
984 template < class ... Indexes >
985 T & operator ()( Indexes ... indexes ) {
986 return this->operator ()( { static_cast < size_t > ( indexes ) ... } );
987 }
988
997 T & operator ()( std::initializer_list < size_t > indexes ) {
998 forward_tree * node = this;
999
1000 for ( size_t index : indexes ) {
1001 node = & node->getChildren ( )[index];
1002 }
1003
1004 return node->getData ( );
1005 }
1006
1007// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1008
1016 friend void swap ( forward_tree & first, forward_tree & second ) {
1017 using std::swap;
1018
1019 swap ( first.m_data, second.m_data );
1020 swap ( first.m_children, second.m_children );
1021 }
1022
1023// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1024
1033 bool operator ==( const forward_tree & other ) const {
1034 return std::equal ( this->prefix_begin ( ), this->prefix_end ( ), other.prefix_begin ( ), other.prefix_end ( ) );
1035 }
1036
1045 auto operator <=> ( const forward_tree & other ) const {
1046 return std::lexicographical_compare_three_way ( this->prefix_begin ( ), this->prefix_end ( ), other.prefix_begin ( ), other.prefix_end ( ) );
1047 }
1048
1049// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1050
1073 std::ostream & nicePrint ( std::ostream & os ) const {
1074 nicePrint ( os, "", true );
1075 return os;
1076 }
1077
1078private:
1101 void nicePrint ( std::ostream & os, std::string prefix, bool last ) const {
1102 os << prefix;
1103
1104 if ( last ) {
1105 os << "\\-";
1106 prefix += " ";
1107 } else {
1108 os << "|-";
1109 prefix += "| ";
1110 }
1111
1112 os << getData ( ) << std::endl;
1113
1114 for ( size_t i = 0; i < m_children.size ( ); ++i ) {
1115 os << prefix << "|" << std::endl;
1116 m_children[i].nicePrint ( os, prefix, i == m_children.size ( ) - 1 );
1117 }
1118 }
1119};
1120
1132template < class T >
1133std::ostream & operator <<( std::ostream & out, const forward_tree < T > & t ) {
1134 out << "[";
1135
1136 size_t level = 0;
1137
1138 for ( typename forward_tree < T >::const_prefix_iterator iter = t.prefix_begin ( ); iter != t.prefix_end ( ); ) {
1139 while ( iter.getLevel ( ) > level ) {
1140 out << "[";
1141 ++level;
1142 }
1143
1144 out << level << * iter;
1145 ++iter;
1146
1147 bool printComma = iter.getLevel ( ) == level;
1148
1149 while ( iter.getLevel ( ) < level ) {
1150 out << "]";
1151 --level;
1152 printComma = true;
1153 }
1154
1155 if ( printComma && ( level != 0 ) )
1156 out << ",";
1157 }
1158
1159 out << "]";
1160 return out;
1161}
1162
1163} /* namespace ext */
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
The iterator type over structure of the tree following postorder traversal.
Definition: forward_tree.hpp:470
const T & reference
Definition: forward_tree.hpp:481
bool operator!=(const const_postfix_iterator &other) const
Compare the iterators for nonequality.
Definition: forward_tree.hpp:563
const T * pointer
Definition: forward_tree.hpp:480
bool operator==(const const_postfix_iterator &other) const
Compare the iterators for equality.
Definition: forward_tree.hpp:551
const T & operator*() const
Dereference the iterator by accessing the pointed node value.
Definition: forward_tree.hpp:573
std::ptrdiff_t difference_type
Definition: forward_tree.hpp:478
const_postfix_iterator(const forward_tree *n)
Constructor of the iterator based on the iterator to child list.
Definition: forward_tree.hpp:490
T value_type
Definition: forward_tree.hpp:479
const T * operator->() const
Dereference the iterator by accessing the pointed node value.
Definition: forward_tree.hpp:583
const_postfix_iterator & operator--()
Retract the iterator.
Definition: forward_tree.hpp:524
const_postfix_iterator & operator++()
Advances the iterator.
Definition: forward_tree.hpp:499
size_t getLevel() const
Retrieves what is the depth of node the iterator is pointing to.
Definition: forward_tree.hpp:593
std::bidirectional_iterator_tag iterator_category
Definition: forward_tree.hpp:482
The iterator type over structure of the tree following preorder traversal.
Definition: forward_tree.hpp:333
const T & reference
Definition: forward_tree.hpp:344
T value_type
Definition: forward_tree.hpp:342
const_prefix_iterator & operator++()
Advance the iterator.
Definition: forward_tree.hpp:362
const T * operator->() const
Dereference the iterator by accessing the pointed node value.
Definition: forward_tree.hpp:446
const_prefix_iterator(const forward_tree *n)
Constructor of the iterator based on the iterator to child list.
Definition: forward_tree.hpp:353
size_t getLevel() const
Retrieves what is the depth of node the iterator is pointing to.
Definition: forward_tree.hpp:456
const_prefix_iterator & operator--()
Retract the iterator.
Definition: forward_tree.hpp:387
std::bidirectional_iterator_tag iterator_category
Definition: forward_tree.hpp:345
bool operator==(const const_prefix_iterator &other) const
Compare the iterators for equality.
Definition: forward_tree.hpp:414
std::ptrdiff_t difference_type
Definition: forward_tree.hpp:341
const T & operator*() const
Dereference the iterator by accessing the pointed node value.
Definition: forward_tree.hpp:436
const T * pointer
Definition: forward_tree.hpp:343
bool operator!=(const const_prefix_iterator &other) const
Compare the iterators for nonequality.
Definition: forward_tree.hpp:426
The iterator type over structure of the tree representing nodes and node_ends.
Definition: forward_tree.hpp:123
std::bidirectional_iterator_tag iterator_category
Definition: forward_tree.hpp:153
const_structure_iterator & operator++()
Advance the iterator.
Definition: forward_tree.hpp:170
T value_type
Definition: forward_tree.hpp:150
const_structure_iterator(const forward_tree *n)
Constructor of the iterator based on the iterator to child list.
Definition: forward_tree.hpp:161
bool operator==(const const_structure_iterator &other) const
Compare the iterators for equality.
Definition: forward_tree.hpp:267
const T * operator->() const
Dereference the iterator by accessing the pointed node value.
Definition: forward_tree.hpp:299
std::ptrdiff_t difference_type
Definition: forward_tree.hpp:149
size_t getLevel() const
Retrieves what is the depth of node the iterator is pointing to.
Definition: forward_tree.hpp:309
const_structure_iterator & operator--()
Retract the iterator.
Definition: forward_tree.hpp:217
bool getVirtual() const
Allows to distinguish entry or leave visit of a pointed to node.
Definition: forward_tree.hpp:319
const T & reference
Definition: forward_tree.hpp:152
bool operator!=(const const_structure_iterator &other) const
Compare the iterators for nonequality.
Definition: forward_tree.hpp:279
const T & operator*() const
Dereference the iterator by accessing the pointed node value.
Definition: forward_tree.hpp:289
const T * pointer
Definition: forward_tree.hpp:151
Class introducing a forward_tree with interface trying to be close to the interface of standard libra...
Definition: forward_tree.hpp:49
forward_tree(T &&data, ext::vector< forward_tree > &&children)
Constructor of the forward_tree from value to be stored in the root node and children trees.
Definition: forward_tree.hpp:698
auto operator<=>(const forward_tree &other) const
Less comparison operator.
Definition: forward_tree.hpp:1045
ext::vector< forward_tree >::const_iterator const_children_iterator
The iterator type over children of the node.
Definition: forward_tree.hpp:109
const ext::vector< forward_tree > & getChildren() const
Getter of children of the root node.
Definition: forward_tree.hpp:101
void push_back(const ext::forward_tree< T > &value)
Pushbacks a subtree after last child of a tree.
Definition: forward_tree.hpp:901
children_iterator erase(const_children_iterator position)
Erases a subtree from a tree on given by position.
Definition: forward_tree.hpp:933
const_children_iterator begin() const
Getter of a children iterator to the begining of children.
Definition: forward_tree.hpp:768
forward_tree(const T &data, Iterator begin, Iterator end)
Constructor of the forward_tree from value to be stored in the root node and range of values to const...
Definition: forward_tree.hpp:746
const_postfix_iterator postfix_end() const
Getter of the postfix iterator one after the last node in the postfix traversal.
Definition: forward_tree.hpp:849
std::ostream & nicePrint(std::ostream &os) const
Internal method of printing a tree into a stream.
Definition: forward_tree.hpp:1073
children_iterator end()
Getter of a children iterator one after the last child.
Definition: forward_tree.hpp:798
const_children_iterator insert(const_children_iterator position, const_children_iterator begin, const_children_iterator end)
Insert helper for insertion specified by position in children and inserted subtrees given by range of...
Definition: forward_tree.hpp:664
const T & getData() const
Getter of the value in the root node.
Definition: forward_tree.hpp:81
forward_tree(const T &data, const ext::vector< forward_tree > &subtrees)
Constructor of the forward_tree from value to be stored in the root node and children trees.
Definition: forward_tree.hpp:708
const_children_iterator insert(const_children_iterator position, Iterator begin, Iterator end)
Inserts a subtrees into a forward_tree. The subtrees are nullary nodes having value given by values i...
Definition: forward_tree.hpp:683
void push_back(T &&value)
Pushbacks a nullary node after last child of a tree.
Definition: forward_tree.hpp:911
const T & operator()(Indexes ... indexes) const
Access value given indexes of chindren allong the selection path.
Definition: forward_tree.hpp:952
const_children_iterator insert(const_children_iterator position, const forward_tree< T > &value)
Inserts a subtree into a forward_tree.
Definition: forward_tree.hpp:650
void push_back(const T &value)
Pushbacks a nullary node after last child of a tree.
Definition: forward_tree.hpp:921
forward_tree(T &&data, Types ... subtrees)
Constructor of the forward_tree from value to be stored in the root node and pack of children trees.
Definition: forward_tree.hpp:734
T & getData()
Getter of the value in the root node.
Definition: forward_tree.hpp:71
children_iterator begin()
Getter of a children iterator to the begining of children.
Definition: forward_tree.hpp:778
friend void swap(forward_tree &first, forward_tree &second)
Swap method of two forward trees.
Definition: forward_tree.hpp:1016
forward_tree(const T &data, Types ... subtrees)
Constructor of the forward_tree from value to be stored in the root node and pack of children trees.
Definition: forward_tree.hpp:721
const_children_iterator insert(const_children_iterator position, forward_tree< T > &&value)
Inserts a subtree into a forward_tree.
Definition: forward_tree.hpp:635
const_structure_iterator structure_end() const
Getter of the structure iterator to one after the last node in the traversal.
Definition: forward_tree.hpp:874
forward_tree(const T &data, const_children_iterator begin, const_children_iterator end)
Constructor of the forward_tree from value to be stored in the root node and range of subtrees.
Definition: forward_tree.hpp:757
const_postfix_iterator postfix_begin() const
Getter of the postfix iterator to the first node in the postfix traversal.
Definition: forward_tree.hpp:835
const_structure_iterator structure_begin() const
Getter of the structure iterator to the first node in the traversal.
Definition: forward_tree.hpp:864
ext::vector< forward_tree > & getChildren()
Getter of children of the root node.
Definition: forward_tree.hpp:91
void push_back(ext::forward_tree< T > &&value)
Pushbacks a subtree after last child of a tree.
Definition: forward_tree.hpp:889
bool operator==(const forward_tree &other) const
Equality comparison operator.
Definition: forward_tree.hpp:1033
ext::vector< forward_tree >::iterator children_iterator
The iterator type over children of the node.
Definition: forward_tree.hpp:115
const_prefix_iterator prefix_begin() const
Getter of the prefix iterator to the root node.
Definition: forward_tree.hpp:810
const_prefix_iterator prefix_end() const
Getter of the prefix iterator one after the last node in the prefix traversal.
Definition: forward_tree.hpp:820
const_children_iterator end() const
Getter of a children iterator one after the last child.
Definition: forward_tree.hpp:788
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 >::iterator iterator
The type of values iterator.
Definition: vector.hpp:61
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
p second
Definition: ToRegExpAlgebraic.h:126
int i
Definition: AllEpsilonClosure.h:118
return res
Definition: MinimizeByPartitioning.h:145
Definition: sigHandler.cpp:20
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
Definition: CompressedBitParallelTreeIndex.h:40
Definition: Node.cpp:11
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