44 template <
typename RandomIt,
typename Swapper,
typename Compare>
45 inline RandomIt
partition(RandomIt first, RandomIt last, Swapper swapper, Compare comp)
58 for (
auto j = lo; j != hi; ++j)
68 template <
typename RandomIt>
74 template <
typename RandomIt>
80 template <
typename RandomIt>
86 template <
typename RandomIt,
typename Swapper,
typename Compare>
87 inline void siftDown(RandomIt first, RandomIt start, RandomIt end, Swapper swapper, Compare comp)
94 if (comp(*
swap, *child))
97 if (child < end && comp(*
swap, *child))
106 template <
typename RandomIt,
typename Swapper,
typename Compare>
107 inline void heapify(RandomIt first, RandomIt last, Swapper swapper, Compare comp)
111 while (start > first)
114 siftDown(first, start, end, swapper, comp);
118 template <
typename RandomIt,
typename Swapper,
typename Compare>
119 inline void heapsort(RandomIt first, RandomIt last, Swapper swapper, Compare comp)
121 heapify(first, last, swapper, comp);
127 siftDown(first, first, end, swapper, comp);
132 template <
typename RandomIt,
typename Swapper,
typename Compare>
133 inline void introsort(RandomIt first, RandomIt last, Swapper swapper, Compare comp, uint32_t depth)
138 heapsort(first, last, swapper, comp);
141 auto p =
partition(first, last, swapper, comp);
142 introsort(first, p, swapper, comp, depth - 1);
143 introsort(p + 1, last, swapper, comp, depth - 1);
149 template <
typename RandomIt,
typename Swapper,
typename Compare>
150 inline void intrusive_sort(RandomIt first, RandomIt last, Swapper swapper, Compare comp)
155 uint32_t maxdepth =
static_cast<uint32_t
>(std::log2(n)) * 2;
159 template <
typename RandomIt,
typename Swapper>
162 intrusive_sort(first, last, swapper, std::less<
typename std::iterator_traits<RandomIt>::value_type>{});
RandomIt partition(RandomIt first, RandomIt last, Swapper swapper, Compare comp)
void heapsort(RandomIt first, RandomIt last, Swapper swapper, Compare comp)
void introsort(RandomIt first, RandomIt last, Swapper swapper, Compare comp, uint32_t depth)
void siftDown(RandomIt first, RandomIt start, RandomIt end, Swapper swapper, Compare comp)
RandomIt heap_parent(RandomIt first, RandomIt node)
void heapify(RandomIt first, RandomIt last, Swapper swapper, Compare comp)
RandomIt heap_right_child(RandomIt first, RandomIt node)
RandomIt heap_left_child(RandomIt first, RandomIt node)
void swap(any &aLhs, any &aRhs)
void intrusive_sort(RandomIt first, RandomIt last, Swapper swapper, Compare comp)
it_type next(it_type it, const typename iterator_traits< it_type >::difference_type distance=1)
iterator_traits< it_type >::difference_type distance(const it_type first, const it_type last)
it_type prev(it_type it, const typename iterator_traits< it_type >::difference_type distance=1)