Functions Index :: A :: ArraySort
Module:
array :: transforms
Definition:
ArraySort(string array, bool "ascending", string "cmp_func", string "cmp_args", string "avg_func", string "avg_args")
Description:
Sorts array, using the quick sort algorithm [1].
Arguments:
array: The array to sort.
ascending (Optional, defaults to true): Boolean flag to determine the sort order (ascending or descending).
cmp_func (Optional, defaults to standard Avisynth comparison operators (>, <)): The name of a custom user function for comparing array elements.
cmp_args (Optional, defaults to "": Additional arguments (as a string) for the custom compare function.
avg_func (Optional, defaults to Average()): The name of a custom user function for averaging array elements.
avg_args: (Optional, defaults to "": Additional arguments (as a string) for the custom average function.
Notes and conditions on arguments relations:
1] Both cmp_func and avg_func must accept two array elements (of the appropriate type) as their first two arguments in their argument list.
2] cmp_func must return one of the -1, 0, 1 when elm1 < elm2, elm1 == elm2, elm1 > elm2, respectively.
Examples:
a1 = ArrayCreate(1, 3, 5, 8, 12, -4, 0, 2)
a2 = a1.ArraySort()
# a2 == "-4, 0, 1, 2, 3, 5, 8, 12"
a3 = a1.ArraySort(false)
# a3 == "12, 8, 5, 3, 2, 1, 0, -4"
[1]:In order to sort arrays containing clips, both cmp_func and avg_func must be provided because the standard Avisynth operators (>, < for comparison and +, / for averaging) do not directly apply to clips.
The same is true when array contains mixed types (for example numbers and strings).