Jump to content

Recommended Posts

Posted (edited)

Sort a multi-dimensional array with multiple sort columns. Max 9 dimensions.

This routine focus on functionality and flexibility and not on performance.
It is meant to be a supplement to the _ArraySort routine which focus is on performance.
I have included a parameter description below which gives you an idea how it works.
Also I feel that the example file should get you started.

; _ArraySortMulti
; Sort a multi-dimensional array with multiple sort columns. Max 9 dimensions.
;
; _ArraySortMulti(ByRef $avArray, COL0 ..[, mixed $arg], COL1 ..[, mixed $arg], [DEBUG])
; $avArray      - Array to sort.
; $sCOL0,$sCOL1 - Required. Must be COL followed by a number.
;                 First column start with zero - COL0.
;                 A 1-dimensional array has one column named COL0.
;                 Multiple sort columns are allowed in any order.
; $arguments    - [optional] ASC, DESC, REGULAR, NUMERIC, STRING, INSEN_STRING, UserOrder, HexOrder.
;                 Can be repeated for every column to sort.
;                 All arguments can be specified in any order and in both lower and upper case.
;                 You can place all arguments in one string separated by comma
;                 or mix it with multiple strings in separate variables.
;                 Do whatever is convenient to you.
; $sASC         - Default=ASC. ASC gives Ascending sort order.
; $sDESC        - Default=ASC. DESC gives Descending sort order.
; $sREGULAR     - Default=REGULAR. REGULAR treat values as they are. Don't change types.
;                 Lexicographically string compares. Case insensitive.
;                 WARNING: Using REGULAR with strings might give you unpredictable results like 'AA' > 'AB'.
;                 Use STRING, INSEN_STRING and NUMERIC whenever possible.
; $sNUMERIC     - Default=REGULAR. NUMERIC treat values numerically.
; $sSTRING      - Default=REGULAR. STRING treat values as strings. Case sensitive.
; $sINSEN_STRING- Default=REGULAR. INSEN_STRING treat values as strings. Case insensitive.
; $sUserOrder   - Default=No order change. Change sort order without changing any data in the array.
;                 Specify UserOrder=(DataFrom=DataTo in pairs (FromTo) separated by semicolon).
;                 Example UserOrder=(January=1;February=2;March=3;April=4) Changes the orders of months lacking numbers.
;                 You do not use single or double quotes inside parenthesis unless they are data themselves.
;                 Parameters like NUMERIC, STRING applies like normal, see examples.
; $sHexOrder    - Default=No order change. Change sort order without changing any data in the array.
;                 Specify HexOrder=(HexFrom=HexTo in pairs (FromTo) separated by semicolon).
;                 Example HexOrder=(C6=5B;D8=5C;C5=5D;E6=7B;F8=7C;E5=7D) Changes hexcode C6 to 5B and so on.
;                 The main purpose of this is to simplify sorting for countries like the Scandinavians
;                 who use additional letters to the english alphabet. A one time job for each country.
;                 Example Hex(Asc("Æ"),2)) & Hex(91,2) will give HexOrder=(C6=5B)
;                 Replace hexcode C6 with 5B without changing data so as to change sort order of strings.
; $sDEBUG       - Default=No debug. If DEBUG will list the arrays before and after sort.
;                                   You only need to specify once.
; Return values : Success = 1
;                 Failure = 0, sets @error:
;                 |1 - $avArray is not an array
;                 |3 - Invalid COL parameter
;                 |4 - COL parameter missing or in wrong position
;                 |5 - Unknown parameter found
;                 |6 - Max 9-dimensions exceeded.
;                 |7 - Cannot use NUMERIC and HexOrder on the same column
;                 |8 - HexOrder specifications invalid
;                 |9 - UserOrder specifications invalid
; Author        : Thopaga
; Modified      : 18 aug 2019
; Remarks       : This routine focus on functionality and flexibility and not on performance.
;                 It is meant to be a supplement to the _ArraySort routine which focus is on performance.
; Related       : _ArraySort
; Link          :
; Example       : Yes

 

ArraySortMulti.zip

Edited by Thopaga
Rewritten to make it more simple.
Posted

Suggestion: A category listing for all those unofficial routines that has been made with link to the example forum.

The person itself could put it into that category and remove it, so that little administration is necessary.

Although I like the idea in general, I'm a little skeptical about it actually working in the long run. If you could elaborate on it some more that would be nice. (Probably better to do so in a separate chat topic.)

Not looked at your example yet, but it sounds interesting.

TIA for sharing.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...