12 template<
typename Type,
typename Fn>
16 for (Type
const&
object : objects)
18 result += ice::forward<Fn>(fn)(object);
23 template<
typename T,
typename U = T>
requires (std::convertible_to<T, U>)
26 template<
typename T,
typename Comp,
typename U = T>
requires (std::convertible_to<T, U>)
29 template<
typename T,
typename U = T>
requires (std::convertible_to<T, U>)
32 template<
typename T,
typename Comp,
typename U = T>
requires (std::convertible_to<T, U>)
35 template<
typename T,
typename U = T>
requires (std::convertible_to<T, U>)
38 template<
typename T,
typename Comp,
typename U = T>
requires (std::convertible_to<T, U>)
41 template<
typename T,
typename U = T>
requires (std::convertible_to<T, U>)
44 template<
typename T,
typename Comp,
typename U = T>
50 template<
typename T,
typename Pred>
53 template<
typename K,
typename V,
typename Pred>
60 template<typename K, typename Pred>
63 template<typename Node, typename Pred>
67 template<typename T, typename U> requires (std::convertible_to<T, U>)
70 return static_cast<ice::u32>(std::lower_bound(values.begin(), values.end(), value) - values.begin());
73 template<
typename T,
typename Comp,
typename U>
requires (std::convertible_to<T, U>)
76 return static_cast<ice::u32>(std::lower_bound(values.
begin(), values.
end(), value, ice::forward<Comp>(comp)) - values.
begin());
79 template<
typename T,
typename U>
requires (std::convertible_to<T, U>)
85 template<
typename T,
typename Comp,
typename U>
requires (std::convertible_to<T, U>)
88 return static_cast<ice::u32>(std::upper_bound(values.
begin(), values.
end(), value, ice::forward<Comp>(comp)) - values.
begin());
91 template<
typename T,
typename U>
requires (std::convertible_to<T, U>)
95 return (values.
size() != out_index) && (values[out_index] == predicate);
98 template<
typename T,
typename Comp,
typename U>
requires (std::convertible_to<T, U>)
102 return (values.
size() != out_index) && (values[out_index] == predicate);
105 template<
typename T,
typename U>
requires (std::convertible_to<T, U>)
108 return search(values, value, [](
auto const& l,
auto const& r)
noexcept {
return l == r; }, out_index);
111 template<
typename T,
typename Comp,
typename U>
116 if (ice::forward<Comp>(comp)(values[idx], value))
118 out_index = idx.u32();
125 template<
typename T,
typename Comp,
typename... U>
130 if (ice::forward<Comp>(comp)(values[idx], idx, params...))
142 template<
typename K,
typename V,
typename Pred>
145 K* pivot = &keys[right];
152 if (ice::forward<Pred>(pred)(keys[j], *pivot))
155 ice::swap(keys[i], keys[j]);
156 ice::swap(values[i], values[j]);
160 ice::swap(keys[i + 1], keys[right]);
161 ice::swap(values[i + 1], values[right]);
165 template<
typename Pred,
typename Key,
typename... Values>
174 Key* pivot = &keys[right];
181 if (ice::forward<Pred>(pred)(keys[j], *pivot))
184 ice::swap(keys[i], keys[j]);
185 (ice::swap(values[i], values[j]), ...);
189 ice::swap(keys[i + 1], keys[right]);
190 (ice::swap(values[i + 1], values[right]), ...);
194 template<
typename K,
typename Pred>
197 K* pivot = &keys[indices[right]];
204 if (ice::forward<Pred>(pred)(keys[indices[j]], *pivot))
207 ice::swap(indices[i], indices[j]);
211 ice::swap(indices[i + 1], indices[right]);
219 template<
typename K,
typename V,
typename Pred>
232 template<
typename Pred,
typename Key,
typename... Values>
244 ice::forward<Pred>(pred), left, right, keys, values...
253 template<
typename K,
typename Pred>
271 std::sort(span.begin(), span.end());
274 template<
typename T,
typename Pred>
277 std::sort(span.begin(), span.end(), ice::forward<Pred>(pred));
280 template<
typename K,
typename V,
typename Pred>
289 template<
typename Key,
typename Pred,
typename... Values>
294 ice::i32 const last_index = keys.size().u32() - 1;
299 template<
typename K,
typename Pred>
303 ice::i32 const last_index = keys.size().u32() - 1;
308 template<
typename Node,
typename Pred>
311 Node* right_list = left_list;
314 left_list->_next =
nullptr;
319 right_list = right_list->_next;
320 right_list->_next =
nullptr;
321 left_list->_next =
nullptr;
325 uint32_t
const half_size = size / 2;
326 for (uint32_t idx = half_size; idx > 0; --idx)
328 right_list = right_list->_next;
331 Node* next = right_list->_next;
332 right_list->_next =
nullptr;
339 Node result{ ._next = left_list };
341 while (left_list->_next !=
nullptr && right_list !=
nullptr)
343 Node* temp = left_list->_next;
344 if (pred(*temp, *right_list) ==
false)
347 left_list->_next = right_list;
352 left_list = left_list->_next;
356 left_list->_next = right_list;
366 std::sort(std::next(std::begin(result), start_offset), std::end(result));
Definition utility.hxx:80
void qsort_many(Pred &&pred, ice::i32 left, ice::i32 right, ice::Span< Key > keys, ice::Span< Values >... values) noexcept
Definition sort.hxx:233
auto qsort_partition_indices(ice::Span< K > keys, ice::Span< ice::u32 > &indices, Pred &&pred, ice::i32 left, ice::i32 right) noexcept -> ice::i32
Definition sort.hxx:195
auto qsort_partition_many(Pred &&pred, ice::i32 left, ice::i32 right, ice::Span< Key > keys, ice::Span< Values >... values) noexcept -> ice::i32
Definition sort.hxx:166
auto qsort_partition(ice::Span< K > keys, ice::Span< V > &values, Pred &&pred, ice::i32 left, ice::i32 right) noexcept -> ice::i32
Definition sort.hxx:143
void qsort(ice::Span< K > keys, ice::Span< V > values, Pred &&pred, ice::i32 left, ice::i32 right) noexcept
Definition sort.hxx:220
void qsort_indices(ice::Span< K > keys, ice::Span< ice::u32 > indices, Pred &&pred, ice::i32 left, ice::i32 right) noexcept
Definition sort.hxx:254
arr_t< Size, T > arr
Definition array.hxx:178
SPDX-License-Identifier: MIT.
Definition array.hxx:12
Span(ice::Span< T > &&) noexcept -> Span< T >
constexpr bool search(ice::Span< T > values, U const &value, ice::u32 &out_index) noexcept
Definition sort.hxx:106
constexpr bool binary_search(ice::Span< T > values, U const &value, ice::u32 &out_index) noexcept
Definition sort.hxx:92
void sort(ice::Span< T > span) noexcept
Definition sort.hxx:269
constexpr auto lower_bound(ice::Span< T > values, U const &value) noexcept -> ice::u32
Definition sort.hxx:68
auto sort_linked_list(Node *left_list, ice::u32 size, Pred &&pred) noexcept -> Node *
Definition sort.hxx:309
constexpr auto upper_bound(ice::Span< T > values, U const &value) noexcept -> ice::u32
Definition sort.hxx:80
std::int32_t i32
Definition types.hxx:21
void sort_many(ice::Span< Key > keys, Pred &&pred, ice::Span< Values >... values) noexcept
Definition sort.hxx:291
constexpr auto count(T const (&)[Size]) noexcept -> ice::u32
Definition base.hxx:43
constexpr bool search_with(ice::Span< T > values, Comp &&comp, ice::u32 &out_index, U const &... params) noexcept
Definition sort.hxx:126
std::uint32_t u32
Definition types.hxx:26
auto accumulate_over(ice::Span< Type > objects, Fn &&fn) noexcept -> ice::u32
Definition sort.hxx:13
void sort_indices(ice::Span< K > keys, ice::Span< ice::u32 > indices, Pred &&pred) noexcept
Definition sort.hxx:300
constexpr auto constexpr_sort_stdarray(T const &arr, ice::u32 start_offset=0) noexcept -> T
Definition sort.hxx:363
A view into an array of objects laid out in contiguous memory.
Definition span.hxx:17
constexpr auto size(this Span const &self) noexcept -> ice::ncount
Definition span.hxx:45
constexpr auto begin(this Self &&self) noexcept -> ice::container::Iterator< Self >
Definition contiguous_container.hxx:75
constexpr auto end(this Self &&self) noexcept -> ice::container::Iterator< Self >
Definition contiguous_container.hxx:81