90#ifndef __ADS_MultiwayMerge
91 #define __ADS_MultiwayMerge
108#include <type_traits>
123template<
class T ,
class C >
124inline constexpr bool kNaturalOrder =
125 std::is_arithmetic_v< T > &&
126 ( std::is_same_v< C , std::less<> > || std::is_same_v< C ,
128 std::is_same_v< C , std::greater<> > ||
129 std::is_same_v< C , std::greater< T > > );
139template<
class T ,
class C = std::less<> >
150 [[nodiscard]] std::size_t
sources(
void )
const;
155 void start( std::size_t s ,
const T & x );
187 [[nodiscard]]
bool empty(
void )
const;
191 [[nodiscard]] std::size_t
winner(
void )
const;
195 [[nodiscard]]
const T &
top(
void )
const;
225 static constexpr bool kNatural = detail::kNaturalOrder< T , C >;
228 static constexpr bool kUp =
229 std::is_same_v< C , std::less<> > || std::is_same_v< C , std::less< T > >;
232 static constexpr bool kByValue = std::is_trivially_copyable_v< T > &&
233 (
sizeof( T ) <= 16 ) &&
234 std::is_default_constructible_v< T >;
236 using Key = std::conditional_t< kByValue , T , const T * >;
239 static constexpr std::uint32_t kSup = std::uint32_t( 1 ) << 31;
249 static const T & keyOf(
const Node & a );
252 static T supKey(
void );
255 [[nodiscard]]
bool beats(
const Node & a ,
const Node & b )
const;
258 void replay( Node cur );
261 [[nodiscard]]
bool winnerIsBest(
void )
const;
265 std::vector< Node > f_node;
266 std::vector< Node > f_leaf;
316template<
class I ,
class O ,
class C = std::less<> >
328#include "ADS/priority/impl/MultiwayMerge.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
void start(std::size_t s, const T &x)
before build(): the source starts with the key , whose address is kept if T is large
bool empty(void) const
whether all the sources are exhausted
std::size_t winner(void) const
the source with the smallest key
void build(void)
plays the matches of the keys given by start(), in time
FlatLoserTree(std::size_t k, C less=C())
the tree of sources, all exhausted
std::size_t sources(void) const
the number of sources,
const T & top(void) const
the key of the winner
void exhaustTop(void)
the winner is exhausted, and the matches on its path are replayed as by replaceTop(),...
void replaceTop(const T &x)
the winner takes the key , and the matches on its path are replayed, matches
O multiwayMerge(E &ex, const std::vector< std::pair< I, I > > &R, O out, C less=C())
the items of the sorted ranges merged into out on the threads of ex, the range of lower index first ...