Irurueta Sorting
| This documentation was generated with the assistance of AI. Please report any inaccuracies. |
Irurueta Sorting is a lightweight Java library that sorts arrays of primitives (double, float,
int, long) and of generic objects (Comparable or ordered through a Comparator), and that
selects the k-th smallest element or the median of an array without fully sorting it.
Core Components
The library organizes its public API around a single abstraction:
Sorter<T>: The abstract base class defines the operations offered by the library: sort,
sortWithIndices, select and median. It also acts as a factory, through the static
Sorter.create() and Sorter.create(SortingMethod) methods, for the concrete algorithm
implementations.
Algorithm implementations: Each of these classes extends Sorter<T> and implements one
specific sorting algorithm:
-
StraightInsertionSortersorts using the straight insertion method, adequate for small arrays. -
ShellSortersorts using Shell’s diminishing increment method, a fast improvement over straight insertion for medium-sized arrays. -
QuicksortSortersorts using the Quicksort algorithm, the fastest general-purpose method for large arrays. -
HeapsortSortersorts using the Heapsort algorithm, an in-place alternative to Quicksort with a guaranteed worst-case running time. -
SystemSorterdelegates to the sorting algorithms bundled with the Java SDK (java.util.Arrays), trading the ability to retrieve sorted indices for the SDK’s own performance characteristics.
SortingMethod: Enumerates the available algorithms so that a Sorter can be selected and
instantiated dynamically through Sorter.create(SortingMethod).
Practical Applications
Besides plain sorting, the library supports:
-
Sorting one array while producing an index table so that other arrays or collections can be reordered consistently (
sortWithIndices). -
Selecting the k-th smallest element of an array in linear time, without sorting the whole array (
select). -
Computing the median of an array, including generic types through the
ComparatorAndAveragerandComparableAndAverageableinterfaces, which describe how to average two elements together (median).
Getting Started
Users should begin with the installation guide, continue with usage for a tour of the API, and then read about the individual straight insertion, Shell, Quicksort and Heapsort algorithms, as well as selection and median computation.