stmm-games-doc  0.32.0
Public Member Functions | Static Public Member Functions | List of all members
stmg::IntSet Class Reference

Smallish set of integers. More...

Public Member Functions

 IntSet () noexcept
 Constructs empty integer set. More...
 
 IntSet (int32_t nValue) noexcept
 Constructs integer set with one value. More...
 
 IntSet (int32_t nFromValue, int32_t nToValue) noexcept
 Constructs integer set with ordered value range. More...
 
 IntSet (int32_t nFromValue, int32_t nToValue, int32_t nStep) noexcept
 Constructs integer set with ordered stepped value range. More...
 
 IntSet (const std::vector< int32_t > &aValues) noexcept
 Constructs integer set with array of unsorted values. More...
 
 IntSet (const std::vector< int32_t > &aValues, bool bIsSorted) noexcept
 Constructs integer set with array of values. More...
 
 IntSet (std::vector< int32_t > &&aValues) noexcept
 Constructs integer set with array of unsorted values. More...
 
 IntSet (std::vector< int32_t > &&aValues, bool bIsSorted) noexcept
 Constructs integer set with array of values. More...
 
 IntSet (const IntSet &oSource) noexcept
 
 IntSet (IntSet &&oSource) noexcept
 
IntSetoperator= (const IntSet &oSource) noexcept
 
IntSetoperator= (IntSet &&oSource) noexcept
 
int32_t size () const noexcept
 The size of the integer set. More...
 
int32_t getValueByIndex (int32_t nIdx) const noexcept
 The value at a given index. More...
 
int32_t getIndexOfValue (int32_t nValue) const noexcept
 The index of the value. More...
 
std::vector< int32_t > getAsVector () const noexcept
 Get as vector of ordered unique values. More...
 
void dump (int32_t nIndentSpaces, bool bHeader) const noexcept
 

Static Public Member Functions

static IntSet makeUnion (const IntSet &oSetL, const IntSet &oSetR) noexcept
 Union of two IntSet. More...
 
static IntSet makeIntersection (const IntSet &oSetL, const IntSet &oSetR) noexcept
 Intersection of two IntSet. More...
 
static IntSet makeDifference (const IntSet &oSet, const IntSet &oSetExcl) noexcept
 Difference of two IntSet. More...
 

Detailed Description

Smallish set of integers.

Constructor & Destructor Documentation

◆ IntSet() [1/10]

stmg::IntSet::IntSet ( )
inlinenoexcept

Constructs empty integer set.

◆ IntSet() [2/10]

stmg::IntSet::IntSet ( int32_t  nValue)
inlineexplicitnoexcept

Constructs integer set with one value.

Parameters
nValueThe value.

◆ IntSet() [3/10]

stmg::IntSet::IntSet ( int32_t  nFromValue,
int32_t  nToValue 
)
noexcept

Constructs integer set with ordered value range.

Value at index 0 is nFromValue, the last is nToValue. Parameter nFromValue can be > nToValue.

Parameters
nFromValueThe start value.
nToValueThe end value.

◆ IntSet() [4/10]

stmg::IntSet::IntSet ( int32_t  nFromValue,
int32_t  nToValue,
int32_t  nStep 
)
noexcept

Constructs integer set with ordered stepped value range.

Value at index 0 is nFromValue, value at index 1 is nFromValue + nStep provided it isn't past nToValue, etc.

Parameter nStep can only be 0 if nFromValue == nToValue.

Parameters
nFromValueThe start value.
nToValueThe end value.
nStepThe step between generated values. Can be < 0.

◆ IntSet() [5/10]

stmg::IntSet::IntSet ( const std::vector< int32_t > &  aValues)
explicitnoexcept

Constructs integer set with array of unsorted values.

If values are repeated they are ignored.

Parameters
aValuesThe values.

◆ IntSet() [6/10]

stmg::IntSet::IntSet ( const std::vector< int32_t > &  aValues,
bool  bIsSorted 
)
explicitnoexcept

Constructs integer set with array of values.

If values are repeated they are ignored.

Parameters
aValuesThe values.
bIsSortedWhether the values are already sorted.

◆ IntSet() [7/10]

stmg::IntSet::IntSet ( std::vector< int32_t > &&  aValues)
explicitnoexcept

Constructs integer set with array of unsorted values.

If values are repeated they are ignored.

Parameters
aValuesThe values.

◆ IntSet() [8/10]

stmg::IntSet::IntSet ( std::vector< int32_t > &&  aValues,
bool  bIsSorted 
)
explicitnoexcept

Constructs integer set with array of values.

If values are repeated they are ignored.

Parameters
aValuesThe values.
bIsSortedWhether the values are already sorted.

◆ IntSet() [9/10]

stmg::IntSet::IntSet ( const IntSet oSource)
inlinenoexcept

◆ IntSet() [10/10]

stmg::IntSet::IntSet ( IntSet &&  oSource)
inlinenoexcept

Member Function Documentation

◆ dump()

void stmg::IntSet::dump ( int32_t  nIndentSpaces,
bool  bHeader 
) const
noexcept

◆ getAsVector()

std::vector<int32_t> stmg::IntSet::getAsVector ( ) const
noexcept

Get as vector of ordered unique values.

Be aware that if size() is a big number, this function might terminate the program because of out of memory exception.

Returns
The new vector.

◆ getIndexOfValue()

int32_t stmg::IntSet::getIndexOfValue ( int32_t  nValue) const
noexcept

The index of the value.

Parameters
nValueThe value to look for.
Returns
The index (>= 0) or -1 if value not in the set.

◆ getValueByIndex()

int32_t stmg::IntSet::getValueByIndex ( int32_t  nIdx) const
noexcept

The value at a given index.

Parameters
nIdxThe index. Must be >= 0 and < size().
Returns
The value.

◆ makeDifference()

static IntSet stmg::IntSet::makeDifference ( const IntSet oSet,
const IntSet oSetExcl 
)
staticnoexcept

Difference of two IntSet.

Parameters
oSetThe main int set.
oSetExclThe set the values of which should not appear in the result.
Returns
The set.

◆ makeIntersection()

static IntSet stmg::IntSet::makeIntersection ( const IntSet oSetL,
const IntSet oSetR 
)
staticnoexcept

Intersection of two IntSet.

Parameters
oSetLThe first.
oSetRThe second.
Returns
The result.

◆ makeUnion()

static IntSet stmg::IntSet::makeUnion ( const IntSet oSetL,
const IntSet oSetR 
)
staticnoexcept

Union of two IntSet.

Parameters
oSetLThe first.
oSetRThe second.
Returns
The result.

◆ operator=() [1/2]

IntSet& stmg::IntSet::operator= ( const IntSet oSource)
inlinenoexcept

◆ operator=() [2/2]

IntSet& stmg::IntSet::operator= ( IntSet &&  oSource)
inlinenoexcept

◆ size()

int32_t stmg::IntSet::size ( ) const
noexcept

The size of the integer set.

Returns
The size.