Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

ApplyOrder.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Column_ApplyOrder_h
00002 #define Impala_Core_Column_ApplyOrder_h
00003 
00004 #include "Util/ApplyOrder.h"
00005 #include "Core/Vector/VectorSet.h"
00006 
00007 namespace Impala
00008 {
00009 namespace Core
00010 {
00011 namespace Column
00012 {
00013 
00014 
00017 template <class C>
00018 void
00019 ApplyOrder(C* data, ColumnTem<int>* order)
00020 {
00021     if(data->Size() == 0)
00022     {
00023         // probably an InvalidColumn : no error
00024         return;
00025     }
00026     if(data->Size() < order->Size())
00027     {
00028         std::cout << "[Column::ApplyOrder] column to reorder shorter than the presented order" << std::endl;
00029         return;
00030     }
00031     Util::ApplyOrder(data->GetData(), order->GetData(), order->Size());
00032 }
00033 
00034 
00036 template <>
00037 void
00038 ApplyOrder(Vector::VectorSet<Array::Array2dScalarReal64>* data, ColumnTem<int>* orderCol)
00039 {
00040     typedef Vector::VectorTem<Array::Array2dScalarReal64::StorType> Type;
00041 
00042     int length = orderCol->Size();
00043     // order is copied to keep callers code simpler
00044     int* order = new int[length];
00045     memcpy(order, orderCol->GetData(), length*sizeof(int));
00046     
00047     int i;
00048     for(i=0 ; i<length ; ++i)
00049     {
00050         if(order[i] != i)
00051         {
00052             // keep swapping until an element is put at the correct position (this will happen!)
00053             int indexFrom = i;
00054             int indexTo = order[i];
00055             order[i] = i;
00056             Type value = data->Get(indexFrom);
00057             while(indexFrom != indexTo)
00058             {
00059                 Type temp = data->Get(indexTo);
00060                 data->Set(indexTo, value);
00061                 value = temp;
00062                 indexFrom = indexTo;
00063                 indexTo = order[indexFrom];
00064                 order[indexFrom] = indexFrom;
00065             }
00066         }
00067     }
00068 }
00069 
00070 } // namespace Column
00071 } // namespace Core
00072 } // namespace Impala
00073 
00074 #endif

Generated on Fri Mar 19 09:31:03 2010 for ImpalaSrc by  doxygen 1.5.1