This chapter describes functions for sorting data, both directly and
indirectly (using an index). All the functions use the heapsort
algorithm. Heapsort is an O(N \log N) algorithm which operates
in-place. It does not require any additional storage and provides
consistent performance. The running time for its worst-case (ordered
data) is not significantly longer than the average and best
cases. Note that the heapsort algorithm does not preserve the relative
ordering of equal elements -- it is an unstable sort. However
the resulting order of equal elements will be consistent across
different platforms when using these functions.