ant
A2 ant: class-based analysis framework
ant::analysis::utils::NchooseK< T > Class Template Reference

KofNvector class: Generate all combinations when drawing k elements out of a vector. More...

#include <Combinatorics.h>

+ Collaboration diagram for ant::analysis::utils::NchooseK< T >:

Classes

class  const_iterator
 Iterator over the elements of a combination. Used to iterate over the current combination. More...
 

Public Types

typedef T value_type
 

Public Member Functions

 NchooseK (const std::vector< T > &data, index_type k)
 KofNvector. More...
 
const T & at (const size_t i) const
 Access the ith element of the currently drawn combination. More...
 
bool next ()
 Generate the next combination. More...
 
const_iterator begin () const
 
const_iterator end () const
 
const index_listIndices () const
 
NchooseK< T > & operator++ ()
 
bool done () const
 
std::size_t size () const
 
std::size_t k () const
 k More...
 
std::size_t n () const
 n More...
 

Protected Types

using index_type = std::size_t
 
using index_list = std::vector< index_type >
 

Protected Member Functions

bool nextlevel (index_type i)
 

Protected Attributes

const std::vector< T > _data
 
index_list indices
 
bool _done
 

Detailed Description

template<class T>
class ant::analysis::utils::NchooseK< T >

KofNvector class: Generate all combinations when drawing k elements out of a vector.

Elements are kept in the order they were in inside the data vector.

No duplicate combinations.

No duplicate elements (drawing without putting back).

Member Typedef Documentation

◆ index_list

template<class T >
using ant::analysis::utils::NchooseK< T >::index_list = std::vector<index_type>
protected

◆ index_type

template<class T >
using ant::analysis::utils::NchooseK< T >::index_type = std::size_t
protected

◆ value_type

template<class T >
typedef T ant::analysis::utils::NchooseK< T >::value_type

Constructor & Destructor Documentation

◆ NchooseK()

template<class T >
ant::analysis::utils::NchooseK< T >::NchooseK ( const std::vector< T > &  data,
index_type  k 
)
inline

KofNvector.

Parameters
_dataThe std::vector to draw from
knumber of elemets to draw each time

Member Function Documentation

◆ at()

template<class T >
const T& ant::analysis::utils::NchooseK< T >::at ( const size_t  i) const
inline

Access the ith element of the currently drawn combination.

Todo:
make a move constructor
Parameters
i
Returns
A reference to the element
Note
read-only. If makes no sense ot modify elements in a combination.

◆ begin()

template<class T >
const_iterator ant::analysis::utils::NchooseK< T >::begin ( ) const
inline

◆ done()

template<class T >
bool ant::analysis::utils::NchooseK< T >::done ( ) const
inline

◆ end()

template<class T >
const_iterator ant::analysis::utils::NchooseK< T >::end ( ) const
inline

◆ Indices()

template<class T >
const index_list& ant::analysis::utils::NchooseK< T >::Indices ( ) const
inline

◆ k()

template<class T >
std::size_t ant::analysis::utils::NchooseK< T >::k ( ) const
inline

k

Returns
number of elements to choose

◆ n()

template<class T >
std::size_t ant::analysis::utils::NchooseK< T >::n ( ) const
inline

n

Returns
number of elements to choose from

◆ next()

template<class T >
bool ant::analysis::utils::NchooseK< T >::next ( )
inline

Generate the next combination.

Returns
false if no more combinations to do.

◆ nextlevel()

template<class T >
bool ant::analysis::utils::NchooseK< T >::nextlevel ( index_type  i)
inlineprotected

◆ operator++()

template<class T >
NchooseK<T>& ant::analysis::utils::NchooseK< T >::operator++ ( )
inline

◆ size()

template<class T >
std::size_t ant::analysis::utils::NchooseK< T >::size ( ) const
inline

Member Data Documentation

◆ _data

template<class T >
const std::vector<T> ant::analysis::utils::NchooseK< T >::_data
protected

◆ _done

template<class T >
bool ant::analysis::utils::NchooseK< T >::_done
protected

◆ indices

template<class T >
index_list ant::analysis::utils::NchooseK< T >::indices
protected

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