This is a somewhat ugly implementation of a sorting algorithm I found.
It's a stable, O(n log(n)) sort that unfortunately isn't in-place, but does
have best-case O(n) behavior for nearly-sorted lists. It finds upward and
downwards runs in the input and merges them.