Home || Visual Search || Applications || Architecture || 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     ILOG_VAR(Impala.Core.Column.ApplyOrder);
00022     if(data->Size() == 0)
00023     {
00024         // probably an InvalidColumn : no error
00025         return;
00026     }
00027     if(data->Size() < order->Size())
00028     {
00029         ILOG_ERROR("Column to reorder shorter than the presented order");
00030         return;
00031     }
00032     Util::ApplyOrder(data->GetData(), order->GetData(), order->Size());
00033 }
00034 
00035 
00037 template <>
00038 void
00039 ApplyOrder(Vector::VectorSet<Array::Array2dScalarReal64>* data, ColumnTem<int>* orderCol)
00040 {
00041     typedef Vector::VectorTem<Array::Array2dScalarReal64::StorType> Type;
00042 
00043     int length = orderCol->Size();
00044     // order is copied to keep callers code simpler
00045     int* order = new int[length];
00046     memcpy(order, orderCol->GetData(), length*sizeof(int));
00047     
00048     int i;
00049     for(i=0 ; i<length ; ++i)
00050     {
00051         if(order[i] != i)
00052         {
00053             // keep swapping until an element is put at the correct position (this will happen!)
00054             int indexFrom = i;
00055             int indexTo = order[i];
00056             order[i] = i;
00057             Type value = data->Get(indexFrom);
00058             while(indexFrom != indexTo)
00059             {
00060                 Type temp = data->Get(indexTo);
00061                 data->Set(indexTo, value);
00062                 value = temp;
00063                 indexFrom = indexTo;
00064                 indexTo = order[indexFrom];
00065                 order[indexFrom] = indexFrom;
00066             }
00067         }
00068     }
00069 }
00070 
00071 } // namespace Column
00072 } // namespace Core
00073 } // namespace Impala
00074 
00075 #endif

Generated on Thu Jan 13 09:04:22 2011 for ImpalaSrc by  doxygen 1.5.1