STK::STK::Array1D< TYPE > Class Template Reference
[Subproject STKernel::TContainer]

Templated one dimensional Array. More...

#include <STK_HeapSort.h>

Inherits IArray1DBase< TYPE, TYPE, Array1D< TYPE > >.

Inherited by STK::Variable< TYPE >.

List of all members.

Public Types

typedef IArrayBase< TYPE * > _IArrayBaseType
typedef IArray1DBase< TYPE,
TYPE, Array1D< TYPE > > 
_IArray1DType

Public Member Functions

 Array1D (const Range &I=Range())
 Array1D (const Range &I, const TYPE &v)
 Array1D (const Array1D &T, bool ref=false)
 Array1D (const Array1D &T, const Range &I)
 Array1D (TYPE *q, const Range &I, const Integer &index=0)
 Array1D (const _IArrayBaseType &T, const Range &I, const Integer &index)
virtual ~Array1D ()
TYPE & getElt (const Integer &pos)
const TYPE & getElt (const Integer &pos) const
Array1D getElt (const Range &J) const
void clear ()
void freeMem ()
void initialize (const Range &I)
void pushBackElts (const Integer &n=1)
void insertElts (Integer pos, Integer n=1)
void popBackElts (const Integer &n=1)
void eraseElts (Integer pos, Integer n=1)
Array1D< TYPE > & operator= (const Array1D< TYPE > &T)
Array1Doperator= (const TYPE &v)
template<class LEAF >
Array1Doperator= (const ITContainer1D< TYPE, LEAF > &T)

Detailed Description

template<class TYPE>
class STK::STK::Array1D< TYPE >

An Array1D is a templated non-oriented container implementing the interface base class IArray1DBase. It contains objects of the type TYPE.

Definition at line 54 of file STK_HeapSort.h.


Member Typedef Documentation

template<class TYPE>
typedef IArrayBase<TYPE*> STK::STK::Array1D< TYPE >::_IArrayBaseType

Type for the Base reference Class.

Reimplemented from STK::IArray1DBase< TYPE, TYPE, Array1D< TYPE > >.

Definition at line 58 of file STK_HeapSort.h.

template<class TYPE>
typedef IArray1DBase<TYPE, TYPE, Array1D<TYPE> > STK::STK::Array1D< TYPE >::_IArray1DType

Type for the IArray1DBase Class.

Definition at line 61 of file STK_HeapSort.h.


Constructor & Destructor Documentation

template<class TYPE>
STK::STK::Array1D< TYPE >::Array1D ( const Range I = Range()  )  [inline]

Default constructor : beg_ =1 and end_ =0.

Parameters:
I range of the container

Definition at line 66 of file STK_HeapSort.h.

00070 {

template<class TYPE>
STK::STK::Array1D< TYPE >::Array1D ( const Range I,
const TYPE &  v 
) [inline]

Misc constructor with beg and end, initialization with a constant.

Parameters:
I range of the container
v initial value of the container

Definition at line 74 of file STK_HeapSort.h.

00080   {

template<class TYPE>
STK::STK::Array1D< TYPE >::Array1D ( const Array1D< TYPE > &  T,
bool  ref = false 
) [inline]

Copy constructor

Parameters:
T the container to copy
ref true if T is wrapped

Definition at line 85 of file STK_HeapSort.h.

00086     {
00087       // j+1 is greatest child
00088       if ( j < nb_elt && T[shift0 + j] < T[shift1 + j] ) j++;
00089       // we have find a child gt value
00090       if (value >= T[shift0 + j]) break;
00091       // else shift the inner value
00092       T[shift0 + i] = T[shift0 + j];
00093       // go down in the tree
00094       i = j;

template<class TYPE>
STK::STK::Array1D< TYPE >::Array1D ( const Array1D< TYPE > &  T,
const Range I 
) [inline]

constructor by reference, ref_=1.

Parameters:
T the container to wrap
I range of the data to wrap

Definition at line 100 of file STK_HeapSort.h.

00105   { // the value to sort

template<class TYPE>
STK::STK::Array1D< TYPE >::Array1D ( TYPE *  q,
const Range I,
const Integer index = 0 
) [inline]

Wrapper constructor : the container is a reference.

Parameters:
q pointer on data
I range of the data
index index (row or column) of the data

Definition at line 109 of file STK_HeapSort.h.

00109                                : we end the job
00110     if (--last == 1)
00111     { T[shift1] = value;

template<class TYPE>
STK::STK::Array1D< TYPE >::Array1D ( const _IArrayBaseType T,
const Range I,
const Integer index 
) [inline]

constructor by reference, ref_=1.

Parameters:
T the container to wrap
I the range of the data to wrap
index the index of the columnto wrap

Definition at line 118 of file STK_HeapSort.h.

00142 {

template<class TYPE>
virtual STK::STK::Array1D< TYPE >::~Array1D (  )  [inline, virtual]

Virtual Dtor: allocated memory is liberated by IArrayBase base class.

Definition at line 126 of file STK_HeapSort.h.

00142 {


Member Function Documentation

template<class TYPE>
TYPE& STK::STK::Array1D< TYPE >::getElt ( const Integer pos  )  [inline]

access to one element.

Parameters:
pos index of the element

Reimplemented from STK::STK::ITContainer1D< TYPE, Array1D< TYPE > >.

Definition at line 131 of file STK_HeapSort.h.

Referenced by STK::operator>>(), and STK::Variable< String >::setNA().

00142 {

template<class TYPE>
const TYPE& STK::STK::Array1D< TYPE >::getElt ( const Integer pos  )  const [inline]

access to one element const.

Parameters:
pos index of the const element

Reimplemented from STK::STK::ITContainer1D< TYPE, Array1D< TYPE > >.

Definition at line 137 of file STK_HeapSort.h.

00142 {

template<class TYPE>
Array1D STK::STK::Array1D< TYPE >::getElt ( const Range J  )  const [inline]

access to many elements.

Parameters:
J the range of the elements

Reimplemented from STK::STK::ITContainer1D< TYPE, Array1D< TYPE > >.

Definition at line 143 of file STK_HeapSort.h.

00154   {
00155     // the value value to insert in the heap
00156     TYPE value = Tsort[shift0 + first];

template<class TYPE>
void STK::STK::Array1D< TYPE >::clear (  )  [inline]

Clear the object. Memory is liberated and the range of the Container is set to 0:-1.

Reimplemented from STK::STK::ITContainer1D< TYPE, Array1D< TYPE > >.

Reimplemented in STK::Variable< TYPE >, and STK::Variable< String >.

Definition at line 161 of file STK_HeapSort.h.

template<class TYPE>
void STK::STK::Array1D< TYPE >::freeMem (  )  [inline]

Method for memory desallocation. Memory is liberated and the range of the Container is set to begin:begin-1.

Definition at line 171 of file STK_HeapSort.h.

00179   { // the value to sort

template<class TYPE>
void STK::STK::Array1D< TYPE >::initialize ( const Range I  )  [inline]

function for memory allocation and initialization. This method will free all allocated memory owned by this container before initialization.

Parameters:
I range of the container

Definition at line 182 of file STK_HeapSort.h.

00183                                : we end the job
00184     if (--last == 1)
00185     { Tsort[shift1] = value;
00186       break;
00187     }
00188     // organize the heap
00189     Integer i=1, j=2;
00190     while (j <= last)
00191     { // j+1 is greatest child
00192       if ( j < last && Tsort[shift0 + j] < Tsort[shift1 + j] ) j++;

template<class TYPE>
void STK::STK::Array1D< TYPE >::pushBackElts ( const Integer n = 1  )  [inline]

Add n Elts to the container.

Parameters:
n number of elements to add

Reimplemented from STK::STK::ITContainer1D< TYPE, Array1D< TYPE > >.

Reimplemented in STK::Variable< TYPE >, STK::Variable< TYPE >, STK::Variable< String >, and STK::Variable< String >.

Definition at line 197 of file STK_HeapSort.h.

00217 {

template<class TYPE>
void STK::STK::Array1D< TYPE >::insertElts ( Integer  pos,
Integer  n = 1 
) [inline]

Insert n elts at the position pos of the container.

Parameters:
pos index where to insert elements
n number of elements to insert (default 1)

Reimplemented in STK::Variable< TYPE >, and STK::Variable< String >.

Definition at line 219 of file STK_HeapSort.h.

00225   { I[i] = i;}
00226 
00227   if (nb_elt < 2) return;
00228 
00229   // if the container is base one, shift0 = 0 and shift1 = 1
00230   Integer shift1 = T.first(), shift0 = T.first() - 1;
00231 
00232   // create heap
00233   for (first = nb_elt/2; first > 0; --first)
00234   {
00235     // the value value to insert in the heap
00236     TYPE value = T[I[shift0 + first]];
00237     // organize the heap
00238     Integer i=first, j=2*first;
00239     while (j <= nb_elt)
00240     {
00241       // j+1 is greatest child
00242       if ( j < nb_elt && T[I[shift0 + j]] < T[I[shift1 + j]] ) j++;
00243       // we have find a child lt value
00244       if (value >= T[I[shift0 + j]]) break;
00245       // else shift the inner values
00246       I[shift0 + i] = I[shift0 + j];
00247       // go down in the tree
00248       i = j;
00249       j*= 2;
00250     }
00251     // plug value in its final location
00252     I[shift0 + i] = shift0 + first;
00253   }
00254 #ifdef STK_HEAPSORT_DEBUG
00255   std::cout << "I=\n" << I <<"\n";
00256 #endif
00257   // sort T
00258   for (Integer last = nb_elt;;)
00259   {
00260     // the value to sort
00261     Integer ivalue = I[shift0 + last];
00262     TYPE value = T[ivalue];
00263     // Put the top of the heap at the end
00264     //T[shift0 + last] = T[shift1];
00265     I[shift0 + last] = I[shift1];
00266     // decrease last.  last==1 : we end the job
00267     if (--last == 1)
00268     { //T[shift1] = value;
00269       I[shift1] = ivalue;
00270       break;
00271     }
00272     // organize the heap
00273     Integer i=1, j=2;
00274     while (j <= last)
00275     { // j+1 is greatest child
00276       if ( j < last && T[I[shift0 + j]] < T[I[shift1 + j]] ) j++;
00277       // we have find a child gt value

template<class TYPE>
void STK::STK::Array1D< TYPE >::popBackElts ( const Integer n = 1  )  [inline]

Delete last elts of the container.

Parameters:
n number of elts to delete

Reimplemented from STK::STK::ITContainer1D< TYPE, Array1D< TYPE > >.

Reimplemented in STK::Variable< TYPE >, STK::Variable< TYPE >, STK::Variable< String >, and STK::Variable< String >.

Definition at line 282 of file STK_HeapSort.h.

00305 {

template<class TYPE>
void STK::STK::Array1D< TYPE >::eraseElts ( Integer  pos,
Integer  n = 1 
) [inline]

Delete n elements at the pos index to the container.

Parameters:
pos index where to delete elements
n number of elements to delete (default 1)

Reimplemented in STK::Variable< TYPE >, and STK::Variable< String >.

Definition at line 310 of file STK_HeapSort.h.

00315   {
00316     A[i] = T[I[i]];
00317   }
00318   T.asLeaf() = A.asLeaf();
00319 }
00320 
00326 template < class TYPE, class TContainerHo, class TContainerVe, class TContainer2D>
00327 void applySort( ITContainer2D< TYPE, TContainerHo, TContainerVe, TContainer2D>& T
00328               , const Array1D<Integer>& I
00329               )
00330 {
00331 #ifdef STK_DEBUG
00332   if (I.range() != T.rangeVe())
00333   { throw std::runtime_error("In applySort(T, I) "
00334                         "incompatible lengths\n");
00335   }
00336 #endif
00337   TContainer2D A(T.rangeVe(), T.rangeHo());
00338   const Integer first = I.first(), last = I.last();
00339   for (Integer i=first; i<= last; i++)
00340   {
00341     A(i) = T(I[i]);
00342   }
00343   T.asLeaf() = A.asLeaf();

template<class TYPE>
Array1D<TYPE>& STK::STK::Array1D< TYPE >::operator= ( const Array1D< TYPE > &  T  )  [inline]

operator = : overwrite the Array1D with t. We resize the object if this and T does not have the same size but if they have the same size, we don't modify the range of the object.

Parameters:
T the container to copy

Reimplemented from STK::STK::ITContainer1D< TYPE, Array1D< TYPE > >.

Definition at line 351 of file STK_HeapSort.h.

template<class TYPE>
Array1D& STK::STK::Array1D< TYPE >::operator= ( const TYPE &  v  )  [inline]

operator= : set the container to a constant value.

Parameters:
v the value to set

Reimplemented in STK::Variable< TYPE >, STK::Variable< TYPE >, STK::Variable< String >, and STK::Variable< String >.

Definition at line 372 of file STK_HeapSort.h.

template<class TYPE>
template<class LEAF >
Array1D& STK::STK::Array1D< TYPE >::operator= ( const ITContainer1D< TYPE, LEAF > &  T  )  [inline]

operator = : overwrite the ArrayHo with the ITContainer1D T. We resize this if this and T don't have the same size but if they have the same size, we don't modify the range of the object.

Parameters:
T the container to copy

Definition at line 387 of file STK_HeapSort.h.


The documentation for this class was generated from the following file:
Generated on Fri Sep 24 15:13:12 2010 for STK++ by  doxygen 1.6.3