sorting_20arrays_20of_20structures
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| sorting_20arrays_20of_20structures [2018/03/31 13:19] – external edit 127.0.0.1 | sorting_20arrays_20of_20structures [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| //by Michael Hutton, October 2008//\\ \\ The SORTSALIB library provides a fast way of sorting Arrays of Structures. It will sort the following types of structure elements: bytes(& | //by Michael Hutton, October 2008//\\ \\ The SORTSALIB library provides a fast way of sorting Arrays of Structures. It will sort the following types of structure elements: bytes(& | ||
| + | <code bb4w> | ||
| INSTALL @lib$ + " | INSTALL @lib$ + " | ||
| + | </ | ||
| it contains the single function FN_sortSAinit(dir%, | it contains the single function FN_sortSAinit(dir%, | ||
| + | <code bb4w> | ||
| sortsa% = FN_sortSAinit(dir%, | sortsa% = FN_sortSAinit(dir%, | ||
| + | </ | ||
| where dir% determines the sorting direction (0 = ascending, 1 = descending) and smode% determines how strings are sorted (0 = normal, 1 = ignore case). You could, if you wanted, initialise it four times with the different options. eg.\\ | where dir% determines the sorting direction (0 = ascending, 1 = descending) and smode% determines how strings are sorted (0 = normal, 1 = ignore case). You could, if you wanted, initialise it four times with the different options. eg.\\ | ||
| + | <code bb4w> | ||
| sortascendingnormal% = FN_sortSAinit(0, | sortascendingnormal% = FN_sortSAinit(0, | ||
| sortdescendingnormal% = FN_sortSAinit(1, | sortdescendingnormal% = FN_sortSAinit(1, | ||
| sortascendingignore% = FN_sortSAinit(0, | sortascendingignore% = FN_sortSAinit(0, | ||
| sortdescendingignore% = FN_sortSAinit(1, | sortdescendingignore% = FN_sortSAinit(1, | ||
| + | </ | ||
| and then CALL the appropriate variable when needed.\\ \\ Beware that the calling procedure is slightly different from SORTLIB in that C% = howmany to sort and D% = starting index of element to sort. For example, if we DIM a structure with the following code: | and then CALL the appropriate variable when needed.\\ \\ Beware that the calling procedure is slightly different from SORTLIB in that C% = howmany to sort and D% = starting index of element to sort. For example, if we DIM a structure with the following code: | ||
| + | <code bb4w> | ||
| DIM structure{(100) a&, b%, c, d#, e$} | DIM structure{(100) a&, b%, c, d#, e$} | ||
| + | </ | ||
| To sort the entire array of structures using the a& element as the sort key.\\ | To sort the entire array of structures using the a& element as the sort key.\\ | ||
| + | <code bb4w> | ||
| C% = DIM(structure{()}, | C% = DIM(structure{()}, | ||
| + | </ | ||
| Note that we MUST pass structure{()} as the first parameter and the keys follow that.\\ \\ To sort part of the array of structures: | Note that we MUST pass structure{()} as the first parameter and the keys follow that.\\ \\ To sort part of the array of structures: | ||
| + | <code bb4w> | ||
| C% = howmany : D% = first : CALL sortsa%, structure{()}, | C% = howmany : D% = first : CALL sortsa%, structure{()}, | ||
| + | </ | ||
| To use other variables as keys add them as parameters: | To use other variables as keys add them as parameters: | ||
| + | <code bb4w> | ||
| C% = howmany : D% = first : CALL sortsa%, structure{()}, | C% = howmany : D% = first : CALL sortsa%, structure{()}, | ||
| \ structure{(0)}.b%, | \ structure{(0)}.b%, | ||
| + | </ | ||
| would sort " | would sort " | ||
sorting_20arrays_20of_20structures.1522502383.txt.gz · Last modified: 2024/01/05 00:16 (external edit)