43# ifndef TPL_RANDOM_QUEUE_H
44# define TPL_RANDOM_QUEUE_H
116 [[deprecated(
"it makes a Mersenne Twister in a set that has none: "
117 "use random_source(); it goes in 8.0.0")]]
129 [[deprecated(
"the generator is no longer of GSL: use random_source(); it goes in 8.0.0")]]
130 [[nodiscard]] gsl_rng * get_rng()
const {
return r.gsl(); }
148 [[nodiscard]]
size_t size()
const {
return array.size(); }
194 noexcept(std::is_nothrow_move_constructible_v<DynArray<T>>)
237 for (
It it = b; it != e; ++it)
244 for (
const auto & item :
l)
259 static_assert(std::is_copy_constructible_v<T>,
260 "Random_Set::put requires copyable T");
276 static_assert(std::is_move_constructible_v<T>,
277 "Random_Set::put requires moveable T");
278 array.append(std::forward<T>(item));
295 const size_t last_index =
array.size() - 1;
297 if (pos != last_index)
310 put(std::forward<T>(item));
311 const size_t last_index =
array.size() - 1;
313 if (pos != last_index)
324 T ret_val =
array.access(pos);
336 return array.access(pos);
373 template <
class Operation>
376 noexcept(
noexcept(
array.traverse(operation)))
378 return array.traverse(operation);
382 template <
class Operation>
385 noexcept(
noexcept(
array.traverse(operation)))
387 return array.traverse(operation);
391 template <
class Operation>
393 bool traverse(Operation && operation = Operation()) const
400 template <
class Operation>
402 bool traverse(Operation && operation = Operation())
418 template <
typename T,
template <
typename>
class C>
422 c.
for_each([&q] (
const T & item) { q.
put(&
const_cast<T&
>(item)); });
426 ret.append(*q.
get());
439 template <
typename T,
template <
typename>
class C>
443 c.
for_each([&q] (
const T & item) { q.
put(&
const_cast<T&
>(item)); });
Container traversal and functional operation mixins.
Exception handling system with formatted messages for Aleph-w.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
STL-compatible iterator adapters for Aleph containers.
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
Read-only view of an Aleph iterator: the iterator of a constant container.
Iterator on the items of array.
Doubly-linked list (defined in tpl_dynList.H).
A random number generator with the sequences of GSL's gsl_rng_mt19937.
void put(const T &item)
Insert an item by copy.
void set_seed(unsigned long seed) const
Seeds the Mersenne Twister of the set, as gsl_rng_set() did: the positions are from then on those of ...
Random_Set(It b, It e)
Initialize the random queue with the items between b and e where these parameters are stl iterators.
Gsl_Compatible_Rng & rng() const
The Mersenne Twister of the set, which a set that was given no seed makes here, and draws from it fro...
Random_Set(Random_Set &&s) noexcept(std::is_nothrow_move_constructible_v< DynArray< T > >)
Take the items and the generator of another set, which is left empty, and draws from then on from a S...
Random_Source & random_source() noexcept
The type of data contained in the queue.
bool traverse(Operation &&operation=Operation()) const noexcept(noexcept(array.traverse(operation)))
See traverse(Operation & operation).
Random_Set & operator=(const Random_Set &s)
Random_Set()
A random queue that draws its positions from a SplitMix64 with a seed of its own.
bool is_empty() const
Return true if the queue is empty.
T Item_Type
The type of set.
T get()
Extract randomly an item.
T & append(T &&item)
Insert randomly an item by moving.
void put(T &&item)
Insert an item by moving.
bool traverse(Operation &&operation=Operation()) noexcept(noexcept(array.traverse(operation)))
See traverse(Operation & operation).
const Random_Source & random_source() const noexcept
The source of random numbers, to look at it: its engine, or whether it is equal to another one.
Random_Set(const Random_Set &s)
Copy constructor.
T & append(const T &item)
Insert randomly an item by copy.
bool traverse(Operation &operation) noexcept(noexcept(array.traverse(operation)))
Conditional traversing of the random queue.
Random_Set(const DynList< T > &l)
Initialize the random queue with the elements of l
Random_Set(std::initializer_list< T > l)
Initialize the random queue with the items of l
size_t size() const
Return the number of items in the queue.
bool traverse(Operation &operation) const noexcept(noexcept(array.traverse(operation)))
See traverse(Operation & operation).
void swap(Random_Set &s) noexcept(noexcept(array.swap(s.array)))
Swap in constant time this with s: their items and their generators.
The source of random numbers of a randomized structure, which draws from one of two generators.
@ Mersenne_Twister
A Gsl_Compatible_Rng, in dynamic memory.
Gsl_Compatible_Rng & mersenne_twister()
The Mersenne Twister of the source, which is its engine from now on.
void seed(const std::uint64_t s) noexcept
Draws from now on from the SplitMix64 of a seed.
void swap(Random_Source &o) noexcept
Swaps the generators, with their states.
std::uint64_t uniform_int_ne(const std::uint64_t n) noexcept
An integer in [0, n), each with the same probability, without checking n.
Common methods to the Aleph-w ( ) containers.
void for_each(Operation &operation) const
Traverse all the container and performs an operation on each element.
Common sequential searching methods on containers.
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
f(args...) is a valid call whose result is usable as a condition.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
C< T * > shuffle_ptr(const C< T > &c)
Return a random sequence of pointers to items of a sequence.
std::decay_t< typename HeadC::Item_Type > T
auto shuffle(const C< T > &c)
Randomly shuffle a sequence.
Iterator of the items of the queue.
typename DynArray< T >::Iterator Base
Iterator() noexcept=default
Default constructor creates an "end" iterator.
Iterator(const Random_Set &)=delete
A constant set is iterated through Const_Iterator.
Generic list of items stored in a container.
Lazy and scalable dynamic array implementation.