; Functions\Initialization.au3
; ----------------------------
; FAS_SortingInitVbSrc       Compile and load .NET code from source file.
; FAS_SortingInitVbDll       Load .NET code from .NET assembly DLL file.


; Sorting.au3
; ----------------------------
; FAS_Random2DArray          Creates/returns a 2D array of random data.
;                            Wrapper for FAS_Random2DArrayAu3, FAS_Random2DArrayOpt, FAS_Random2DArrayOptP, FAS_Random2DArrayOptEx.
;                            The purpose of the wrapper function is to select the fastest of the four functions.
; FAS_Sort2DArray            Index based sorting of a 2D array by one or more columns.
;                            Wrapper function for FAS_Sort2DArrayAu3, FAS_Sort2DArrayOpt and FAS_Sort2DArrayOptEx.
;                            The purpose of the wrapper function is to select the fastest of the three functions.

; SortingWr.au3
; ----------------------------
; FAS_Random2DArrayWr        Wrapper function for FAS_Random2DArray. Displays splash text and progress bar for large arrays.
; FAS_Sort2DArrayWr          Wrapper function for FAS_Sort2DArray. Displays splash text and progress bar for large arrays.


; Functions\RandomArray.au3
; ----------------------------
; FAS_Random2DArrayAu3       Creates/returns a 2D array of random data. Pure AutoIt code.
; FAS_Random2DArrayOpt       Creates/returns a 2D array of random data. Single-threaded VB code.
; FAS_Random2DArrayOptP      Creates a 2D array of data. Produces progress data in worker thread.
;                            Runs the same code as FAS_Random2DArrayOpt and produces progress data.
; FAS_Random2DArrayOptEx     Creates/returns a 2D array of random data. Multi-threaded VB code.
;                            Because the VB code runs multi-threaded it can produce progress data.
; FAS_Random2DArrayLimits    Number of rows and elements to decide which of the 4 functions to use.
; FAS_Random2DArrayWeight    Returns minimum number of weighted array elements for progress data.
;                            Also returns number of string columns (takes longer than other types).
; FAS_Random2DArrayCount     Returns number of rows to display progress under creation of array.
; FAS_Random2DArrayGet       Returns the 2D array of random data from VB code to AutoIt code.
; FAS_Random2DArrayDel       Deletes a 2D array of random data stored internally in VB code.

; Functions\RandomArrayGUI.au3
; ----------------------------
; FAS_Random2DArrayGUI       Returns an $aColumns array which defines the number of columns and data types in a random array.
;                            $aColumns array is created in an easy to use GUI. Through buttons a random array can be created
;                            and displayed with $aColumns as input. An au3 file with directly executable code can be created.


; Functions\IndexSort.au3
; ----------------------------
; FAS_Sort2DArrayAu3         Index based sorting of a 2D array by one or more columns. Pure AutoIt code.
; FAS_Sort2DArrayOpt         Index based sorting of a 2D array by one or more columns. Single-threaded VB code.
; FAS_Sort2DArrayOptEx       Index based sorting of a 2D array by one or more columns. Multi-threaded VB code.
;                            Because the VB code runs as multi-threaded code it can produce progress data.
; FAS_Sort2DArrayLimits      Number of rows and elements to decide which of the 3 functions to use.
; FAS_Sort2DIndexCount       Returns number of rows to display progress data while sorting the array.
; FAS_Sort2DIndexGet         Returns the sorting index as a 1D array of integers to AutoIt code.
; FAS_Sort2DDuplsCount       Returns the number of duplicates after the 2D array has been sorted.
; FAS_Sort2DDuplsGet         Returns a 1D array of duplicates after the 2D array has been sorted.
; FAS_Sort2DDuplsGetEx       Returns a 1D array of duplicate indices to use in _ArrayDisplayEx.
; FAS_Sort2DArrayDel         Deletes a 2D array (stored as global array) internally in VB code.

; Functions\IndexSortGUI.au3
; ----------------------------
; FAS_Sort2DArrayGUI         Takes an array as input and returns an $aCompare array which contains info about columns used
;                            in sorting. $aCompare array is created in an easy to use GUI. Through buttons the array can be
;                            sorted and displayed with $aCompare as input. An au3 file with executable code can be created.


; Functions\Initialization.au3
; ----------------------------
; Compile and load .NET code from a source file
; The source file must be specified with a full path
; Or it must be specified with a path relative to the running script
FAS_SortingInitVbSrc( $sSrcPath )

; Load .NET code from a .NET assembly DLL file
; The DLL file must be specified with a full path
; Or it must be specified with a path relative to the running script
; Or it must be placed in the same folder as the running script
;
; If you're having trouble loading a DLL file, copy the DLL file to the same
; folder as the running script, and compile the script into an EXE file.
FAS_SortingInitVbDll( $sDllPath = "" )


; Sorting.au3
; ----------------------------
; Creates/returns a 2D array of random data
FAS_Random2DArray( _
  $iRows, _         ; Number of rows in the array
  $aColumns, _      ; Number of columns and data types in the array, see 1) in docu
  $sSource = "", _  ; Character source for string columns, random strings are created from these characters
  $bRetArray = 1, _ ; True to return array, else the array is stored as a global variable in compiled code
  $bProgress = 0 _  ; True to calculate progress data while creation of the array is performed
  , _               ; A mechanism (loop) must be implemented to wait for the code to finish
  $iOptElms      = FAS_Random2DArrayLimits()[0], _ ; Determines which of the 3 case statements to use below
  $iOptExElems   = FAS_Random2DArrayLimits()[1], _ ; Determines which of the 3 case statements to use below
  $iProgressElms = FAS_Random2DArrayLimits()[3] )  ; Min. number of weighted array elements for progress data

; Index based sorting of a 2D array by one or more columns
; Returns the sorting index as a DllStruct/array of integers
FAS_Sort2DArray( _
  $aArray _            ; The 2D array to be sorted by index
  , _                  ; Or 0/"" if array is stored in VB code, 0) in docu
  $aCompare, _         ; Info about columns used in sorting, see 1) in docu
  $bDelArray = 1, _    ; Delete array (stored as global array) in VB code
  $bSortByIndex = 0, _ ; Sort duplicates by array index (asc), 2) in docu
  $bDuplicates = 0, _  ; Information about duplicate rows, 3) in docu
  $bProgress = 0 _     ; Calculate progress data while sorting the array is performed
  , _                  ; A mechanism (loop) must be implemented to wait for the code to finish
  $iOptRows      = FAS_Sort2DArrayLimits()[0], _ ; Determines which of the 3 case statements to use below
  $iOptExRows    = FAS_Sort2DArrayLimits()[1], _ ; Determines which of the 3 case statements to use below
  $iProgressRows = FAS_Sort2DArrayLimits()[2] )  ; Minimum number of array rows for progress data

; SortingWr.au3
; ----------------------------
FAS_Random2DArrayWr( _
  $iRows, _         ; Number of rows in the array
  $aColumns, _      ; Number of columns and data types in the array, see 1) in docu
  $sSource = "", _  ; Character source for string columns, random strings are created from these characters
  $bRetArray = 1 )  ; True to return array, else the array is stored as a global variable in compiled code

; Returns the 2D array of random
; data from VB code to AutoIt code.
; Displays splash text for large arrays.
FAS_Random2DArrayGetWr( _
  $iRows, _        ; Number of rows in the array
  $aColumns, _     ; Number of columns and data types in the array
  $bDelArray = 1 ) ; Delete array stored as global in VB code

FAS_Sort2DArrayWr( _
  $aArray _            ; The 2D array to be sorted by index
  , _                  ; Or 0/"" if array is stored in VB code, 0) in docu
  $aCompare, _         ; Info about columns used in sorting, see 1) in docu
  $bDelArray = 1, _    ; Delete array (stored as global array) in VB code
  $bSortByIndex = 0, _ ; Sort duplicates by array index (asc), 2) in docu
  $bDuplicates = 0 )   ; Information about duplicate rows, 3) in docu


; Functions\RandomArray.au3
; ----------------------------
; Creates/returns a 2D array of random data
FAS_Random2DArrayAu3( _
  $iRows, _       ; Number of rows in the array
  $aColumns, _    ; Number of columns and data types in the array, see 1) in docu
  $sSource = "" ) ; Character source for string columns, random strings are created from these characters

; Creates/returns a 2D array of random data
; Single-threaded creation of the 2D array
FAS_Random2DArrayOpt( _
  $iRows, _        ; Number of rows in the array
  $aColumns, _     ; Number of columns and data types in the array, see 1) in docu
  $sSource = "", _ ; Character source for string columns, random strings are created from these characters
  $bRetArray = 1 ) ; True to return array, else the array is stored as a global variable in compiled code

; Creates a 2D array of random data
; Single-threaded creation of the 2D array
; Runs in a worker thread to be able to produce progress data
FAS_Random2DArrayOptP( _
  $iRows, _       ; Number of rows in the array
  $aColumns, _    ; Number of columns and data types in the array, see 1) in docu
  $sSource = "" ) ; Character source for string columns, random strings are created from these characters

; Creates/returns a 2D array of random data
; Multi-threaded creation of the 2D array
FAS_Random2DArrayOptEx( _
  $iRows, _         ; Number of rows in the array
  $aColumns, _      ; Number of columns and data types in the array, see 1) in docu
  $sSource = "", _  ; Character source for string columns, random strings are created from these characters
  $bRetArray = 1, _ ; True to return array, else the array is stored as a global variable in compiled code
  $bProgress = 0 )  ; True to calculate progress data while creation of the array is performed
                    ; A mechanism (loop) must be implemented to wait for the code to finish

; Number of rows and elements to decide which of the 4 functions to use
FAS_Random2DArrayLimits()
  Static $aLimits = [ _
        1500    , _ ; Use FAS_Random2DArrayAu3     if less than      1,500 weighted array elements  eg.       100 strs,       500 flts or        750 ints
     2700000      _ ; Use FAS_Random2DArrayOpt     if less than  2,700,000 weighted array elements  eg.   180.000 strs,   900.000 flts or  1.350.000 ints
                , _ ; Use FAS_Random2DArrayOptEx   if more than  2,700,000 weighted array elements
           0.35   _ ; Use FAS_Random2DArrayOptP    if @AutoItX64 And $iStrCols / $iColumns > 0.35
                , _ ; Only FAS_Random2DArrayOptEx and FAS_Random2DArrayOptP produces progress data
     6000000    , _ ; Splash text to create array  if more than  6,000,000 weighted array elements  eg.   400.000 strs, 2.000.000 flts or  3.000.000 ints
    15000000    , _ ; Progress bar to create array if more than 15,000,000 weighted array elements  eg. 1.000.000 strs, 5.000.000 flts or  7.500.000 ints
    21000000    ]   ; Splash text to pass array    if more than 21,000,000 weighted array elements  eg. 1.400.000 strs, 7.000.000 flts or 10.500.000 ints

; Returns minimum number of weighted array elements for progress data
; Also returns number of string columns (takes longer than other types)
FAS_Random2DArrayWeight( _
  $iRows, _            ; Number of rows in the array
  $aColumns, _         ; Number of columns and data types in the array
  $iWeightStrs = 15, _ ; Weight for string elements      ; It takes about 7 times as long to create a string (16-32 chars) as an integer, date, time
  $iWeightInts =  2, _ ; Weight for integer, date, time  ; It takes about  5 times as long to create a string (16-32 chars) as a float, row/col
  $iWeightFlts =  3 )  ; Weight for float, row/col       ; It takes about 1 times as long to create a float, row/col as an integer, date, time

; Returns number of rows to display progress under creation of array
FAS_Random2DArrayCount( $bDelArray = False )

; Returns the 2D array of random data from VB code to AutoIt code
FAS_Random2DArrayGet( $iRows, $bDelArray = True )

; Deletes a 2D array of random data stored internally in VB code
FAS_Random2DArrayDel()

; Functions\RandomArrayGUI.au3
; ----------------------------
FAS_Random2DArrayGUI()


; Functions\IndexSort.au3
; ----------------------------
; Index based sorting of a 2D array by one or more columns
; Returns the sorting index as a DllStruct of integers
FAS_Sort2DArrayAu3( _
  $aArray, _           ; The 2D array to be sorted by index
  $aCompare, _         ; Info about columns used in sorting, see 1) in docu
  $bSortByIndex = 0, _ ; Sort duplicates by array index (asc), 2) in docu
  $bDuplicates = 0 )   ; Information about duplicate rows, 3) in docu

; Index based sorting of a 2D array by one or more columns
; Returns the sorting index as a 1D array of integers
; Single-threaded sorting of the 2D array
FAS_Sort2DArrayOpt( _
  $aArray _            ; The 2D array to be sorted by index
  , _                  ; Or 0/"" if array is stored in VB code, 0) in docu
  $aCompare, _         ; Info about columns used in sorting, see 1) in docu
  $bDelArray = 1, _    ; Delete array (stored as global array) in VB code
  $bSortByIndex = 0, _ ; Sort duplicates by array index (asc), 2) in docu
  $bDuplicates = 0 )   ; Information about duplicate rows, 3) in docu

; Index based sorting of a 2D array by one or more columns
; Returns the sorting index as a 1D array of integers
; Multi-threaded sorting of the 2D array
FAS_Sort2DArrayOptEx( _
  $aArray _            ; The 2D array to be sorted by index
  , _                  ; Or 0/"" if array is stored in VB code, 0) in docu
  $aCompare, _         ; Info about columns used in sorting, see 1) in docu
  $bDelArray = 1, _    ; Delete array (stored as global array) in VB code
  $bSortByIndex = 0, _ ; Sort duplicates by array index (asc), 2) in docu
  $bDuplicates = 0, _  ; Information about duplicate rows, 3) in docu
  $bProgress = 0 )     ; Calculate progress data while sorting the array is performed
                       ; A mechanism (loop) must be implemented to wait for the code to finish

; Number of rows and elements to decide which of the 3 functions to use
FAS_Sort2DArrayLimits()
  Static $aLimits = [ _
       100 , _ ; Use FAS_Sort2DArrayAu3     if less than     100 rows
     35000   _ ; Use FAS_Sort2DArrayOpt     if less than  35,000 rows
           , _ ; Use FAS_Sort2DArrayOptEx   if more than  35,000 rows
    150000 , _ ; Splash text to sort array  if more than 150,000 rows
    300000 , _ ; Progress bar to sort array if more than 300,000 rows
    750000 , _ ; Splash text to pass array  if more than 750,000 array elements (from AutoIt code to VB code)
    750000 ]   ; Splash text to pass index  if more than 750,000 rows           (from VB code to AutoIt code)

; Returns number of rows to display progress data while sorting the array
FAS_Sort2DIndexCount( $bDelArray = 0 )

; Returns the sorting index as a 1D array of integers to AutoIt code
FAS_Sort2DIndexGet( $iRows, $bDelArray = True, $bDuplicatesIn = 0, $bSortGlobalArrayIn = 0 )

; Returns the number of duplicates after the 2D array has been sorted
FAS_Sort2DDuplsCount( $bSet = 0, $iDuplsIn = -1 )

; Returns a 1D array of duplicates after the 2D array has been sorted
FAS_Sort2DDuplsGet( $bSet = 0, $aDuplsIn = 0 )

; Returns a 1D array of duplicate indices to use in _ArrayDisplayEx
FAS_Sort2DDuplsGetEx( $bSortDupls = 0 )

; Deletes a 2D array (stored as global array) internally in VB code
FAS_Sort2DArrayDel()

; Functions\IndexSortGUI.au3
; ----------------------------
FAS_Sort2DArrayGUI( _
  $aArray, _      ; The 2D array to be sorted by index
  $aColumns = 0 ) ; Number of columns and data types in the array
