ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
QuicksortAdversary.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------ File QuicksortAdversary.h -----------------------*/
3/*--------------------------------------------------------------------------*/
46/*--------------------------------------------------------------------------*/
47/*----------------------------- DEFINITIONS --------------------------------*/
48/*--------------------------------------------------------------------------*/
49
50#ifndef __ADS_QuicksortAdversary
51 #define __ADS_QuicksortAdversary
52/* self-identification: #endif constant */
53
54/*--------------------------------------------------------------------------*/
55/*------------------------------ INCLUDES ----------------------------------*/
56/*--------------------------------------------------------------------------*/
57
58#include "ADS/Contract.h"
59
60#include <cstddef>
61#include <vector>
62
63/*--------------------------------------------------------------------------*/
64/*--------------------------- NAMESPACE ------------------------------------*/
65/*--------------------------------------------------------------------------*/
66
67namespace ADS
68{
69
70/*--------------------------------------------------------------------------*/
71/*----------------------- CLASS QuicksortAdversary -------------------------*/
72/*--------------------------------------------------------------------------*/
73
77{
78
79/*--------------------------------------------------------------------------*/
80 public:
82 explicit QuicksortAdversary( std::size_t n );
83
86 class Less
87 {
88 public:
90 explicit Less( QuicksortAdversary & a ) : f_a( &a ) { }
91
110 bool operator()( std::size_t x , std::size_t y ) const;
111
112 private:
113 QuicksortAdversary * f_a;
114 };
115
117 [[nodiscard]] Less less( void ) { return( Less( *this ) ); }
118
120 [[nodiscard]] std::vector< std::size_t > items( void ) const;
121
123 [[nodiscard]] std::size_t comparisons( void ) const { return( f_count ); }
124
129 [[nodiscard]] std::vector< std::size_t > input( void ) const;
130
131/*--------------------------------------------------------------------------*/
132 private:
133 std::vector< std::size_t > f_val;
134 std::size_t f_solid = 0;
135 std::size_t f_candidate;
136 std::size_t f_count = 0;
137
138 }; // end( class QuicksortAdversary )
139
140/*--------------------------------------------------------------------------*/
141
142} // end( namespace ADS )
143
144/*--------------------------------------------------------------------------*/
145/*-------------------------- IMPLEMENTATION --------------------------------*/
146/*--------------------------------------------------------------------------*/
147
148#include "ADS/sort/impl/QuicksortAdversary.tpp"
149
150/*--------------------------------------------------------------------------*/
151
152#endif /* QuicksortAdversary.h included */
153
154/*--------------------------------------------------------------------------*/
155/*--------------------- End File QuicksortAdversary.h ----------------------*/
156/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
the comparator to pass to a sort, by value: a pointer to the adversary, which must outlive it
Definition QuicksortAdversary.h:87
Less(QuicksortAdversary &a)
the comparator of the adversary
Definition QuicksortAdversary.h:90
bool operator()(std::size_t x, std::size_t y) const
true if the value of is smaller than that of , after freezing one of them if both are gas
Less less(void)
the comparator of this adversary
Definition QuicksortAdversary.h:117
std::vector< std::size_t > input(void) const
the value of each item, the gas frozen in the order of the items after the frozen ones: an input of ...
std::size_t comparisons(void) const
the number of calls of the comparator so far
Definition QuicksortAdversary.h:123
std::vector< std::size_t > items(void) const
the items to sort,
QuicksortAdversary(std::size_t n)
the adversary of the items , all gas
Definition ADT.h:96