26 #ifndef __TERRALIB_SAM_KDTREE_INTERNAL_PARTITION_H    27 #define __TERRALIB_SAM_KDTREE_INTERNAL_PARTITION_H    46       template<
class CONTAINER, 
class COMPFUNCTOR>
    47       void HoareFind(CONTAINER& 
A, 
const std::size_t& kthElement, 
const std::size_t& firstElement, 
const std::size_t& lastElement, 
const COMPFUNCTOR& compFunctor)
    49         std::size_t m = firstElement;
    50         std::size_t n = lastElement;
    53         if(kthElement < firstElement || kthElement > lastElement)
    62           typename CONTAINER::value_type r = A[kthElement];
    66             while(compFunctor(A[i], r))
    69             while(compFunctor(r, A[j]))
    74               typename CONTAINER::value_type w = A[i];
    86           else if(i <= kthElement) 
   105       template<
class CONTAINER, 
class LESSTHANX, 
class LESSTHANY>
   106       void kdsort(CONTAINER& dataSet, 
const std::size_t& first, 
const std::size_t& last, 
const char& level, 
const LESSTHANX& lessThanCompFunctorByX, 
const LESSTHANY& lessThanCompFunctorByY)
   108         const std::size_t kth = (last - first + 1) / 2;
   113           HoareFind(dataSet, first + kth, first, last, lessThanCompFunctorByX);
   116           if(first + kth > first)
   117             kdsort(dataSet, first, first + kth - 1, 
'y', lessThanCompFunctorByX, lessThanCompFunctorByY);
   119           if((first + kth) < last)
   120             kdsort(dataSet, first + kth + 1, last, 
'y', lessThanCompFunctorByX, lessThanCompFunctorByY);
   125           HoareFind(dataSet, first + kth, first, last, lessThanCompFunctorByY);
   128           if(first + kth > first)
   129             kdsort(dataSet, first, first + kth - 1, 
'x', lessThanCompFunctorByX, lessThanCompFunctorByY);
   131           if(first + kth < last)
   132             kdsort(dataSet, first + kth + 1, last, 
'x', lessThanCompFunctorByX, lessThanCompFunctorByY);
   140 #endif  // __TERRALIB_SAM_KDTREE_INTERNAL_PARTITION_H void HoareFind(CONTAINER &A, const std::size_t &kthElement, const std::size_t &firstElement, const std::size_t &lastElement, const COMPFUNCTOR &compFunctor)
This function partition the container in two parts: k-1 elements to the left (elements less than or e...
 
void kdsort(CONTAINER &dataSet, const std::size_t &first, const std::size_t &last, const char &level, const LESSTHANX &lessThanCompFunctorByX, const LESSTHANY &lessThanCompFunctorByY)
This partition the container like a bidimensional K-d Tree using Hoare algorithms.