.. default-domain:: chpl

.. module:: Sort
   :synopsis: The `Sort` module is designed to support standard sorting

Sort
====

The `Sort` module is designed to support standard sorting
routines.  The current interface is minimal and should be expected to
grow and evolve over time. Each of the following functions accepts an
optional boolean argument, `reverse`, which is `false` by
default. If `true`, then the sort function will order in reverse.



.. function:: proc BubbleSort(Data: [?Dom] ?eltType, doublecheck = false, param reverse = false)

   
   Sort the 1D array `Data` in-place using a sequential bubble sort algorithm.
   
   :arg Data: The array to be sorted
   :type Data: [] `eltType`
   :arg doublecheck: Verify the array is correctly sorted before returning
   :type doublecheck: `bool`
   :arg reverse: Sort in reverse numerical order
   :type reverse: `bool`
   
   

.. function:: proc HeapSort(Data: [?Dom] ?eltType, doublecheck = false, param reverse = false)

   
   Sort the 1D array `Data` in-place using a sequential heap sort algorithm.
   
   :arg Data: The array to be sorted
   :type Data: [] `eltType`
   :arg doublecheck: Verify the array is correctly sorted before returning
   :type doublecheck: `bool`
   :arg reverse: Sort in reverse numerical order
   :type reverse: `bool`
   
   

.. function:: proc InsertionSort(Data: [?Dom] ?eltType, doublecheck = false, param reverse = false)

   
   Sort the 1D array `Data` in-place using a sequential insertion sort algorithm.
   
   :arg Data: The array to be sorted
   :type Data: [] `eltType`
   :arg doublecheck: Verify the array is correctly sorted before returning
   :type doublecheck: `bool`
   :arg reverse: Sort in reverse numerical order
   :type reverse: `bool`
   
   

.. function:: proc MergeSort(Data: [?Dom], minlen = 16, doublecheck = false, param reverse = false)

   
   Sort the 1D array `Data` in-place using a parallel merge sort algorithm.
   
   :arg Data: The array to be sorted
   :type Data: [] `eltType`
   :arg minlen: When the array size is less than `minlen` use insertion sort algorithm
   :type minlen: `integral`
   :arg doublecheck: Verify the array is correctly sorted before returning
   :type doublecheck: `bool`
   :arg reverse: Sort in reverse numerical order
   :type reverse: `bool`
   
   

.. function:: proc QuickSort(Data: [?Dom] ?eltType, minlen = 16, doublecheck = false, param reverse = false)

   
   Sort the 1D array `Data` in-place using a sequential quick sort algorithm.
   
   :arg Data: The array to be sorted
   :type Data: [] `eltType`
   :arg minlen: When the array size is less than `minlen` use insertion sort algorithm
   :type minlen: `integral`
   :arg doublecheck: Verify the array is correctly sorted before returning
   :type doublecheck: `bool`
   :arg reverse: Sort in reverse numerical order
   :type reverse: `bool`
   
   

.. function:: proc SelectionSort(Data: [?Dom], doublecheck = false, param reverse = false)

   
   Sort the 1D array `Data` in-place using a sequential selection sort
   algorithm.
   
   :arg Data: The array to be sorted
   :type Data: [] `eltType`
   :arg doublecheck: Verify the array is correctly sorted before returning
   :type doublecheck: `bool`
   :arg reverse: Sort in reverse numerical order
   :type reverse: `bool`
   
   

.. function:: proc VerifySort(Data: [?Dom] ?eltType, str: string, param reverse = false)

   
   Verify that the array `Data` is in sorted order and halt if any element is
   out of order.
   
   :arg Data: The array to verify
   :type Data: [] `eltType`
   :arg str: string to print while halting if an element is out of order
   :type str: `string`
   :arg reverse: if true, expect the values to be sorted in reverse.
   :type reverse: `bool`
   
   

.. iterfunction:: iter sorted(x)

   
   Yield the elements of argument `x` in sorted order.
   
   :arg x: An iterable value to be sorted and yielded element by element
   :type x: `iterable`
   
   :yields: The elements of x in sorted order
   :ytype: x's element type
   
   

