ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Treque.h File Reference

The treque (triple ended queue) of exercise 2.3 of Morin's book, beyond the book: a LIST by rank whose operator[] takes \( O( 1 ) \) time and whose insertions and removals at the rank \( i \) take \( O( 1 + \min\{ i , n - i , | n / 2 - i | \} ) \) amortized time, fast near either end and near the middle. More...

#include "ADS/Contract.h"
#include "ADS/Iterators.h"
#include "ADS/queue/RingDeque.h"
#include <cstddef>
#include <initializer_list>
#include <iterator>
#include <utility>
#include "ADS/sequence/impl/Treque.tpp"

Go to the source code of this file.

Classes

class  ADS::Treque< T >
 a LIST by rank fast at both ends and in the middle, on two circular deques More...

Namespaces

namespace  ADS

Detailed description

The treque (triple ended queue) of exercise 2.3 of Morin's book, beyond the book: a LIST by rank whose operator[] takes \( O( 1 ) \) time and whose insertions and removals at the rank \( i \) take \( O( 1 + \min\{ i , n - i , | n / 2 - i | \} ) \) amortized time, fast near either end and near the middle.

The items are in two circular deques [see RingDeque.h], \( L \) with the ranks \( 0 , \ldots , |L| - 1 \) and \( R \) with the others, with \( |L| = \lfloor n / 2 \rfloor \) or \( |L| = \lceil n / 2 \rceil \): an operation at the rank \( i < |L| \) is one at the rank \( i \) of \( L \), which moves the items of its shorter side, the \( \min\{ i , |L| - i \} \) ones, and the same holds for \( R \); then one item at most passes between the back of \( L \) and the front of \( R \) to restore the balance, in \( O( 1 ) \) time.

The contracts [see Contract.h]: a rank is below size() (at most size() for an insertion), and the removals at the ends need a treque that is not empty; the invariant is \( \lfloor n / 2 \rfloor \le |L| \le \lceil n / 2 \rceil \). The operations are defined in Treque.tpp.

See also
P. Morin, Open Data Structures (in C++), Edition 0.1G, 2013, https://opendatastructures.org/ods-cpp.pdf, exercise 2.3
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa