Module: 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.

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

Sort the 1D array Data in-place using a sequential bubble sort algorithm.

Arguments:
  • Data : [] eltType – The array to be sorted
  • doublecheck : bool – Verify the array is correctly sorted before returning
  • reverse : bool – Sort in reverse numerical order
proc HeapSort(Data: [?Dom] ?elType, doublecheck = false, param reverse = false)

Sort the 1D array Data in-place using a sequential heap sort algorithm.

Arguments:
  • Data : [] elType – The array to be sorted
  • doublecheck : bool – Verify the array is correctly sorted before returning
  • reverse : bool – Sort in reverse numerical order
proc InsertionSort(Data: [?Dom] ?elType, doublecheck = false, param reverse = false)

Sort the 1D array Data in-place using a sequential insertion sort algorithm.

Arguments:
  • Data : [] eltType – The array to be sorted
  • doublecheck : bool – Verify the array is correctly sorted before returning
  • reverse : bool – Sort in reverse numerical order
proc MergeSort(Data: [?Dom], minlen = 16, doublecheck = false, param reverse = false)

Sort the 1D array Data in-place using a parallel merge sort algorithm.

Arguments:
  • Data : [] eltType – The array to be sorted
  • minlen : integral – When the array size is less than minlen use insertion sort algorithm
  • doublecheck : bool – Verify the array is correctly sorted before returning
  • reverse : bool – Sort in reverse numerical order
proc QuickSort(Data: [?Dom] ?elType, minlen = 16, doublecheck = false, param reverse = false)

Sort the 1D array Data in-place using a sequential quick sort algorithm.

Arguments:
  • Data : [] eltType – The array to be sorted
  • minlen : integral – When the array size is less than minlen use insertion sort algorithm
  • doublecheck : bool – Verify the array is correctly sorted before returning
  • reverse : bool – Sort in reverse numerical order
proc SelectionSort(Data: [?Dom], doublecheck = false, param reverse = false)

Sort the 1D array Data in-place using a sequential selection sort algorithm.

Arguments:
  • Data : [] eltType – The array to be sorted
  • doublecheck : bool – Verify the array is correctly sorted before returning
  • reverse : bool – Sort in reverse numerical order
proc VerifySort(Data: [?Dom] ?elType, str: string, param reverse = false)

Verify that the array Data is in sorted order and halt if any element is out of order.

Arguments:
  • Data : [] eltType – The array to verify
  • str : string – string to print while halting if an element is out of order
  • reverse : bool – if true, expect the values to be sorted in reverse.
iter sorted(x)

Yield the elements of argument x in sorted order.

Arguments:x : iterable – An iterable value to be sorted and yielded element by element
Yields:The elements of x in sorted order
Yield type:x’s element type