# HG changeset patch # User Franz Glasner # Date 1729691986 -7200 # Node ID 1c9c1cd4fd47366aae9c53d0d4b85bb255bf9045 # Parent 56ab5c012d5f4ea52f1af65e5aebd65a0a64875a farray.sh: Prepare for multiple array sort implementations diff -r 56ab5c012d5f -r 1c9c1cd4fd47 share/local-bsdtools/farray.sh --- a/share/local-bsdtools/farray.sh Wed Oct 23 13:56:52 2024 +0200 +++ b/share/local-bsdtools/farray.sh Wed Oct 23 15:59:46 2024 +0200 @@ -1614,11 +1614,7 @@ #: -#: Sort using Gnome Sort. -#: -#: This is a very simple stable sort (a variant of insertion sort). -#: -#: See: https://en.wikipedia.org/wiki/Gnome_sort +#: Sort an array. #: #: Args: #: $1: The array to sort to @@ -1631,6 +1627,50 @@ _farr_array_get_meta "$@" + _farr_array_gnomesort +} + + +#: +#: Sort an array using Gnome Sort. +#: +#: Args: +#: $1: The array to sort to +#: +#: See Also: +#: `_farr_array_gnomesort` +#: +farray_gnomesort() { + local __farr_name + + local __farr_token __farr_gvrname __farr_len \ + __farr_pos __farr_val __farr_val_1 + + _farr_array_get_meta "$@" + + _farr_array_gnomesort +} + + +#: +#: Internal sort implementation using Gnome Sort. +#: +#: This is a very simple stable sort (a variant of insertion sort). +#: +#: See: https://en.wikipedia.org/wiki/Gnome_sort +#: +#: Input (Globals): +#: All the "Output (Globals)" from `farr_array_get_meta`: +#: __farr_name, __farr_token, __farr_gvrname and __farr_len. +#: These variables are declared local in this function but the shell +#: initializes them from the same variables in the nearest dynamic scope. +#: So they are really input variables and not also output variables. +#: +_farr_array_gnomesort() { + + local __farr_name __farr_token __farr_gvrname __farr_len \ + __farr_pos __farr_val __farr_val_1 + __farr_pos=1 while [ "${__farr_pos}" -le "${__farr_len}" ]; do if [ "${__farr_pos}" -eq 1 ]; then