Container of Numbers. More...

#include <rnumcontainer.h>

Inheritance diagram for RNumContainer< I, bOrder >:
[legend]

Public Member Functions

 RNumContainer (size_t max)
 
 RNumContainer (const RNumContainer &vector)
 
void Verify (size_t max)
 
void Init (size_t nb, I val)
 
int Compare (const RNumContainer< I, bOrder > &) const
 
size_t GetIndex (I nb, bool &find) const
 
bool IsSame (const RNumContainer &vi) const
 
bool IsIn (I value) const
 
size_t Insert (I ins)
 
void InsertAt (I ins, size_t pos, bool replace=false)
 
void Delete (I del)
 
void DeleteAt (size_t pos, bool shift=true)
 
void Clear (void)
 
void ReOrder (void)
 
void Randomize (RRandom *rand, size_t nb=0)
 
template<bool bOrder1>
RNumContaineroperator= (const RNumContainer< I, bOrder1 > &src)
 
template<bool bOrder1>
RNumContainer< I, bOrder > & Add (const RNumContainer< I, bOrder1 > &src)
 
operator[] (size_t i) const
 
I & operator[] (size_t i)
 
const I * GetList (void) const
 
size_t GetNb (void) const
 
template<bool bOrder1, bool bOrder2>
void Inter (const RNumContainer< I, bOrder1 > &src1, const RNumContainer< I, bOrder2 > &src2)
 
template<bool bOrder1, bool bOrder2>
void Union (const RNumContainer< I, bOrder1 > &src1, const RNumContainer< I, bOrder2 > &src2)
 
 ~RNumContainer (void)
 

Protected Attributes

size_t NbInt
 
size_t MaxInt
 
I * List
 

Static Private Member Functions

static int ReOrderFunction (const void *num1, const void *num2)
 

Detailed Description

template<class I, bool bOrder = true>
class R::RNumContainer< I, bOrder >

Container of Numbers.

The RNumContainer class provides a representation of a container of numbers.

Template Parameters
IType (int, double, etc.).
bOrderIs the container ordered?
Warning
Some methods applied on an ordered container can disorder the container.

Constructor & Destructor Documentation

RNumContainer ( size_t  max)

Construct the list of values.

Parameters
maxMaximum number of values.
RNumContainer ( const RNumContainer< I, bOrder > &  vector)

Copy constructor.

Parameters
vectorVector to copy.
~RNumContainer ( void  )

Destructor of the list.

Member Function Documentation

void Verify ( size_t  max)

Verify if the container can hold a certain number of elements. If not, the container is extended.

Parameters
maxNumber of elements that must be contained.
void Init ( size_t  nb,
val 
)

Initialize the container with a given values.

Parameters
nbNumber of elements.
valValue used to initialize.
int Compare ( const RNumContainer< I, bOrder > &  ) const

Compare method that can be used to construct an unordered container of containers.

size_t GetIndex ( nb,
bool &  find 
) const

This function returns the index of an element represented by tag, and it is used when the elements are to be ordered.

Parameters
nbNumber to find.
findIf the element represented by tag exist, find is set to true.
Returns
Returns the index of the element if it exists or the index where is has to inserted.
bool IsSame ( const RNumContainer< I, bOrder > &  vi) const

Test if two lists have exactly the same values.

Parameters
viThe list used for the comparison.
Returns
True if the lists are the same.
bool IsIn ( value) const

Verify if a value is in the list.

Parameters
valueThe value to test.
Returns
True if the value is in the list, false else.
size_t Insert ( ins)

Insert an value in the list. If the vector is ordered, the method verifies that the value is not in before insertion. If the vector is unordered, the value is simply inserted at the end.

Parameters
insThe value to insert.
Returns
the position of the value in the list.
void InsertAt ( ins,
size_t  pos,
bool  replace = false 
)

Insert a value in the list at a given position.

Parameters
insThe value to insert.
posThe position where to insert.
replaceSpecify if the value that was previously at the position should be replaced or shifted.
Warning
If applied on an ordered container, this method can disorder it.
void Delete ( del)

Delete a value in the list.

Parameters
delThe value to delete.
void DeleteAt ( size_t  pos,
bool  shift = true 
)

Delete an element at a given position.

Parameters
posPosition of the element to remove.
shiftMust the elements be shifted.
Warning
If applied on an ordered container, this method can disorder it.
void Clear ( void  )

Clear the list.

static int ReOrderFunction ( const void *  num1,
const void *  num2 
)
staticprivate

Static function needed to order a list.

void ReOrder ( void  )

Reorder the current list of values in ascending order.

void Randomize ( RRandom rand,
size_t  nb = 0 
)

Randomize the list.

Parameters
randRandom number generator to use.
nbNumber of first element to randomize. If null, all values are randomized.
Warning
If applied on an ordered container, this method can disorder it.
RNumContainer& operator= ( const RNumContainer< I, bOrder1 > &  src)

Assignment operator.

Template Parameters
bOrder1Is the list ordered?
Parameters
srcList used for the assignment.
RNumContainer<I,bOrder>& Add ( const RNumContainer< I, bOrder1 > &  src)

Insert all the values of a list in the current one. This function supposes that the list to insert don't contain any value already in the current list.

Template Parameters
bOrder1Is the list ordered?
Parameters
srcThe list to insert.
I operator[] ( size_t  i) const

Return the value at position i. The first value is at position 0.

Parameters
iIndex.
I& operator[] ( size_t  i)

Return the value at position i. The first value is at position 0.

Parameters
iIndex.
Warning
If applied on an ordered container, this method can disorder it.
const I* GetList ( void  ) const

Get the list of the values contained in the vector.

size_t GetNb ( void  ) const

Get the number of values in the list.

Returns
size_t
void Inter ( const RNumContainer< I, bOrder1 > &  src1,
const RNumContainer< I, bOrder2 > &  src2 
)

Compute the intersection of two lists. The list is emptied. before.

Template Parameters
bOrder1Is the first list ordered?
bOrder2Is the second list ordered?
Parameters
src1First list.
src2Second list.
void Union ( const RNumContainer< I, bOrder1 > &  src1,
const RNumContainer< I, bOrder2 > &  src2 
)

Compute the union of two lists. The list is emptied. before.

Template Parameters
bOrder1Is the first list ordered?
bOrder2Is the second list ordered?
Parameters
src1First list.
src2Second list.

Field Documentation

size_t NbInt
protected

Number of values in the list.

size_t MaxInt
protected

Maximal number of values in the list.

I* List
protected

The array representing the values.