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

New sorting is still strange #16

Open
rlwhitcomb opened this issue Nov 7, 2022 · 7 comments
Open

New sorting is still strange #16

rlwhitcomb opened this issue Nov 7, 2022 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@rlwhitcomb
Copy link
Contributor

Even with "natorder-1.1.3.jar":

> s = [ "$", "#", "1", "0", "2" ]
s = ["$", "#", "1", "0", "2"] -> [ "$", "#", "1", "0", "2" ]
> sort s
sort s -> [ "0", "#", "$", "1", "2" ]

I would expect [ "#", "$", "0", "1", "2" ] instead

@rlwhitcomb
Copy link
Contributor Author

This is tracking issue rlwhitcomb/utilities#547.

@616slayer616
Copy link
Owner

I had a look and the problem is that "0" is kind of special since it there can be leading zeroes.

The method isSpaceOrSeparatorOrEmpty could be adjusted like this:
return isSpaceOrSeparator(c) || c == '0' || c == '#' || c == '$';
To get it to work. But I don't know what other implications there could be and you would basically have to add all special characters.

The example with the one character strings is very basic and this library is not intended for this purpose.
It makes zero sense to compare single characters with this.

Do you have longer examples which illustrate this issue?
I could test those in this branch: https://github.com/616slayer616/natorder/tree/issue%2316

@616slayer616 616slayer616 added the bug Something isn't working label Nov 11, 2022
@616slayer616 616slayer616 self-assigned this Nov 11, 2022
@rlwhitcomb
Copy link
Contributor Author

The original reason this came up was in my Calculator language I define special variables for function parameters (for the case of variable number of arguments) named "$#" (for total number of args), "$*" (for the array of arguments), plus "$0", "$1, "$2", etc. for each individual argument. I was trying to sort them and saw the strange order, so basically any prefix to these "#", "*" would cause it. I don't know how common this type of naming would be, but ...

> a = [ '$*', '$#', '$0', '$1', '$2', '$10' ]
a = ['$*', '$#', '$0', '$1', '$2', '$10'] -> [ "$*", "$#", "$0", "$1", "$2", "$10" ]
> sort a
sort a -> [ "$0", "$#", "$*", "$1", "$2", "$10" ]
> a = [ "abc0", "abc#", "abc*", "abc1", "abc2", "abc10", "abc20" ]
a = ["abc0", "abc#", "abc*", "abc1", "abc2", "abc10", "abc20"] -> [ "abc0", "abc#", "abc*", "abc1", "abc2", "abc10", "abc20" ]
> sort a
sort a -> [ "abc0", "abc#", "abc*", "abc1", "abc2", "abc10", "abc20" ]

My thought to fix it was to basically sort symbols in their ASCII order compared to numbers, so the test you mentioned could just be `... || c < '0' (Note: I haven't tried that yet to be sure).

@rlwhitcomb
Copy link
Contributor Author

Further testing just now shows this weirdness too:

a = ["abc0def", "abc#def", "abc*def", "abc1def", "abc2def", "abc10def", "abc20def"] -> [ "abc0def", "abc#def", "abc*def", "abc1def", "abc2def", "abc10def", "abc20def" ]
> sort a
sort a -> [ "abc#def", "abc*def", "abc1def", "abc2def", "abc10def", "abc20def", "abc0def" ]

where the "0" gets put to the end ...

@616slayer616
Copy link
Owner

I can't get it to work for everything.
I can do minuscule changes to the method to achieve your desired results but then other tests will fail.
Could introducing "flaovrs" be a solution here?
master...issue#16
"SPECIAL" worked for your first examples and "ZERO" works for your "zero in the middle of a string" example.
If you like it maybe you have better naming ideas

@rlwhitcomb
Copy link
Contributor Author

That solution sounds like probably the only way to get it to "work", but I'm afraid for my use case it probably won't fly, because in order to set the "right" sort flavor I'd have to analyze the data beforehand, which isn't feasible.... Unfortunately.

@krasa
Copy link

krasa commented Nov 25, 2022

It seems similar to this: paour/natorder#14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants