43# ifndef TPL_RANDOM_QUEUE_H
44# define TPL_RANDOM_QUEUE_H
46# include <gsl/gsl_rng.h>
146 for (It it = b; it != e; ++it)
153 for (
const auto & item :
l)
174 static_assert(std::is_copy_constructible_v<T>,
175 "Random_Set::put requires copyable T");
191 static_assert(std::is_move_constructible_v<T>,
192 "Random_Set::put requires moveable T");
193 array.append(std::forward<T>(item));
225 put(std::forward<T>(item));
252 std::swap(
array.access(pos),
array.access(0));
277 template <
class Operation>
284 template <
class Operation>
291 template <
class Operation>
298 template <
class Operation>
314 template <
typename T,
template <
typename>
class C>
318 c.
for_each([&q] (
const T & item) { q.
put(&
const_cast<T&
>(item)); });
335 template <
typename T,
template <
typename>
class C>
339 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.
#define ah_bad_alloc_if(C)
Throws std::bad_alloc if condition holds.
Iterator on the items of array.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
bool traverse(Operation &operation)
Conditional traversing of the random queue.
Random_Set(Random_Set &&s) noexcept
Move constructor.
gsl_rng * get_rng() const
The type of data contained in the queue.
void put(const T &item)
Insert an item by copy.
Random_Set(It b, It e)
Initialize the random queue with the items between b and e where these parameters are stl iterators.
bool traverse(Operation &operation) const
void set_seed(unsigned long seed) const noexcept
Set the seed of random number generator.
bool traverse(Operation &&operation=Operation())
Random_Set & operator=(const Random_Set &s)
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.
Random_Set(const Random_Set &s)
Copy constructor.
T & append(const T &item)
Insert randomly an item by copy.
bool traverse(Operation &&operation=Operation()) const
void swap(Random_Set &s)
Swap in constant time this with s
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.
Equality test for containers.
Common methods to the Aleph-w ( ) containers.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Common sequential searching methods on containers.
Mixin that adds STL begin()/end() and cbegin()/cend() to Aleph containers.
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.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Generic list of items stored in a container.
Lazy and scalable dynamic array implementation.