17 #include "LvArrayConfig.hpp" 24 namespace sortedArrayManipulation
39 template<
class A,
class B >
64 m_a( std::move( src.
m_a )),
74 m_a( std::move( src.
m_a )),
144 m_a = std::move( src.m_a );
145 m_b = std::move( src.m_b );
157 m_a = std::move( src.m_a );
158 m_b = std::move( src.m_b );
177 template<
typename A,
typename B,
typename Compare >
198 {
return m_compare( lhs.
m_a, rhs.
m_a ); }
209 {
return m_compare( lhs.
m_a, rhs.
m_a ); }
222 template<
class RandomAccessIteratorA,
class RandomAccessIteratorB >
227 using A =
typename std::remove_reference< decltype( *std::declval< RandomAccessIteratorA >() ) >::type;
230 using B =
typename std::remove_reference< decltype( *std::declval< RandomAccessIteratorB >() ) >::type;
286 {
return DualIterator( m_itA + offset, m_itB + offset ); }
321 std::ptrdiff_t
const distance = m_itA - rhs.
m_itA;
333 {
return *
this + (-offset); }
342 {
return *
this += (-offset); }
363 {
return m_itA != rhs.
m_itA; }
372 {
return m_itA < rhs.
m_itA; }
389 template<
class Compare >
412 return std::move( a );
423 template<
class A,
class B >
434 template<
class Iterator >
438 *a = std::move( *b );
439 *b = std::move( temp );
454 template<
class B
idirIt1,
class B
idirIt2 >
457 while( first != last )
459 *(--d_last) = std::move( *(--last));
477 template<
typename Iterator,
typename Compare >
486 else if( comp( *a, *c ))
495 else if( comp( *a, *c ))
499 else if( comp( *b, *c ))
522 template<
typename RandomAccessIterator,
typename Compare >
524 RandomAccessIterator pivot, Compare && comp )
528 while( comp( *first, *pivot ))
534 while( comp( *pivot, *last ))
561 template<
typename RandomAccessIterator,
typename Compare >
564 RandomAccessIterator mid = first + (last - first) / 2;
579 template<
typename RandomAccessIterator,
typename Compare >
583 RandomAccessIterator next = last - 1;
584 while( comp( val, *next ))
586 *last = std::move( *next );
590 *last = std::move( val );
605 template<
class RandomAccessIterator,
class Compare >
608 for( std::ptrdiff_t i = 1; i < n; ++i )
610 if( comp( *(first + i), *first ))
614 *first = std::move( val );
640 template<
typename RandomAccessIterator,
typename Compare >
643 constexpr
int MAX_RANGES = 31;
644 RandomAccessIterator ranges[MAX_RANGES + 1];
649 while( nRanges != 0 )
651 RandomAccessIterator
const m_first = ranges[nRanges - 1];
656 ranges[nRanges + 1] = ranges[nRanges];
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE bool operator<(DualIterator const &rhs) const
Return true if this less than rhs.
Definition: sortedArrayManipulationHelpers.hpp:371
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE T && createTemporary(T &a)
Return a temporary object holding the value of a.
Definition: sortedArrayManipulationHelpers.hpp:410
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIterator operator-(std::ptrdiff_t const offset) const
Return a new DualIterator where both of the underlying iterators have been decrement by offset...
Definition: sortedArrayManipulationHelpers.hpp:332
#define LVARRAY_ASSERT(EXP)
Assert EXP is true with no message.
Definition: Macros.hpp:184
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.
Definition: sortedArrayManipulationHelpers.hpp:178
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE bool operator!=(DualIterator const &rhs) const
Return true if rhs does not point to the same values.
Definition: sortedArrayManipulationHelpers.hpp:362
B & m_b
A reference to the second value.
Definition: sortedArrayManipulationHelpers.hpp:166
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIterator & operator-=(std::ptrdiff_t const offset)
Decrement the underlying iterators by offset and return a reference to *this.
Definition: sortedArrayManipulationHelpers.hpp:341
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIteratorComparator< A, B, Compare > createComparator(Compare &&comp) const
Return a new Comparator which will compare two DualIteratorAccessors using the given comparison...
Definition: sortedArrayManipulationHelpers.hpp:390
RandomAccessIteratorA m_itA
The first iterator.
Definition: sortedArrayManipulationHelpers.hpp:395
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIteratorAccessor & operator=(Temporary &&src)
Move assignment operator that moves the values of src into the values of this.
Definition: sortedArrayManipulationHelpers.hpp:155
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void unguardedLinearInsert(RandomAccessIterator last, Compare comp)
Definition: sortedArrayManipulationHelpers.hpp:580
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE bool operator()(DualIteratorAccessor< A, B > const &lhs, DualIteratorAccessor< A, B > const &rhs) const
Compare lhs with rhs using their first values.
Definition: sortedArrayManipulationHelpers.hpp:196
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIterator operator+(std::ptrdiff_t const offset) const
Return a new DualIterator where both of the underlying iterators have been incremented by offset...
Definition: sortedArrayManipulationHelpers.hpp:285
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE std::ptrdiff_t operator-(DualIterator const &rhs) const
Return the distance between *this and rhs.
Definition: sortedArrayManipulationHelpers.hpp:319
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE Temporary(DualIteratorAccessor &&src)
Move the values pointed at by src into a temporary location.
Definition: sortedArrayManipulationHelpers.hpp:73
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void insertionSort(RandomAccessIterator first, std::ptrdiff_t const n, Compare comp)
sort the range [first, first + n) under comp using insertions sort.
Definition: sortedArrayManipulationHelpers.hpp:606
B m_b
A copy of type B.
Definition: sortedArrayManipulationHelpers.hpp:100
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIterator & operator--()
Decrement the underlying iterators by 1 and return a reference to *this.
Definition: sortedArrayManipulationHelpers.hpp:349
Temporary & operator=(Temporary const &)=delete
Deleted copy assignment operator.
Compare m_compare
The comparator that compares objects of type A.
Definition: sortedArrayManipulationHelpers.hpp:213
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIteratorAccessor & operator=(DualIteratorAccessor &&src)
Move assignment operator that moves the values of src into the values of this.
Definition: sortedArrayManipulationHelpers.hpp:142
Temporary()=delete
Deleted default constructor.
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIteratorAccessor(A &a, B &b)
Constructor to wrap the two given values.
Definition: sortedArrayManipulationHelpers.hpp:114
constexpr int INTROSORT_THRESHOLD
The size above which we continue with the introsortLoop.
Definition: sortedArrayManipulationHelpers.hpp:30
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIterator & operator++()
Increment the underlying iterators by 1 and return a reference to *this.
Definition: sortedArrayManipulationHelpers.hpp:306
The top level namespace.
Definition: Array.hpp:24
This class is the type returned by the DualIterator operator* and holds a reference to a value in bot...
Definition: sortedArrayManipulationHelpers.hpp:40
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIteratorAccessor< A, B > operator*() const
Return a DualIteratorAccessor to the two values at which m_itA and m_itB point at.
Definition: sortedArrayManipulationHelpers.hpp:379
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIterator(RandomAccessIteratorA const itA, RandomAccessIteratorB const itB)
Constructor taking the two iterators to wrap.
Definition: sortedArrayManipulationHelpers.hpp:244
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void exchange(Iterator a, Iterator b)
Exchange the values pointed at by the two iterators.
Definition: sortedArrayManipulationHelpers.hpp:435
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIterator & operator+=(std::ptrdiff_t const offset)
Increment the underlying iterators by offset and return a reference to *this.
Definition: sortedArrayManipulationHelpers.hpp:294
A & m_a
A reference to the first value.
Definition: sortedArrayManipulationHelpers.hpp:163
Contains a bunch of macro definitions.
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE Temporary(Temporary &&src)
Move constructor, moves the values from src..
Definition: sortedArrayManipulationHelpers.hpp:63
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE RandomAccessIterator unguardedPartition(RandomAccessIterator first, RandomAccessIterator last, RandomAccessIterator pivot, Compare &&comp)
Partition the range [first, last) with regards to *pivot.
Definition: sortedArrayManipulationHelpers.hpp:523
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void introsortLoop(RandomAccessIterator first, RandomAccessIterator last, Compare &&comp)
Partially sort the range [first, last) under comp.
Definition: sortedArrayManipulationHelpers.hpp:641
DISABLE_HD_WARNING ~Temporary()=default
Default destructor, must be declared default so we can disable host-device warnings.
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void 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 rever...
Definition: sortedArrayManipulationHelpers.hpp:455
A helper class that holds a copy of the values.
Definition: sortedArrayManipulationHelpers.hpp:46
#define DISABLE_HD_WARNING
Disable host device warnings.
Definition: Macros.hpp:561
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE DualIteratorComparator(Compare comp)
Constructor that takes in a comparison method.
Definition: sortedArrayManipulationHelpers.hpp:185
This class acts as a single iterator while wrapping two iterators.
Definition: sortedArrayManipulationHelpers.hpp:223
typename std::remove_reference< decltype(*std::declval< RandomAccessIteratorB >()) >::type B
An alias for the type pointed to by RandomAccessIteratorB.
Definition: sortedArrayManipulationHelpers.hpp:230
DualIteratorAccessor()=delete
Delete the default constructor.
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE RandomAccessIterator unguardedPartitionPivot(RandomAccessIterator first, RandomAccessIterator last, Compare &&comp)
Partition the range [first, last).
Definition: sortedArrayManipulationHelpers.hpp:562
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE bool operator()(typename DualIteratorAccessor< A, B >::Temporary const &lhs, DualIteratorAccessor< A, B > const &rhs) const
Compare lhs with rhs using their first values.
Definition: sortedArrayManipulationHelpers.hpp:207
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void computeMedian(Iterator result, Iterator a, Iterator b, Iterator c, Compare &&comp)
Compute the median of *a, *b and *c and place it in *result.
Definition: sortedArrayManipulationHelpers.hpp:478
typename std::remove_reference< decltype(*std::declval< RandomAccessIteratorA >()) >::type A
An alias for the type pointed to by RandomAccessIteratorA.
Definition: sortedArrayManipulationHelpers.hpp:227
RandomAccessIteratorB m_itB
The second iterator.
Definition: sortedArrayManipulationHelpers.hpp:398
#define LVARRAY_ASSERT_EQ(lhs, rhs)
Assert that two values compare equal in debug builds.
Definition: Macros.hpp:485
A m_a
A copy of type A.
Definition: sortedArrayManipulationHelpers.hpp:97
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:549