LvArray
Classes | Namespaces | Functions | Variables
sortedArrayManipulationHelpers.hpp File Reference

Contains helper functions for the sortedArrayManipulation routines. Much of this was adapted from stl_heap.h and stl_algo.h of the gcc standard library See https://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/include/bits/. More...

#include "LvArrayConfig.hpp"
#include "Macros.hpp"
#include <utility>
Include dependency graph for sortedArrayManipulationHelpers.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  LvArray::sortedArrayManipulation::internal::DualIteratorAccessor< A, B >
 This class is the type returned by the DualIterator operator* and holds a reference to a value in both underlying arrays. More...
 
class  LvArray::sortedArrayManipulation::internal::DualIteratorAccessor< A, B >::Temporary
 A helper class that holds a copy of the values. More...
 
class  LvArray::sortedArrayManipulation::internal::DualIteratorComparator< A, B, Compare >
 This class is used to make a comparison method that takes in DualIteratorAccessor<A, B> from a comparison method that takes in objects of type A. More...
 
class  LvArray::sortedArrayManipulation::internal::DualIterator< RandomAccessIteratorA, RandomAccessIteratorB >
 This class acts as a single iterator while wrapping two iterators. More...
 

Namespaces

 LvArray
 The top level namespace.
 
 LvArray::sortedArrayManipulation
 Contains functions for operating on a contiguous sorted unique array of values.
 

Functions

template<class T >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE T && LvArray::sortedArrayManipulation::internal::createTemporary (T &a)
 Return a temporary object holding the value of a. More...
 
template<class A , class B >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIteratorAccessor< A, B >::Temporary LvArray::sortedArrayManipulation::internal::createTemporary (DualIteratorAccessor< A, B > &&it)
 Return a temporary object holding the values held in the DualIteratorAccessor. More...
 
template<class Iterator >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void LvArray::sortedArrayManipulation::internal::exchange (Iterator a, Iterator b)
 Exchange the values pointed at by the two iterators. More...
 
template<class BidirIt1 , class BidirIt2 >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void LvArray::sortedArrayManipulation::internal::moveBackward (BidirIt1 first, BidirIt1 last, BidirIt2 d_last)
 Move the elements in [first, last) to another range ending in d_last. The elements are moved in reverse order. More...
 
template<typename Iterator , typename Compare >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void LvArray::sortedArrayManipulation::internal::computeMedian (Iterator result, Iterator a, Iterator b, Iterator c, Compare &&comp)
 Compute the median of *a, *b and *c and place it in *result. More...
 
template<typename RandomAccessIterator , typename Compare >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE RandomAccessIterator LvArray::sortedArrayManipulation::internal::unguardedPartition (RandomAccessIterator first, RandomAccessIterator last, RandomAccessIterator pivot, Compare &&comp)
 Partition the range [first, last) with regards to *pivot. More...
 
template<typename RandomAccessIterator , typename Compare >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE RandomAccessIterator LvArray::sortedArrayManipulation::internal::unguardedPartitionPivot (RandomAccessIterator first, RandomAccessIterator last, Compare &&comp)
 Partition the range [first, last). More...
 
template<typename RandomAccessIterator , typename Compare >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void LvArray::sortedArrayManipulation::internal::unguardedLinearInsert (RandomAccessIterator last, Compare comp)
 
template<class RandomAccessIterator , class Compare >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void LvArray::sortedArrayManipulation::internal::insertionSort (RandomAccessIterator first, std::ptrdiff_t const n, Compare comp)
 sort the range [first, first + n) under comp using insertions sort. More...
 
template<typename RandomAccessIterator , typename Compare >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void LvArray::sortedArrayManipulation::internal::introsortLoop (RandomAccessIterator first, RandomAccessIterator last, Compare &&comp)
 Partially sort the range [first, last) under comp. More...
 

Variables

constexpr int LvArray::sortedArrayManipulation::internal::INTROSORT_THRESHOLD = 64
 The size above which we continue with the introsortLoop.
 

Detailed Description

Contains helper functions for the sortedArrayManipulation routines. Much of this was adapted from stl_heap.h and stl_algo.h of the gcc standard library See https://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/include/bits/.

Function Documentation

◆ computeMedian()

template<typename Iterator , typename Compare >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void LvArray::sortedArrayManipulation::internal::computeMedian ( Iterator  result,
Iterator  a,
Iterator  b,
Iterator  c,
Compare &&  comp 
)
inline

Compute the median of *a, *b and *c and place it in *result.

Template Parameters
Iteratoran iterator type.
Comparethe type of the comparison method.
Parameters
resultiterator to the place to store the result.
aiterator to the first value to compare
biterator to the first value to compare.
citerator to the first value to compare.
compthe comparison method to use.
Note
This method was adapted from the gcc standard libarary header stl_algo.h which can be found at https://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/include/bits/.

◆ createTemporary() [1/2]

template<class T >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE T&& LvArray::sortedArrayManipulation::internal::createTemporary ( T &  a)
inline

Return a temporary object holding the value of a.

Template Parameters
Tthe type of the value to create.
Parameters
athe value to move.
Returns
Return a temporary object holding the value of a.

◆ createTemporary() [2/2]

template<class A , class B >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIteratorAccessor< A, B >::Temporary LvArray::sortedArrayManipulation::internal::createTemporary ( DualIteratorAccessor< A, B > &&  it)
inline

Return a temporary object holding the values held in the DualIteratorAccessor.

Template Parameters
Athe type of the first value in the DualIteratorAccessor.
Bthe type of the second value in the DualIteratorAccessor.
Parameters
itthe DualIteratorAccessor to move from.
Returns
Return a temporary object holding the values held in the DualIteratorAccessor.

◆ exchange()

template<class Iterator >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void LvArray::sortedArrayManipulation::internal::exchange ( Iterator  a,
Iterator  b 
)
inline

Exchange the values pointed at by the two iterators.

Template Parameters
Iteratoran iterator type.
Parameters
athe first iterator.
bthe second iterator.

◆ insertionSort()

template<class RandomAccessIterator , class Compare >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void LvArray::sortedArrayManipulation::internal::insertionSort ( RandomAccessIterator  first,
std::ptrdiff_t const  n,
Compare  comp 
)
inline

sort the range [first, first + n) under comp using insertions sort.

Template Parameters
RandomAccessIteratora random access iterator type.
Comparethe type of the comparison method.
Parameters
firstiterator to the beginning of the range.
nthe size of the range.
compthe comparison method to use.
Note
This method was adapted from the gcc standard libarary header stl_algo.h which can be found at https://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/include/bits/.

◆ introsortLoop()

template<typename RandomAccessIterator , typename Compare >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void LvArray::sortedArrayManipulation::internal::introsortLoop ( RandomAccessIterator  first,
RandomAccessIterator  last,
Compare &&  comp 
)
inline

Partially sort the range [first, last) under comp.

Template Parameters
RandomAccessIteratora random access iterator type.
Comparethe type of the comparison method.
Parameters
firstiterator to the beginning of the range.
lastiterator to the end of the range.
compthe comparison method to use.
Note
This method was heavily modified to get rid of recursion. As a result it no-longer does a heap-sort when the recursion depth reaches a limit. On randomly generated datasets it performs as well or better than std::sort. However because it no longer does heap-sort there may be certain cases where std::sort performs better. If this becomes an issue try adding heap-sort back in.
This method was adapted from the gcc standard libarary header stl_algo.h which can be found at https://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/include/bits/.

◆ moveBackward()

template<class BidirIt1 , class BidirIt2 >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void LvArray::sortedArrayManipulation::internal::moveBackward ( BidirIt1  first,
BidirIt1  last,
BidirIt2  d_last 
)
inline

Move the elements in [first, last) to another range ending in d_last. The elements are moved in reverse order.

Template Parameters
BidirIt1a bidirectional iterator type.
BidirIt2a bidirectional iterator type.
Parameters
firstiterator to the beginning of the values to move.
lastiterator to the end of the values to move.
d_lastiterator to the end of the values to move to.
Note
This should be equivalent to std::move_backward and this implementation was gotten from https://en.cppreference.com/w/cpp/algorithm/move_backward.

◆ unguardedLinearInsert()

template<typename RandomAccessIterator , typename Compare >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void LvArray::sortedArrayManipulation::internal::unguardedLinearInsert ( RandomAccessIterator  last,
Compare  comp 
)
inline
Template Parameters
RandomAccessIteratora random access iterator type.
Comparethe type of the comparison method.
Parameters
lastiterator to the end of the range.
compthe comparison method to use.
Note
This method was adapted from the gcc standard libarary header stl_algo.h which can be found at https://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/include/bits/.

◆ unguardedPartition()

template<typename RandomAccessIterator , typename Compare >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE RandomAccessIterator LvArray::sortedArrayManipulation::internal::unguardedPartition ( RandomAccessIterator  first,
RandomAccessIterator  last,
RandomAccessIterator  pivot,
Compare &&  comp 
)
inline

Partition the range [first, last) with regards to *pivot.

Template Parameters
RandomAccessIteratora random access iterator type.
Comparethe type of the comparison method.
Parameters
firstiterator to the beginning of the range to partition.
lastiterator to the end of the range to partition.
pivotiterator to the value to use as a pivot.
compthe comparison method to use.
Returns
An iterator to pivot.
Note
This method was adapted from the gcc standard libarary header stl_algo.h which can be found at https://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/include/bits/.

◆ unguardedPartitionPivot()

template<typename RandomAccessIterator , typename Compare >
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE RandomAccessIterator LvArray::sortedArrayManipulation::internal::unguardedPartitionPivot ( RandomAccessIterator  first,
RandomAccessIterator  last,
Compare &&  comp 
)
inline

Partition the range [first, last).

Template Parameters
RandomAccessIteratora random access iterator type.
Comparethe type of the comparison method.
Parameters
firstiterator to the beginning of the range to partition.
lastiterator to the end of the range to partition.
compthe comparison method to use.
Returns
An iterator to pivot.
Note
This method was adapted from the gcc standard libarary header stl_algo.h which can be found at https://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/include/bits/.