-
Notifications
You must be signed in to change notification settings - Fork 223
Question: should NumericSort skip leading zeroes when comparing numbers? #1413
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
Comments
Do you mean that you want to sort names as follow? Before
After
or
|
It depends on what we're aiming for. But the current implementation is not a "truly" numeric sort, since it assumes that leading zeroes should "non-numerically" contribute to the sorting order (since substring length currently takes precedence over actual numeric value). Below is a (hopefully) clarifying example... NOTE: I've inserted extra line breaks where the numeric sequence-ordering breaks! The following list is sorted alphabetically (not taking "numbers" into account, only individual digits) :
This is what it should look in a "truly" numeric order (i.e after converting each numeric substring to an integer, and then sorting these numeric substrings using these integers) :
However, using the current implementation of
Maybe this is what is intended, though, hence the question in the title of this issue... |
I don't think there is anything wrong now. When we name a file or branch, if we use three digits, in general, it means that we may have 001 to 999 possibilities. That is to say, 010 at this time does not indicate the first one, but 10th one in the files of the naming method. The previous one is 009, and the latter is 011.
|
Thanks, I see - just wanted to make sure this was "by-design" and not a bug... It will be identical to a "true" numeric sort-order, as long as we use either NO leading zeroes OR a consistent number of digit-columns when naming files/branches/tags. |
Moreover, I don't think it's right to divide the same number of digits into different groups. For example, if there are xxx-001 and xxx-002 in your example, it is more reasonable to let them next to each other in the same group .
|
For a "truly" numeric sort, these would be next to each other, EXCEPT that other representations of the very same numbers NOTE: I'm fine with the current |
Enhancement #597 added "numerical" sorting, where digit sub-string parts in sorted items are treated separately (from non-digit sub-string parts) in order to sort
2
before10
(for example, ascending).However, leading zeroes are included when doing a "trivial" number-length pre-check in the NumericSort code, which means
2
is still sorted before01
(for example, ascending).If desired, it would be (relatively) easy to correct this, by skipping any leading zeroes from the two numerical sub-strings being compared, before doing the actual number-comparison...
The text was updated successfully, but these errors were encountered: