|
ADS
Algorithms and Data Structures
|
The QUEUE with the minimum of exercise 3.15 of Morin's book in \( O( 1 ) \) worst-case time per operation, beyond the book [see ADT.h and MinQueue.h for the amortized one]: enqueue(), dequeue(), top(), size() and min(), by the real-time queue of Hood and Melville on arrays with the minimum. More...
#include "ADS/Contract.h"#include "ADS/Portable.h"#include "ADS/queue/SlidingAggregate.h"#include <algorithm>#include <cstddef>#include <functional>#include <memory>#include <utility>#include "ADS/queue/impl/RealTimeMinQueue.tpp"Go to the source code of this file.
Classes | |
| class | ADS::RealTimeMinQueue< T, C > |
| a QUEUE with its least item, every operation in \( O( 1 ) \) worst-case time More... | |
Namespaces | |
| namespace | ADS |
The QUEUE with the minimum of exercise 3.15 of Morin's book in \( O( 1 ) \) worst-case time per operation, beyond the book [see ADT.h and MinQueue.h for the amortized one]: enqueue(), dequeue(), top(), size() and min(), by the real-time queue of Hood and Melville on arrays with the minimum.
The items are on two stacks, as in MinQueue: the front \( F \), the first item on top, and the back \( R \), the last item on top, each cell with the place of the least item at or below it. When \( R \) has one item more than \( F \), a rotation starts: \( R \) is frozen, a new back takes the insertions, and a new front \( N \) is built from the bottom, first the items of the frozen back from the last one, then those of \( F \) from its bottom, three moves per operation, while the removals still take the top of \( F \); the rotation ends when the moves of \( F \) meet its top, and \( N \) becomes the front. With \( |R| = |F| + 1 \) at the start, the \( |F| + 1 \) moves of the back end within \( \lceil ( |F| + 1 ) / 3 \rceil \) operations, before \( F \) empties, and the whole rotation within \( \lceil ( 2 |F| + 1 ) / 3 \rceil \); the minimum is the least of the minima of the parts, the one of \( F \) read in \( N \) when its place has moved there. The arrays are allocated with their final size when a rotation starts and emptied by the moves, so that no operation copies or frees more than \( O( 1 ) \) items (the allocation counted as \( O( 1 ) \)). The rotation is that of the real-time windows of SlidingAggregate [see SlidingAggregate.h], on the cells with the least place of detail::MinCells. See The minimum in constant worst-case time.
The contracts [see Contract.h]: top(), dequeue() and min() need a queue that is not empty; enqueue() ensures one item more, dequeue() one less, and the rotation ends before the front empties (an invariant). The operations are defined in RealTimeMinQueue.tpp.