summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-10-08 13:56:25 +0200
committerRémi Verschelde <rverschelde@gmail.com>2022-10-08 13:56:25 +0200
commit358c751658cec7ae156ea36607473c75dd4f967c (patch)
tree911fc2162a5a47108c36b7899f8bb2b891088187 /doc
parentbea0cbbb4d255e89acee7a1a13db42c2fcf64105 (diff)
parent85b617a6a3a17f05b8e111220daec6eb769a81e8 (diff)
Merge pull request #67053 from Calinou/doc-array-sort-not-stable
Document `Array.sort()` and `sort_custom()` using unstable sorting
Diffstat (limited to 'doc')
-rw-r--r--doc/classes/Array.xml4
1 files changed, 3 insertions, 1 deletions
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml
index d8c4b8fdb5..047089c917 100644
--- a/doc/classes/Array.xml
+++ b/doc/classes/Array.xml
@@ -557,6 +557,7 @@
<return type="void" />
<description>
Sorts the array.
+ [b]Note:[/b] The sorting algorithm used is not [url=https://en.wikipedia.org/wiki/Sorting_algorithm#Stability]stable[/url]. This means that values considered equal may have their order changed when using [method sort].
[b]Note:[/b] Strings are sorted in alphabetical order (as opposed to natural order). This may lead to unexpected behavior when sorting an array of strings ending with a sequence of numbers. Consider the following example:
[codeblocks]
[gdscript]
@@ -581,7 +582,8 @@
<param index="0" name="func" type="Callable" />
<description>
Sorts the array using a custom method. The custom method receives two arguments (a pair of elements from the array) and must return either [code]true[/code] or [code]false[/code]. For two elements [code]a[/code] and [code]b[/code], if the given method returns [code]true[/code], element [code]b[/code] will be after element [code]a[/code] in the array.
- [b]Note:[/b] You cannot randomize the return value as the heapsort algorithm expects a deterministic result. Doing so will result in unexpected behavior.
+ [b]Note:[/b] The sorting algorithm used is not [url=https://en.wikipedia.org/wiki/Sorting_algorithm#Stability]stable[/url]. This means that values considered equal may have their order changed when using [method sort_custom].
+ [b]Note:[/b] You cannot randomize the return value as the heapsort algorithm expects a deterministic result. Randomizing the return value will result in unexpected behavior.
[codeblocks]
[gdscript]
func sort_ascending(a, b):