|
ADS
Algorithms and Data Structures
|
The interfaces of chapter 1 of Morin's book for the sequences, beyond the book, as concepts of C++20 [see ADT.h for those of the book]: More...
#include "ADS/Contract.h"#include <concepts>#include <cstddef>#include <numeric>#include <span>#include <utility>#include <vector>#include "ADS/sequence/impl/IndexedList.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Concepts | |
| concept | ADS::IndexedList |
| the LIST of Morin: a sequence read, written, extended and shortened by rank | |
| concept | ADS::IndexedDeque |
| the DEQUE of Morin: a sequence changed and read at both ends | |
Functions | |
| template<class T> | |
| void | ADS::rotateArray (std::span< T > a, std::size_t r) |
| the item \( a[ i ] \) moved to \( a[ ( i + r ) \bmod n ] \), for every \( i \), by three reversals: \( n \) swaps at most and \( O( 1 ) \) space | |
| template<IndexedList L> | |
| void | ADS::rotate (L &l, std::size_t r) |
| the item of rank \( i \) of \( l \) moved to the rank \( ( i + r ) \bmod n \): the rotate() of the list if it has one, the cycles of the permutation otherwise, \( n + \gcd( n , r ) \) moves | |
The interfaces of chapter 1 of Morin's book for the sequences, beyond the book, as concepts of C++20 [see ADT.h for those of the book]:
Two rotations come with them: rotateArray(), the item \( a[ i ] \) of an array moved to \( a[ ( i + r ) \bmod n ] \) by three reversals (exercise 2.4 of Morin), \( n \) swaps at most and no memory, and rotate(), the same on an IndexedList, which calls the rotate() of the list when it has one (\( O( 1 + \min\{ r , n - r \} ) \) on RingDeque, DualArrayDeque and List, exercises 2.5 and 3.8) and otherwise follows the \( \gcd( n , r ) \) cycles of the permutation by operator[], \( n + \gcd( n , r ) \) moves.
The contracts [see Contract.h]: none but those of the lists; the rotations ensure that the items are where they should be (an audit). The algorithms are defined in IndexedList.tpp.