Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Random_Set< T > Class Template Reference

Random queue. More...

#include <tpl_random_queue.H>

Inheritance diagram for Aleph::Random_Set< T >:
[legend]
Collaboration diagram for Aleph::Random_Set< T >:
[legend]

Classes

struct  Iterator
 Iterator of the items of the queue. More...
 

Public Types

using Set_Type = Random_Set
 
using Item_Type = T
 The type of set.
 
- Public Types inherited from StlAlephIterator< Random_Set< T > >
using iterator = StlIterator< Random_Set< T > >
 
using const_iterator = StlConstIterator< Random_Set< T > >
 

Public Member Functions

gsl_rngget_rng () const
 The type of data contained in the queue.
 
void set_seed (unsigned long seed) const noexcept
 Set the seed of random number generator.
 
size_t size () const
 Return the number of items in the queue.
 
 Random_Set ()
 
void swap (Random_Set &s)
 Swap in constant time this with s
 
 Random_Set (const Random_Set &s)
 Copy constructor.
 
 Random_Set (Random_Set &&s) noexcept
 Move constructor.
 
Random_Setoperator= (const Random_Set &s)
 
Random_Setoperator= (Random_Set &&s) noexcept
 
 Random_Set (const DynList< T > &l)
 Initialize the random queue with the elements of l
 
template<class It >
 Random_Set (It b, It e)
 Initialize the random queue with the items between b and e where these parameters are stl iterators.
 
 Random_Set (std::initializer_list< T > l)
 Initialize the random queue with the items of l
 
 ~Random_Set ()
 
void put (const T &item)
 Insert an item by copy.
 
void put (T &&item)
 Insert an item by moving.
 
Tappend (const T &item)
 Insert randomly an item by copy.
 
Tappend (T &&item)
 Insert randomly an item by moving.
 
T get ()
 Extract randomly an item.
 
T pick () const
 
bool is_empty () const
 Return true if the queue is empty.
 
template<class Operation >
bool traverse (Operation &operation)
 Conditional traversing of the random queue.
 
template<class Operation >
bool traverse (Operation &operation) const
 
template<class Operation >
bool traverse (Operation &&operation=Operation()) const
 
template<class Operation >
bool traverse (Operation &&operation=Operation())
 
- Public Member Functions inherited from LocateFunctions< Random_Set< T >, T >
auto get_it () const
 Return a properly initialized iterator positioned at the first item on the container.
 
auto get_it (const size_t pos) const
 Return a properly initialized iterator positioned at the pos item on the container.
 
auto get_itor () const
 Alias of get_it().
 
T & nth_ne (const size_t n) noexcept
 Return the n‑th element without bounds checking.
 
const T & nth_ne (const size_t n) const noexcept
 Const overload of nth_ne(size_t).
 
T & nth (const size_t n)
 Return the n-th item of container.
 
const T & nth (const size_t n) const
 Const overload of nth(size_t).
 
T * find_ptr (Operation &operation) noexcept(operation_is_noexcept< Operation >())
 Find a pointer to an item in the container according to a searching criteria.
 
const T * find_ptr (Operation &operation) const noexcept(operation_is_noexcept< Operation >())
 Const overload of find_ptr(Operation&).
 
const T * find_ptr (Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
 Overload of find_ptr(Operation&) const that accepts rvalues.
 
T * find_ptr (Operation &&operation) noexcept(operation_is_noexcept< Operation >())
 Overload of find_ptr(Operation&) that accepts rvalues.
 
size_t find_index (Operation &operation) const noexcept(operation_is_noexcept< Operation >())
 Find the position of an item in the container according to a searching criteria.
 
size_t find_index (Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
 Overload of find_index(Operation&) that accepts rvalues.
 
std::tuple< bool, T > find_item (Operation &operation) noexcept(operation_is_noexcept< Operation >())
 Safe sequential searching of an item matching a criteria.
 
std::tuple< bool, T > find_item (Operation &operation) const noexcept(operation_is_noexcept< Operation >())
 
std::tuple< bool, T > find_item (Operation &&operation) noexcept(operation_is_noexcept< Operation >())
 
std::tuple< bool, T > find_item (Operation &&operation) const noexcept(operation_is_noexcept< Operation >())
 
- Public Member Functions inherited from FunctionalMethods< Random_Set< T >, T >
void emplace (Args &&... args)
 Appends a new element into the container by constructing it in-place with the given args.
 
void emplace_end (Args &&... args)
 
void emplace_ins (Args &&... args)
 Insert a new element into the container by constructing it in-place with the given args.
 
size_t ninsert (Args ... args)
 Insert n variadic items.
 
size_t nappend (Args ... args)
 Append n variadic items.
 
void for_each (Operation &operation)
 Traverse all the container and performs an operation on each element.
 
void for_each (Operation &operation) const
 Const overload of for_each(Operation&).
 
void for_each (Operation &&operation) const
 Overload of for_each(Operation&) const that accepts rvalues.
 
void for_each (Operation &&operation)
 Overload of for_each(Operation&) that accepts rvalues.
 
void each (Operation &operation)
 Alias of for_each(Operation&).
 
void each (Operation &operation) const
 Const alias of for_each(Operation&).
 
void each (Operation &&operation) const
 Const alias of for_each(Operation&) that accepts rvalues.
 
void each (Operation &&operation)
 Alias of for_each(Operation&) that accepts rvalues.
 
void each (size_t pos, const size_t slice, Operation &operation) const
 Traverse the container starting at pos taking one item every slice, performing a mutable operation on each visited element.
 
void each (const size_t pos, const size_t slice, Operation &&operation) const
 
void mutable_for_each (Operation &operation)
 
void mutable_for_each (Operation &&operation)
 
bool all (Operation &operation) const
 Check if all the elements of container satisfy a condition.
 
bool all (Operation &&operation) const
 Overload of all(Operation&) that accepts rvalues.
 
bool exists (Operation &op) const
 Test for existence in the container of an element satisfying a criteria.
 
bool exists (Operation &&op) const
 Overload of exists(Operation&) that accepts rvalues.
 
Aleph::DynList< __T > maps (Operation &op) const
 Map the elements of the container.
 
Aleph::DynList< __T > maps (Operation &&op) const
 Overload of maps(Operation&) that accepts rvalues.
 
Aleph::DynList< __Tmaps_if (Prop prop, Operation &op) const
 Conditional mapping of the elements of the container.
 
Aleph::DynList< __Tmaps_if (Prop prop, Operation &&op) const
 Overload of maps_if(Prop, Operation&) that accepts rvalues.
 
Aleph::DynList< T > to_dynlist () const
 Convert container to DynList.
 
std::vector< T > to_vector () const
 Convert container to std::vector.
 
__T foldl (const __T &init, Op &op) const
 Fold the elements of the container to a specific result.
 
__T foldl (const __T &init, Op &&op=Op()) const
 Overload of foldl(const __T&, Op&) that accepts rvalues.
 
__T fold_left (const __T &init, Op &op) const
 Alias for foldl with the same accumulator type.
 
__T fold_left (const __T &init, Op &&op=Op()) const
 Overload of fold_left(const __T&, Op&) that accepts rvalues.
 
fold (const T &init, Operation &operation) const
 Simplified version of foldl() where the folded type is the same type of elements stored in the container.
 
fold (const T &init, Operation &&operation) const
 Overload of fold(const T&, Operation&) that accepts rvalues.
 
Aleph::DynList< T > filter (Operation &operation) const
 Filter the elements of a container according to a matching criteria.
 
Aleph::DynList< T > filter (Operation &&operation) const
 Overload of filter(Operation&) that accepts rvalues.
 
Aleph::DynList< const T * > ptr_filter (Operation &operation) const
 Filter the elements of a container according to a matching criteria and return a pointer to the matched items in the container.
 
Aleph::DynList< const T * > ptr_filter (Operation &&operation) const
 Overload of ptr_filter(Operation&) that accepts rvalues.
 
Aleph::DynList< std::tuple< T, size_t > > pfilter (Operation &operation) const
 Filter the elements of a container according to a matching criteria and determine its positions respect to the traversal of container.
 
Aleph::DynList< std::tuple< T, size_t > > pfilter (Operation &&operation) const
 Overload of pfilter(Operation&) that accepts rvalues.
 
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition (Operation &op) const
 Exclusive partition of container according to a filter criteria.
 
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition (Operation &&op) const
 Overload of partition(Operation&) that accepts rvalues.
 
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > partition (size_t n) const
 Exclusive partition of container in the nth item.
 
std::pair< Aleph::DynList< T >, Aleph::DynList< T > > split_half () const
 Split the container into two halves by alternating elements.
 
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition (Operation &op) const
 Exclusive partition of container according to a filter criteria.
 
std::tuple< Aleph::DynList< T >, Aleph::DynList< T > > tpartition (Operation &&op) const
 Overload of tpartition(Operation&) that accepts rvalues.
 
size_t length () const noexcept
 Count the number of elements of a container.
 
Aleph::DynList< T > rev () const
 Return a list with the elements of container in reverse order respect to its traversal order.
 
Aleph::DynList< T > take (const size_t n) const
 Return a list with the first n elements seen in the container during its traversal.
 
Aleph::DynList< T > take (size_t i, const size_t j, const size_t step=1) const
 Return a list with elements seen in the container between i and j position respect to its traversal.
 
Aleph::DynList< T > drop (const size_t n) const
 Drop the first n elements seen in the container during its traversal.
 
void mutable_drop (const size_t n)
 Drop the first n elements seen from container.
 
- Public Member Functions inherited from GenericItems< Container, T >
Aleph::DynList< T > items () const
 Return a list of all the elements of a container sorted by traversal order.
 
Aleph::DynList< T > keys () const
 
- Public Member Functions inherited from EqualToMethod< Random_Set< T > >
bool equal_to (const Random_Set< T > &r) const noexcept
 Test if elements of this are exactly contained in another container.
 
bool operator== (const Random_Set< T > &r) const noexcept
 
bool operator!= (const Random_Set< T > &r) const noexcept
 Negation of equal_to()
 
- Public Member Functions inherited from StlAlephIterator< Random_Set< T > >
iterator begin () noexcept
 Return an STL-compatible iterator to the first element.
 
const_iterator begin () const noexcept
 Return a const iterator to the first element.
 
iterator end () noexcept
 Return an STL-compatible end iterator.
 
const_iterator end () const noexcept
 Return a const end iterator.
 
const_iterator cbegin () const noexcept
 Return a const iterator to the first element.
 
const_iterator cend () const noexcept
 Return a const end iterator.
 

Private Attributes

DynArray< Tarray
 
gsl_rngr = nullptr
 

Additional Inherited Members

Detailed Description

template<class T>
class Aleph::Random_Set< T >

Random queue.

Random_Set<T> implements a random set of items which are inserted and extracted in a random order.

The class internally uses the gsl random number generator of GSL - GNU Scientific Library. By default, the Mersene twister is used and the seed is taken from system time.

Definition at line 68 of file tpl_random_queue.H.

Member Typedef Documentation

◆ Item_Type

The type of set.

Definition at line 84 of file tpl_random_queue.H.

◆ Set_Type

template<class T >
using Aleph::Random_Set< T >::Set_Type = Random_Set

Definition at line 82 of file tpl_random_queue.H.

Constructor & Destructor Documentation

◆ Random_Set() [1/6]

◆ Random_Set() [2/6]

template<class T >
Aleph::Random_Set< T >::Random_Set ( const Random_Set< T > &  s)
inline

Copy constructor.

Definition at line 111 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::append(), and FunctionalMethods< Container, T >::for_each().

◆ Random_Set() [3/6]

template<class T >
Aleph::Random_Set< T >::Random_Set ( Random_Set< T > &&  s)
inlinenoexcept

Move constructor.

Definition at line 117 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::swap().

◆ Random_Set() [4/6]

template<class T >
Aleph::Random_Set< T >::Random_Set ( const DynList< T > &  l)
inline

Initialize the random queue with the elements of l

Definition at line 137 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::append(), FunctionalMethods< Container, T >::for_each(), and l.

◆ Random_Set() [5/6]

template<class T >
template<class It >
Aleph::Random_Set< T >::Random_Set ( It  b,
It  e 
)
inline

Initialize the random queue with the items between b and e where these parameters are stl iterators.

Definition at line 144 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::append().

◆ Random_Set() [6/6]

template<class T >
Aleph::Random_Set< T >::Random_Set ( std::initializer_list< T l)
inline

Initialize the random queue with the items of l

Definition at line 151 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::append(), and l.

◆ ~Random_Set()

Member Function Documentation

◆ append() [1/2]

template<class T >
T & Aleph::Random_Set< T >::append ( const T item)
inline

Insert randomly an item by copy.

append(item) performs a random choice. Use this method if you must obtain fastly a random array. It returns a reference to the stored element so callers can mutate it in place, same as other Aleph sequences.

Parameters
[in]itemreference to the item to be inserted
Returns
reference to the inserted item inside the queue
Exceptions
bad_allocif there is no enough memory

Definition at line 207 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::array, FunctionalMethods< Random_Set< T >, T >::maps(), Aleph::Random_Set< T >::put(), and Aleph::Random_Set< T >::r.

Referenced by Aleph::Random_Set< T >::Random_Set(), Aleph::Random_Set< T >::Random_Set(), Aleph::Random_Set< T >::Random_Set(), Aleph::Random_Set< T >::Random_Set(), Aleph::Random_Set< T >::operator=(), TEST(), TEST(), TEST(), and TEST().

◆ append() [2/2]

template<class T >
T & Aleph::Random_Set< T >::append ( T &&  item)
inline

Insert randomly an item by moving.

Parameters
[in]itemrvalue reference to the item to be inserted
Returns
reference to the inserted item inside the queue
Exceptions
bad_allocif there is no enough memory

Definition at line 223 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::array, FunctionalMethods< Random_Set< T >, T >::maps(), Aleph::Random_Set< T >::put(), and Aleph::Random_Set< T >::r.

◆ get()

◆ get_rng()

template<class T >
gsl_rng * Aleph::Random_Set< T >::get_rng ( ) const
inline

The type of data contained in the queue.

Return a pointer to random number generator

Definition at line 87 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::r.

◆ is_empty()

template<class T >
bool Aleph::Random_Set< T >::is_empty ( ) const
inline

Return true if the queue is empty.

Definition at line 257 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::array.

Referenced by Aleph::shuffle(), Aleph::shuffle_ptr(), TEST(), TEST(), TEST(), and TEST().

◆ operator=() [1/2]

◆ operator=() [2/2]

template<class T >
Random_Set & Aleph::Random_Set< T >::operator= ( Random_Set< T > &&  s)
inlinenoexcept

Definition at line 130 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::swap().

◆ pick()

◆ put() [1/2]

template<class T >
void Aleph::Random_Set< T >::put ( const T item)
inline

Insert an item by copy.

put() does not perform any random operation. It simply puts the item at the end of an internal sequence. It is when the item is extracted that a random choice is done.

Parameters
[in]itemreference to the item to be inserted
Exceptions
bad_allocif there is no enough memory

Definition at line 172 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::array.

Referenced by Aleph::Random_Set< T >::append(), Aleph::Random_Set< T >::append(), Aleph::shuffle(), Aleph::shuffle_ptr(), TEST(), TEST(), and TEST().

◆ put() [2/2]

template<class T >
void Aleph::Random_Set< T >::put ( T &&  item)
inline

Insert an item by moving.

put() does not perform any random operation. It simply puts the item at the end of an internal sequence. It is when the item is extracted that a random choice is done.

Parameters
[in]itemrvalue reference to the item to be moved
Exceptions
bad_allocif there is no enough memory

Definition at line 189 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::array.

◆ set_seed()

template<class T >
void Aleph::Random_Set< T >::set_seed ( unsigned long  seed) const
inlinenoexcept

Set the seed of random number generator.

Definition at line 90 of file tpl_random_queue.H.

References FunctionalMethods< Random_Set< T >, T >::maps(), and Aleph::Random_Set< T >::r.

◆ size()

template<class T >
size_t Aleph::Random_Set< T >::size ( ) const
inline

Return the number of items in the queue.

Definition at line 93 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::array.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ swap()

template<class T >
void Aleph::Random_Set< T >::swap ( Random_Set< T > &  s)
inline

Swap in constant time this with s

Definition at line 104 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::array, and Aleph::Random_Set< T >::r.

Referenced by Aleph::Random_Set< T >::Random_Set(), and Aleph::Random_Set< T >::operator=().

◆ traverse() [1/4]

template<class T >
template<class Operation >
bool Aleph::Random_Set< T >::traverse ( Operation &&  operation = Operation())
inline

◆ traverse() [2/4]

template<class T >
template<class Operation >
bool Aleph::Random_Set< T >::traverse ( Operation &&  operation = Operation()) const
inline

◆ traverse() [3/4]

template<class T >
template<class Operation >
Aleph::Random_Set< T >::traverse ( Operation operation)
inline

Conditional traversing of the random queue.

Parameters
[in]operationto be performed on each item. If it return true then the traversing continues; otherwise stops.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 278 of file tpl_random_queue.H.

References Aleph::Random_Set< T >::array, and FunctionalMethods< Random_Set< T >, T >::maps().

Referenced by TEST(), TEST(), TEST(), Aleph::Random_Set< T >::traverse(), Aleph::Random_Set< T >::traverse(), and Aleph::Random_Set< T >::traverse().

◆ traverse() [4/4]

template<class T >
template<class Operation >
bool Aleph::Random_Set< T >::traverse ( Operation operation) const
inline

Member Data Documentation

◆ array

◆ r


The documentation for this class was generated from the following files: