Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add docstring for small threshold #54602

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,11 @@ The algorithms used by `DEFAULT_UNSTABLE` are an implementation detail. They are
the same as those used by [`DEFAULT_STABLE`](@ref), but this is subject to change in future.
"""
const DEFAULT_UNSTABLE = DEFAULT_STABLE
"""
DanielFrantes marked this conversation as resolved.
Show resolved Hide resolved
SMALL_THRESHOLD

SMALL_THRESHOLD is a constant that is used internally to decide what is considered to be small or large.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lot better already, but it isn't yet all that helpful as it gives no indication about the context in which it is used, i.e. what "small" or "large" mean or affect.

I think something to the effect of: for vectors with less (?) than SMALL_THRESHOLD elements, sorting switches to a different algorithm SMALL_ALGORITHM, otherwise it uses the big algorithm. This is in particular relevant for recursive sorting algorithms which reduce to smaller sublists, sort those and combine the result.

Note that SMALL_ALGORITHM also has a docstring.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The threshold at which to switch sorting algorithms based on size is also quite variable. SMALL_THRESHOLD is only used in some cases (e.g. QuickSort and MergeSort)

"""
const SMALL_THRESHOLD = 20

function Base.show(io::IO, alg::Algorithm)
Expand Down