diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-01-14 13:26:55 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-01-14 13:26:55 -0300 |
commit | 825ac8eca8e384d6ad2538b5670088c31e08a9d7 (patch) | |
tree | 14a92070cf251a1fc93246e92562ac2855dc676d | |
parent | b07fc10e91a5954254b47280aba287220c734a4b (diff) | |
download | lua-825ac8eca8e384d6ad2538b5670088c31e08a9d7.tar.gz lua-825ac8eca8e384d6ad2538b5670088c31e08a9d7.tar.bz2 lua-825ac8eca8e384d6ad2538b5670088c31e08a9d7.zip |
Corrected documentation for 'table.sort'
The sort function must define a (strict) weak order for a correct
sorting. A partial order is not enough.
-rw-r--r-- | manual/manual.of | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/manual/manual.of b/manual/manual.of index 09297a63..2fe332a4 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -7821,19 +7821,19 @@ from @T{list[1]} to @T{list[#list]}. | |||
7821 | If @id{comp} is given, | 7821 | If @id{comp} is given, |
7822 | then it must be a function that receives two list elements | 7822 | then it must be a function that receives two list elements |
7823 | and returns true when the first element must come | 7823 | and returns true when the first element must come |
7824 | before the second in the final order | 7824 | before the second in the final order, |
7825 | (so that, after the sort, | 7825 | so that, after the sort, |
7826 | @T{i < j} implies @T{not comp(list[j],list[i])}). | 7826 | @T{i <= j} implies @T{not comp(list[j],list[i])}. |
7827 | If @id{comp} is not given, | 7827 | If @id{comp} is not given, |
7828 | then the standard Lua operator @T{<} is used instead. | 7828 | then the standard Lua operator @T{<} is used instead. |
7829 | 7829 | ||
7830 | Note that the @id{comp} function must define | 7830 | The @id{comp} function must define a consistent order; |
7831 | a strict partial order over the elements in the list; | 7831 | more formally, the function must define a strict weak order. |
7832 | that is, it must be asymmetric and transitive. | 7832 | (A weak order is similar to a total order, |
7833 | Otherwise, no valid sort may be possible. | 7833 | but it can equate different elements for comparison purposes.) |
7834 | 7834 | ||
7835 | The sort algorithm is not stable: | 7835 | The sort algorithm is not stable: |
7836 | elements considered equal by the given order | 7836 | Different elements considered equal by the given order |
7837 | may have their relative positions changed by the sort. | 7837 | may have their relative positions changed by the sort. |
7838 | 7838 | ||
7839 | } | 7839 | } |