ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ExternalSorting.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------ File ExternalSorting.h --------------------------*/
3/*--------------------------------------------------------------------------*/
113/*--------------------------------------------------------------------------*/
114/*----------------------------- DEFINITIONS --------------------------------*/
115/*--------------------------------------------------------------------------*/
116
117#ifndef __ADS_ExternalSorting
118 #define __ADS_ExternalSorting
119/* self-identification: #endif constant */
120
121/*--------------------------------------------------------------------------*/
122/*------------------------------ INCLUDES ----------------------------------*/
123/*--------------------------------------------------------------------------*/
124
125#include "ADS/Contract.h"
132#include "ADS/sort/Sort.h"
133#include "ADS/sort/Sorted.h"
134
135#include <algorithm>
136#include <cmath>
137#include <cstddef>
138#include <cstdint>
139#include <functional>
140#include <memory>
141#include <optional>
142#include <utility>
143#include <vector>
144
145/*--------------------------------------------------------------------------*/
146/*--------------------------- NAMESPACE ------------------------------------*/
147/*--------------------------------------------------------------------------*/
148
149namespace ADS
150{
151
157[[nodiscard]] inline std::uint64_t
158mergeSortIOs( std::size_t n , std::size_t M , std::size_t B , std::size_t k );
159
169[[nodiscard]] inline std::uint64_t
170sortingLowerBound( std::size_t n , std::size_t M , std::size_t B );
171
177[[nodiscard]] inline std::uint64_t
178permutingLowerBound( std::size_t n , std::size_t M , std::size_t B );
179
202template< class T , class C = std::less<> >
204 C less = C() );
205
239template< class T , class C = std::less<> , class Sel = LoserTree< T , C > >
241 C less = C() , bool snowPlow = false );
242
273template< class T , class R , class C = std::less<> >
274void distributionSort( const DiskFile< T > & in , DiskFile< T > & out , R & g ,
275 C less = C() );
276
299template< class T >
301 const DiskFile< std::size_t > & pi ,
302 DiskFile< T > & out );
303
321template< class T >
322void permuteDirect( const DiskFile< T > & in ,
323 const DiskFile< std::size_t > & pi , DiskFile< T > & out );
324
325/*--------------------------------------------------------------------------*/
326
327} // end( namespace ADS )
328
329/*--------------------------------------------------------------------------*/
330/*-------------------------- IMPLEMENTATION --------------------------------*/
331/*--------------------------------------------------------------------------*/
332
333#include "ADS/external/impl/ExternalSorting.tpp"
334
335/*--------------------------------------------------------------------------*/
336
337#endif /* ExternalSorting.h included */
338
339/*--------------------------------------------------------------------------*/
340/*----------------------- End File ExternalSorting.h -----------------------*/
341/*--------------------------------------------------------------------------*/
The binary search of section 1.2 in a sorted vector : is compared with the middle item of the part ...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
A -ary heap of plain items, beyond the book: the heap of section 10.1 with children per node in a ve...
The sort of a file larger than the memory, beyond the book, as Knuth describes it for tapes,...
The tree of losers of a tournament among players, the structure of the merge of sorted sequences (K...
Random numbers as Knuth treats them (chapter 3 of The Art of Computer Programming),...
The sort that chooses its algorithm, beyond the book: sort() and stableSort() look at what they sort ...
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
The two-level memory model of Aggarwal and Vitter, simulated so that the algorithms of the external m...
a file of items on the disk of the model, in blocks of items
Definition TwoLevelMemory.h:199
std::uint64_t permutingLowerBound(std::size_t n, std::size_t M, std::size_t B)
the least I/Os of a permutation of items, the larger of and the smallest with
void distributionSort(const DiskFile< T > &in, DiskFile< T > &out, R &g, C less=C())
the items of in, sorted, into out, by the distribution with pivots from a random sample drawn by g
std::uint64_t sortingLowerBound(std::size_t n, std::size_t M, std::size_t B)
the least I/Os of a sort of items by comparisons, writes plus the reads that the tree of the I/Os n...
void multiwayMergeSort(const DiskFile< T > &in, DiskFile< T > &out, C less=C(), bool snowPlow=false)
the items of in, sorted, into out, by the mergesort of fan-in ; the runs by replacement selection if ...
std::uint64_t mergeSortIOs(std::size_t n, std::size_t M, std::size_t B, std::size_t k)
the I/Os of a mergesort of fan-in at most , with : a pass that forms the runs and one per level of ...
void permuteBySorting(const DiskFile< T > &in, const DiskFile< std::size_t > &pi, DiskFile< T > &out)
, by two sorts and three scans
void binaryMergeSort(const DiskFile< T > &in, DiskFile< T > &out, C less=C())
the items of in, sorted, into out, by the binary mergesort
void permuteDirect(const DiskFile< T > &in, const DiskFile< std::size_t > &pi, DiskFile< T > &out)
, one read per item at most
Definition ADT.h:96