Commit 40d35192 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Added default sorter selector.

parent 7460350b
Loading
Loading
Loading
Loading
+27 −7
Original line number Diff line number Diff line
@@ -12,18 +12,38 @@

#pragma once

#include <utility>  // std::pair, std::forward

#include <TNL/Devices/Sequential.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
#include <TNL/Algorithms/Sorting/BitonicSort.h>
#include <TNL/Algorithms/Sorting/Quicksort.h>
#include <TNL/Algorithms/Sorting/DefaultSorter.h>

namespace TNL {
   namespace Algorithms {


template< typename Array,
          typename Sorter = typename Sorting::DefaultSorter< typename Array::DeviceType >::SorterType >
void sort( Array& array )
{
   Sorter::sort( array );
}

template< typename Array,
          typename Compare,
          typename Sorter = typename Sorting::DefaultSorter< typename Array::DeviceType >::SorterType >
void sort( Array& array, const Compare& compare )
{
   Sorter::sort( array, compare );
}

template< typename Device,
          typename Index,
          typename Fetch,
          typename Compare,
          typename Swap,
          typename Sorter = typename Sorting::DefaultInplaceSorter< Device >::SorterType >
void inplaceSort( const Index begin, const Index end, const Fetch& fetch, const Compare& compare, const Swap& swap )
{
   Sorter::inplaceSort( begin, end, fetch, compare, swap );
}

template <typename Array, typename Function>
bool isSorted( const Array& arr, const Function& cmp )
{
+54 −0
Original line number Diff line number Diff line
/***************************************************************************
                          DefaultSorter.h  -  description
                             -------------------
    begin                : Jul 14, 2021
    copyright            : (C) 2021 by Tomas Oberhuber et al.
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

// Implemented by: Tomas Oberhuber

#pragma once

#include <utility>  // std::pair, std::forward

#include <TNL/Devices/Sequential.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
#include <TNL/Algorithms/Sorting/BitonicSort.h>
#include <TNL/Algorithms/Sorting/Quicksort.h>
#include <TNL/Algorithms/Sorting/STLSort.h>

namespace TNL {
   namespace Algorithms {
      namespace Sorting {

template< typename Device >
struct DefaultSorter;

template<>
struct DefaultSorter< Devices::Host >
{
   using SorterType = Algorithms::Sorting::STLSort;
};

template<>
struct DefaultSorter< Devices::Cuda >
{
   using SorterType = Algorithms::Sorting::Quicksort;
};

template< typename Device >
struct DefaultInplaceSorter;

template<>
struct DefaultInplaceSorter< Devices::Cuda >
{
   using SorterType = Algorithms::Sorting::BitonicSort;
};

      } // namespace Sorting
   } // namespace Algorithms
} // namespace TNL