|
ADS
Algorithms and Data Structures
|
The engineered merge of \( k \) sorted sequences, beyond the book [see LoserTree.h for the tree of losers of the notes]: FlatLoserTree, the tree of losers with the keys in its nodes, for the merges whose sequences arrive a block at a time, and multiwayMerge(), the merge of \( k \) sorted ranges in memory, by a funnel of binary mergers. More...
#include "ADS/Contract.h"#include "ADS/sort/Sorted.h"#include <algorithm>#include <cstddef>#include <cstdint>#include <cstring>#include <functional>#include <iterator>#include <limits>#include <type_traits>#include <utility>#include <vector>#include "ADS/priority/impl/MultiwayMerge.tpp"Go to the source code of this file.
Classes | |
| class | ADS::FlatLoserTree< T, C > |
| the tree of losers of \( k \) sources with the keys in its nodes, the winner the smallest key by less, the lower source on equal keys More... | |
Namespaces | |
| namespace | ADS |
Functions | |
| template<class I, class O, class C = std::less<>> | |
| O | ADS::multiwayMerge (const std::vector< std::pair< I, I > > &R, O out, C less=C()) |
| the items of the sorted ranges \( R[ i ] = [ \mathit{first} , \mathit{last} ) \) merged into out, the range of lower index first on equal items; the end of the output | |
The engineered merge of \( k \) sorted sequences, beyond the book [see LoserTree.h for the tree of losers of the notes]: FlatLoserTree, the tree of losers with the keys in its nodes, for the merges whose sequences arrive a block at a time, and multiwayMerge(), the merge of \( k \) sorted ranges in memory, by a funnel of binary mergers.
Compared with the literature: the tree of losers with the keys in the nodes is that of Knuth (5.4.1), whose cache behavior Sanders analyzed for his sequence heaps; the multiway merge of the MCSTL of Singler, Sanders and Putze, in the parallel mode of libstdc++ and in tlx, has the same tree, with branches on the matches, and special merges of 3 and 4 sequences. The funnel is the \( k \)-merger of the cache-oblivious funnelsort of Frigo, Leiserson, Prokop and Ramachandran, made of binary mergers as Brodal, Fagerberg and Vinther engineered it; with no jump in its steps it beats the tree of losers by about 1.7 times on random keys, where every match of the tree is a coin toss for the predictor.
The contracts [see Contract.h]: \( k \ge 1 \) sources; top(), winner() and the replays on a tree that is not empty; the ranges of multiwayMerge() sorted by less, an audit, and the output their items sorted, a stable merge, an audit. The functions are defined in MultiwayMerge.tpp.