Templated one dimensional Array. More...
#include <STK_HeapSort.h>
Inherits IArray1DBase< TYPE, TYPE, Array1D< TYPE > >.
Inherited by STK::Variable< TYPE >.
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) |
| Array1D & | operator= (const TYPE &v) |
| template<class LEAF > | |
| Array1D & | operator= (const ITContainer1D< TYPE, LEAF > &T) |
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.
| 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.
| 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.
| STK::STK::Array1D< TYPE >::Array1D | ( | const Range & | I = Range() |
) | [inline] |
Default constructor : beg_ =1 and end_ =0.
| I | range of the container |
Definition at line 66 of file STK_HeapSort.h.
| STK::STK::Array1D< TYPE >::Array1D | ( | const Range & | I, | |
| const TYPE & | v | |||
| ) | [inline] |
Misc constructor with beg and end, initialization with a constant.
| I | range of the container | |
| v | initial value of the container |
Definition at line 74 of file STK_HeapSort.h.
| STK::STK::Array1D< TYPE >::Array1D | ( | const Array1D< TYPE > & | T, | |
| bool | ref = false | |||
| ) | [inline] |
Copy constructor
| T | the container to copy | |
| ref | true if T is wrapped |
Definition at line 85 of file STK_HeapSort.h.
| STK::STK::Array1D< TYPE >::Array1D | ( | const Array1D< TYPE > & | T, | |
| const Range & | I | |||
| ) | [inline] |
constructor by reference, ref_=1.
| T | the container to wrap | |
| I | range of the data to wrap |
Definition at line 100 of file STK_HeapSort.h.
| STK::STK::Array1D< TYPE >::Array1D | ( | TYPE * | q, | |
| const Range & | I, | |||
| const Integer & | index = 0 | |||
| ) | [inline] |
Wrapper constructor : the container is a reference.
| 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.
| STK::STK::Array1D< TYPE >::Array1D | ( | const _IArrayBaseType & | T, | |
| const Range & | I, | |||
| const Integer & | index | |||
| ) | [inline] |
constructor by reference, ref_=1.
| 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.
| 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.
| TYPE& STK::STK::Array1D< TYPE >::getElt | ( | const Integer & | pos | ) | [inline] |
access to one element.
| 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().
| const TYPE& STK::STK::Array1D< TYPE >::getElt | ( | const Integer & | pos | ) | const [inline] |
access to one element const.
| pos | index of the const element |
Reimplemented from STK::STK::ITContainer1D< TYPE, Array1D< TYPE > >.
Definition at line 137 of file STK_HeapSort.h.
| Array1D STK::STK::Array1D< TYPE >::getElt | ( | const Range & | J | ) | const [inline] |
access to many elements.
| 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];
| 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.
| 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.
| 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.
| I | range of the container |
Definition at line 182 of file STK_HeapSort.h.
| void STK::STK::Array1D< TYPE >::pushBackElts | ( | const Integer & | n = 1 |
) | [inline] |
Add n Elts to the container.
| 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.
| void STK::STK::Array1D< TYPE >::insertElts | ( | Integer | pos, | |
| Integer | n = 1 | |||
| ) | [inline] |
Insert n elts at the position pos of the container.
| 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
| void STK::STK::Array1D< TYPE >::popBackElts | ( | const Integer & | n = 1 |
) | [inline] |
Delete last elts of the container.
| 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.
| void STK::STK::Array1D< TYPE >::eraseElts | ( | Integer | pos, | |
| Integer | n = 1 | |||
| ) | [inline] |
Delete n elements at the pos index to the container.
| 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();
| 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.
| T | the container to copy |
Reimplemented from STK::STK::ITContainer1D< TYPE, Array1D< TYPE > >.
Definition at line 351 of file STK_HeapSort.h.
| Array1D& STK::STK::Array1D< TYPE >::operator= | ( | const TYPE & | v | ) | [inline] |
operator= : set the container to a constant value.
| 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.
| 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.
| T | the container to copy |
Definition at line 387 of file STK_HeapSort.h.
1.6.3