ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
WordRangeMinimum.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------ File WordRangeMinimum.h -------------------------*/
3/*--------------------------------------------------------------------------*/
88/*--------------------------------------------------------------------------*/
89/*----------------------------- DEFINITIONS --------------------------------*/
90/*--------------------------------------------------------------------------*/
91
92#ifndef __ADS_WordRangeMinimum
93 #define __ADS_WordRangeMinimum
94/* self-identification: #endif constant */
95
96/*--------------------------------------------------------------------------*/
97/*------------------------------ INCLUDES ----------------------------------*/
98/*--------------------------------------------------------------------------*/
99
100#include "ADS/Contract.h"
101#include "ADS/Portable.h"
103#include "ADS/search/CountLess.h"
105
106#include <bit>
107#include <cstddef>
108#include <cstdint>
109#include <functional>
110#include <vector>
111
112/*--------------------------------------------------------------------------*/
113/*--------------------------- NAMESPACE ------------------------------------*/
114/*--------------------------------------------------------------------------*/
115
116namespace ADS
117{
118
119/*--------------------------------------------------------------------------*/
120/*------------------------ CLASS WordRangeMinimum --------------------------*/
121/*--------------------------------------------------------------------------*/
122
124template< class T , class Compare = std::less< T > >
126{
127
128/*--------------------------------------------------------------------------*/
129 public:
131 WordRangeMinimum( void ) = default;
132
154 explicit WordRangeMinimum( std::vector< T > A , Compare less = {} );
155
179 [[nodiscard]] std::size_t query( std::size_t i , std::size_t j ) const;
180
182 [[nodiscard]] std::size_t size( void ) const { return( f_A.size() ); }
183
186 [[nodiscard]] const T & operator[]( std::size_t i ) const;
187
188/*------------------------- THE STANDARD INTERFACE -------------------------*/
189
190 // a constant view of the array, random access
191
192 using value_type = T;
193 using size_type = std::size_t;
194 using difference_type = std::ptrdiff_t;
195 using const_reference = const T &;
197 using const_iterator = typename std::vector< T >::const_iterator;
200
202 [[nodiscard]] const_iterator begin( void ) const { return( f_A.begin() ); }
204 [[nodiscard]] const_iterator end( void ) const { return( f_A.end() ); }
206 [[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
208 [[nodiscard]] const_iterator cend( void ) const { return( end() ); }
209
210/*--------------------------------------------------------------------------*/
211 private:
215 struct Place
216 {
217 T suf;
218 T pre;
219 std::uint8_t si;
220 std::uint8_t pi;
221 };
222
224 struct Min
225 {
226 T v;
227 std::uint32_t i;
228 };
229
234 [[nodiscard]] Min better( const Min & a , const Min & b ) const {
235 const bool t = f_less( b.v , a.v );
236 return( Min{ t ? b.v : a.v , t ? b.i : a.i } );
237 }
238
240 void stacks( std::size_t b , std::size_t n );
241
242 std::vector< T > f_A;
243 std::vector< std::uint64_t , HugePageAllocator< std::uint64_t > > f_M;
245 std::vector< Place , HugePageAllocator< Place > > f_P;
246 std::vector< Min , HugePageAllocator< Min > > f_S;
247 std::size_t f_blocks = 0;
248 ADS_NO_UNIQUE_ADDRESS Compare f_less;
249
250 }; // end( class WordRangeMinimum )
251
252/*--------------------------------------------------------------------------*/
253
254} // end( namespace ADS )
255
256/*--------------------------------------------------------------------------*/
257/*-------------------------- IMPLEMENTATION --------------------------------*/
258/*--------------------------------------------------------------------------*/
259
260#include "ADS/search/impl/WordRangeMinimum.tpp"
261
262/*--------------------------------------------------------------------------*/
263
264#endif /* WordRangeMinimum.h included */
265
266/*--------------------------------------------------------------------------*/
267/*---------------------- End File WordRangeMinimum.h -----------------------*/
268/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The count of the items of a short array smaller than a key, the search in a node of the B-trees in ma...
An allocator for the large blocks of a structure, beyond the book: a request of at least one huge pag...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
The range minimum query, beyond the book: given an array of items of an ordered universe,...
const_iterator iterator
the same, constant
Definition WordRangeMinimum.h:199
std::size_t query(std::size_t i, std::size_t j) const
the place of the leftmost minimum of ,
std::size_t size_type
the type of the sizes
Definition WordRangeMinimum.h:193
std::size_t size(void) const
the number of the items
Definition WordRangeMinimum.h:182
const T & operator[](std::size_t i) const
the item of place
const T & const_reference
a reference to an item
Definition WordRangeMinimum.h:195
const_iterator begin(void) const
the first item
Definition WordRangeMinimum.h:202
std::ptrdiff_t difference_type
the type of the distances
Definition WordRangeMinimum.h:194
WordRangeMinimum(std::vector< T > A, Compare less={})
the structure on , in
const_iterator end(void) const
past the last item
Definition WordRangeMinimum.h:204
const_reference reference
the same, constant
Definition WordRangeMinimum.h:196
typename std::vector< T >::const_iterator const_iterator
an iterator on the items
Definition WordRangeMinimum.h:197
WordRangeMinimum(void)=default
an empty structure
const_iterator cend(void) const
past the last item
Definition WordRangeMinimum.h:208
T value_type
the type of the items
Definition WordRangeMinimum.h:192
const_iterator cbegin(void) const
the first item
Definition WordRangeMinimum.h:206
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81
Definition ADT.h:96