Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::bucket_sort_detail Namespace Reference

Classes

struct  bucket_sort_invoker_factory
 Factory for bucket_sort with extra parameters. More...
 
struct  sort_invoker_factory
 Factory for lambdas that forward to a sort function. More...
 

Functions

template<typename T , class Compare >
void insertion_sort_range (T *a, const size_t lo, const size_t hi, const Compare &cmp) noexcept(std::is_nothrow_move_constructible_v< T > and std::is_nothrow_move_assignable_v< T > and noexcept(std::declval< const Compare & >()(std::declval< const T & >(), std::declval< const T & >())))
 Insertion sort a sub-array [lo, hi).
 
template<typename T , class Compare , class BucketKey >
void bucket_sort_impl (T *a, const size_t n, const size_t num_buckets, const BucketKey &bucket_key, const Compare &cmp)
 Core bucket sort implementation on a raw pointer range.
 
template<typename T , class Container , class SortFn , class Compare >
void apply_sort_with_temp (Container &a, SortFn sort_fn, const Compare &cmp)
 Helper to sort any container by copying to a temporary array.
 

Function Documentation

◆ apply_sort_with_temp()

template<typename T , class Container , class SortFn , class Compare >
void Aleph::bucket_sort_detail::apply_sort_with_temp ( Container a,
SortFn  sort_fn,
const Compare &  cmp 
)

Helper to sort any container by copying to a temporary array.

Used by bucket_sort and timsort wrappers for non-contiguous containers.

Note
This provides the basic exception-safety guarantee. If sort_fn or the comparator throws, the container a will remain in a valid but unspecified state because elements are moved to tmp.

Definition at line 5414 of file tpl_sort_utils.H.

References cmp(), Aleph::Array< T >::create(), and Aleph::divide_and_conquer_partition_dp().

◆ bucket_sort_impl()

template<typename T , class Compare , class BucketKey >
void Aleph::bucket_sort_detail::bucket_sort_impl ( T a,
const size_t  n,
const size_t  num_buckets,
const BucketKey bucket_key,
const Compare &  cmp 
)

Core bucket sort implementation on a raw pointer range.

Distributes elements into num_buckets buckets according to bucket_key, sorts each bucket with insertion sort, and writes the concatenated result back.

Template Parameters
TElement type.
CompareComparison functor.
BucketKeyCallable mapping T -> size_t bucket index.

Definition at line 5352 of file tpl_sort_utils.H.

References ah_domain_error_if, cmp(), Aleph::Array< T >::create(), Aleph::divide_and_conquer_partition_dp(), and insertion_sort_range().

Referenced by Aleph::bucket_sort(), and Aleph::bucket_sort().

◆ insertion_sort_range()

template<typename T , class Compare >
void Aleph::bucket_sort_detail::insertion_sort_range ( T a,
const size_t  lo,
const size_t  hi,
const Compare &  cmp 
)
noexcept

Insertion sort a sub-array [lo, hi).

Used internally by bucket sort to sort individual buckets.

Definition at line 5320 of file tpl_sort_utils.H.

References Aleph::and, cmp(), and Aleph::divide_and_conquer_partition_dp().

Referenced by bucket_sort_impl().