quicksort optimized for duplicate keys