ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
RandomQueue.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*--------------------------- File RandomQueue.h ---------------------------*/
3
/*--------------------------------------------------------------------------*/
39
/*--------------------------------------------------------------------------*/
40
/*----------------------------- DEFINITIONS --------------------------------*/
41
/*--------------------------------------------------------------------------*/
42
43
#ifndef __ADS_RandomQueue
44
#define __ADS_RandomQueue
45
/* self-identification: #endif constant */
46
47
/*--------------------------------------------------------------------------*/
48
/*------------------------------ INCLUDES ----------------------------------*/
49
/*--------------------------------------------------------------------------*/
50
51
#include "
ADS/Contract.h
"
52
#include "
ADS/Portable.h
"
53
#include "
ADS/Wide.h
"
54
#include "
ADS/dictionary/RandomHashing.h
"
55
56
#include <cstddef>
57
#include <cstdint>
58
#include <utility>
59
#include <vector>
60
61
/*--------------------------------------------------------------------------*/
62
/*--------------------------- NAMESPACE ------------------------------------*/
63
/*--------------------------------------------------------------------------*/
64
65
namespace
ADS
66
{
67
68
/*--------------------------------------------------------------------------*/
69
/*--------------------------- CLASS RandomQueue ----------------------------*/
70
/*--------------------------------------------------------------------------*/
71
73
template
<
class
T >
74
class
RandomQueue
75
{
76
77
/*--------------------------------------------------------------------------*/
78
public
:
79
using
Item
= T;
80
82
explicit
RandomQueue
( std::uint64_t seed = 1 ) : f_g( seed ) { }
83
85
[[nodiscard]]
bool
empty
(
void
)
const
{
return
( f_A.empty() ); }
86
88
[[nodiscard]] std::size_t
size
(
void
)
const
{
return
( f_A.size() ); }
89
91
void
push
(
const
T & x ) { f_A.push_back( x ); }
92
94
void
push
( T && x ) { f_A.push_back( std::move( x ) ); }
95
110
T
pop
(
void
);
111
114
[[nodiscard]]
const
T &
sample
(
void
);
115
132
[[nodiscard]] std::size_t
uniform
( std::size_t n );
133
135
void
clear
(
void
) { f_A.clear(); }
136
138
[[nodiscard]]
const
std::vector< T > &
items
(
void
)
const
{
return
( f_A ); }
139
140
/*--------------------------------------------------------------------------*/
141
private
:
142
std::vector< T > f_A;
143
SplitMix64
f_g;
144
145
};
// end( class RandomQueue )
146
147
/*--------------------------------------------------------------------------*/
148
149
}
// end( namespace ADS )
150
151
/*--------------------------------------------------------------------------*/
152
/*-------------------------- IMPLEMENTATION --------------------------------*/
153
/*--------------------------------------------------------------------------*/
154
155
#include "ADS/queue/impl/RandomQueue.tpp"
156
157
/*--------------------------------------------------------------------------*/
158
159
#endif
/* RandomQueue.h included */
160
161
/*--------------------------------------------------------------------------*/
162
/*------------------------- End File RandomQueue.h -------------------------*/
163
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
Portable.h
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
RandomHashing.h
Hashing with random tables, beyond the book:
Wide.h
The arithmetic of two words that C++20 does not spell, in one form for every compiler: the product of...
ADS::RandomQueue::Item
T Item
the type of the items
Definition
RandomQueue.h:79
ADS::RandomQueue::uniform
std::size_t uniform(std::size_t n)
a place uniform in , by the multiplication of Lemire
ADS::RandomQueue::items
const std::vector< T > & items(void) const
the items, in no order
Definition
RandomQueue.h:138
ADS::RandomQueue::pop
T pop(void)
takes out an item chosen uniformly at random and returns it, (Morin's remove())
ADS::RandomQueue::size
std::size_t size(void) const
the number of items
Definition
RandomQueue.h:88
ADS::RandomQueue::empty
bool empty(void) const
true if there is no item
Definition
RandomQueue.h:85
ADS::RandomQueue::push
void push(T &&x)
puts in, moved
Definition
RandomQueue.h:94
ADS::RandomQueue::RandomQueue
RandomQueue(std::uint64_t seed=1)
the empty queue, its draws from the seed
Definition
RandomQueue.h:82
ADS::RandomQueue::push
void push(const T &x)
puts in, amortized (Morin's add( x ))
Definition
RandomQueue.h:91
ADS::RandomQueue::clear
void clear(void)
removes all the items
Definition
RandomQueue.h:135
ADS::RandomQueue::sample
const T & sample(void)
an item chosen uniformly at random, left in
ADS::SplitMix64
the generator SplitMix64, a UniformRandomBitGenerator
Definition
RandomHashing.h:122
ADS
Definition
ADT.h:96
ADS
queue
RandomQueue.h
Generated by
1.17.0