ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
LoserTree.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*--------------------------- File LoserTree.h -----------------------------*/
3
/*--------------------------------------------------------------------------*/
54
/*--------------------------------------------------------------------------*/
55
/*----------------------------- DEFINITIONS --------------------------------*/
56
/*--------------------------------------------------------------------------*/
57
58
#ifndef __ADS_LoserTree
59
#define __ADS_LoserTree
60
/* self-identification: #endif constant */
61
62
/*--------------------------------------------------------------------------*/
63
/*------------------------------ INCLUDES ----------------------------------*/
64
/*--------------------------------------------------------------------------*/
65
66
#include "
ADS/Contract.h
"
67
#include "
ADS/sort/Sorted.h
"
68
69
#include <algorithm>
70
#include <cstddef>
71
#include <functional>
72
#include <optional>
73
#include <utility>
74
#include <vector>
75
76
/*--------------------------------------------------------------------------*/
77
/*--------------------------- NAMESPACE ------------------------------------*/
78
/*--------------------------------------------------------------------------*/
79
80
namespace
ADS
81
{
82
83
/*--------------------------------------------------------------------------*/
84
/*---------------------------- CLASS LoserTree -----------------------------*/
85
/*--------------------------------------------------------------------------*/
86
89
template
<
class
T ,
class
C = std::less<> >
90
class
LoserTree
91
{
92
93
/*--------------------------------------------------------------------------*/
94
public
:
124
explicit
LoserTree
( std::vector< std::optional< T > > keys , C less = C() );
125
127
[[nodiscard]] std::size_t
players
(
void
)
const
;
128
130
[[nodiscard]]
bool
empty
(
void
)
const
;
131
134
[[nodiscard]] std::size_t
winner
(
void
)
const
;
135
138
[[nodiscard]]
const
T &
top
(
void
)
const
;
139
159
void
replace
( std::optional< T > key );
160
161
/*--------------------------------------------------------------------------*/
162
private
:
164
[[nodiscard]]
bool
beats( std::size_t i , std::size_t j )
const
;
165
167
[[nodiscard]]
bool
winnerIsBest(
void
)
const
;
168
169
std::vector< std::optional< T > > f_key;
170
std::vector< std::size_t > f_node;
172
C f_less;
173
174
};
// end( class LoserTree )
175
197
template
<
class
T ,
class
C = std::less<> >
198
std::vector< T >
kWayMerge
(
const
std::vector< std::vector< T > > & R ,
199
C less = C() );
200
201
/*--------------------------------------------------------------------------*/
202
203
}
// end( namespace ADS )
204
205
/*--------------------------------------------------------------------------*/
206
/*-------------------------- IMPLEMENTATION --------------------------------*/
207
/*--------------------------------------------------------------------------*/
208
209
#include "ADS/priority/impl/LoserTree.tpp"
210
211
/*--------------------------------------------------------------------------*/
212
213
#endif
/* LoserTree.h included */
214
215
/*--------------------------------------------------------------------------*/
216
/*-------------------------- End File LoserTree.h --------------------------*/
217
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
Sorted.h
The checks of the contracts of the sorts [see Contract.h]: a copy of the input kept only when the aud...
ADS::LoserTree::winner
std::size_t winner(void) const
the player with the smallest key
ADS::LoserTree::replace
void replace(std::optional< T > key)
the winner takes the key, or is exhausted if it is empty, and the matches on its path are replayed,...
ADS::LoserTree::empty
bool empty(void) const
whether all the players are exhausted
ADS::LoserTree::top
const T & top(void) const
the key of the winner
ADS::LoserTree::LoserTree
LoserTree(std::vector< std::optional< T > > keys, C less=C())
the tree of the players with their first keys, an empty key for an exhausted one, its matches played...
ADS::LoserTree::players
std::size_t players(void) const
the number of players,
ADS::kWayMerge
std::vector< T > kWayMerge(const std::vector< std::vector< T > > &R, C less=C())
the items of the sorted vectors of , merged through a tree of losers
ADS
Definition
ADT.h:96
ADS
priority
LoserTree.h
Generated by
1.17.0