Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
changeset 771:1c9c1cd4fd47
farray.sh: Prepare for multiple array sort implementations
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 23 Oct 2024 15:59:46 +0200 |
| parents | 56ab5c012d5f |
| children | e942b091b762 |
| files | share/local-bsdtools/farray.sh |
| diffstat | 1 files changed, 45 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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
