Skip to content
Merged
4 changes: 4 additions & 0 deletions .github/workflows/cmake_eastl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
repository: electronicarts/EASTL
path: eastl
submodules: true
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.31.x'
- name: Configure CMake EASTL
working-directory: ${{github.workspace}}/eastl
run: cmake -B ${{github.workspace}}/eastl/build -DCMAKE_BUILD_TYPE=${{matrix.BUILD_TYPE}} -DCMAKE_CXX_STANDARD=${{matrix.cppstd}} -D CMAKE_C_COMPILER=${{matrix.compiler.c}} -D CMAKE_CXX_COMPILER=${{matrix.compiler.cpp}}
Expand Down
76 changes: 52 additions & 24 deletions includes/rah2/algo_sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ namespace RAH2_NS
typename Sentinel,
RAH2_STD::enable_if_t<
forward_iterator<ForwardIterator> && sentinel_for<Sentinel, ForwardIterator>>* = nullptr>
ForwardIterator operator()(ForwardIterator first, Sentinel last) const
constexpr ForwardIterator operator()(ForwardIterator first, Sentinel last) const
{
if (first == last)
{
return first;
}
ForwardIterator next = first;

while (++next != last)
++next;
while (next != last)
{
if (*next < *first)
return next;

first = next;
++first;
++next;
}
return next;
}
Expand All @@ -53,7 +54,7 @@ namespace RAH2_NS
typename Compare,
typename Proj = RAH2_NS::details::identity,
RAH2_STD::enable_if_t<RAH2_NS::sentinel_for<Sentinel, ForwardIterator>>* = nullptr>
ForwardIterator
constexpr ForwardIterator
operator()(ForwardIterator first, Sentinel last, Compare compare, Proj proj = {}) const
{
auto pred_proj =
Expand Down Expand Up @@ -83,7 +84,7 @@ namespace RAH2_NS
typename Compare,
typename Proj = RAH2_NS::details::identity,
RAH2_STD::enable_if_t<forward_range<ForwardRange>>* = nullptr>
auto operator()(ForwardRange&& r, Compare compare, Proj proj = {}) const
constexpr auto operator()(ForwardRange&& r, Compare compare, Proj proj = {}) const
{
return (*this)(
RAH2_NS::ranges::begin(r),
Expand All @@ -93,7 +94,7 @@ namespace RAH2_NS
}

template <typename ForwardRange>
auto operator()(ForwardRange&& r) const
constexpr auto operator()(ForwardRange&& r) const
{
return (*this)(RAH2_NS::ranges::begin(r), RAH2_NS::ranges::end(r));
}
Expand All @@ -111,7 +112,7 @@ namespace RAH2_NS
typename Comp = RAH2_NS::ranges::less, // RAH2_STD::indirect_strict_weak_order<RAH2_STD::projected<I, Proj>>
typename Proj = RAH2_NS::details::identity,
RAH2_STD::enable_if_t<forward_iterator<I> && sentinel_for<S, I>>* = nullptr>
constexpr bool operator()(I first, S last, Comp comp = {}, Proj proj = {}) const
constexpr bool operator()(I first, S last, Comp comp, Proj proj = {}) const
{
return RAH2_NS::ranges::is_sorted_until(
RAH2_STD::move(first),
Expand All @@ -126,14 +127,37 @@ namespace RAH2_NS
typename Comp = RAH2_NS::ranges::less, // RAH2_STD::indirect_strict_weak_order<RAH2_STD::projected<ranges::iterator_t<R>, Proj>>
typename Proj = RAH2_NS::details::identity,
RAH2_STD::enable_if_t<forward_range<R>>* = nullptr>
constexpr bool operator()(R&& r, Comp comp = {}, Proj proj = {}) const
constexpr bool operator()(R&& r, Comp comp, Proj proj = {}) const
{
return (*this)(
RAH2_NS::ranges::begin(r),
RAH2_NS::ranges::end(r),
RAH2_STD::move(comp),
RAH2_STD::move(proj));
}

template <
typename I, // RAH2_STD::forward_iterator
typename S, // RAH2_STD::sentinel_for<I>
typename Comp = RAH2_NS::ranges::less, // RAH2_STD::indirect_strict_weak_order<RAH2_STD::projected<I, Proj>>
typename Proj = RAH2_NS::details::identity,
RAH2_STD::enable_if_t<forward_iterator<I> && sentinel_for<S, I>>* = nullptr>
constexpr bool operator()(I first, S last) const
{
return RAH2_NS::ranges::is_sorted_until(
RAH2_STD::move(first), RAH2_STD::move(last))
== last;
}

template <
typename R, // ranges::forward_range
typename Comp = RAH2_NS::ranges::less, // RAH2_STD::indirect_strict_weak_order<RAH2_STD::projected<ranges::iterator_t<R>, Proj>>
typename Proj = RAH2_NS::details::identity,
RAH2_STD::enable_if_t<forward_range<R>>* = nullptr>
constexpr bool operator()(R&& r) const
{
return (*this)(RAH2_NS::ranges::begin(r), RAH2_NS::ranges::end(r));
}
};
} // namespace niebloids

Expand Down Expand Up @@ -1044,8 +1068,9 @@ namespace RAH2_NS
auto lasti = result;
while ((lasti - first) > 5)
{
auto&& midValue(RAH2_NS::ranges::median(
*first, *(first + (lasti - first) / 2), *(lasti - 1)));
auto&& midValue(
RAH2_NS::ranges::median(
*first, *(first + (lasti - first) / 2), *(lasti - 1)));
RandomAccessIterator const midPos(
RAH2_NS::ranges::get_partition(first, lasti, RAH2_STD::move(midValue)));

Expand Down Expand Up @@ -1088,8 +1113,9 @@ namespace RAH2_NS
auto lasti = result;
while ((lasti - first) > 5)
{
auto const midValue(RAH2_NS::ranges::median(
*first, *(first + (lasti - first) / 2), *(lasti - 1), pred_proj));
auto const midValue(
RAH2_NS::ranges::median(
*first, *(first + (lasti - first) / 2), *(lasti - 1), pred_proj));
RandomAccessIterator const midPos(
RAH2_NS::ranges::get_partition(first, lasti, midValue, pred_proj));

Expand Down Expand Up @@ -1136,11 +1162,12 @@ namespace RAH2_NS
{
while (((last - first) > details::kQuickSortLimit) && (kRecursionCount > 0))
{
RandomAccessIterator const position(RAH2_NS::ranges::get_partition(
first,
last,
RAH2_STD::forward<PivotValueType>(RAH2_NS::ranges::median(
*first, *(first + (last - first) / 2), *(last - 1)))));
RandomAccessIterator const position(
RAH2_NS::ranges::get_partition(
first,
last,
RAH2_STD::forward<PivotValueType>(RAH2_NS::ranges::median(
*first, *(first + (last - first) / 2), *(last - 1)))));

quick_sort_impl_helper<RandomAccessIterator, Sentinel, Size, PivotValueType>(
position, last, --kRecursionCount);
Expand All @@ -1157,12 +1184,13 @@ namespace RAH2_NS
{
while (((last - first) > details::kQuickSortLimit) && (kRecursionCount > 0))
{
RandomAccessIterator const position(RAH2_NS::ranges::get_partition(
first,
last,
RAH2_STD::forward<PivotValueType>(RAH2_NS::ranges::median(
*first, *(first + (last - first) / 2), *(last - 1), compare)),
compare));
RandomAccessIterator const position(
RAH2_NS::ranges::get_partition(
first,
last,
RAH2_STD::forward<PivotValueType>(RAH2_NS::ranges::median(
*first, *(first + (last - first) / 2), *(last - 1), compare)),
compare));

quick_sort_impl_helper<RandomAccessIterator, Sentinel, Size, Compare, PivotValueType>(
position, last, --kRecursionCount, compare);
Expand Down
Loading