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

Sorted Indices errors on large lists containing both numbers and strings #5328

Open
1 task done
sovdeeth opened this issue Jan 6, 2023 · 0 comments
Open
1 task done
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. priority: low Issues that are not harmful to the experience but are related to useful changes or additions. up for debate When the decision is yet to be debated on the issue in question

Comments

@sovdeeth
Copy link
Member

sovdeeth commented Jan 6, 2023

Skript/Server Version

[01:24:23 INFO]: [Skript] Skript's aliases can be found here: https://github.com/SkriptLang/skript-aliases
[01:24:23 INFO]: [Skript] Skript's documentation can be found here: https://docs.skriptlang.org/
[01:24:23 INFO]: [Skript] Skript's tutorials can be found here: https://docs.skriptlang.org/tutorials
[01:24:23 INFO]: [Skript] Server Version: git-Paper-125 (MC: 1.19.2)
[01:24:23 INFO]: [Skript] Skript Version: 2.6.4
[01:24:23 INFO]: [Skript] Installed Skript Addons:
[01:24:23 INFO]: [Skript]  - skript-worldguard v1.0-alpha1 (https://github.com/SkriptLang/skript-worldguard)
[01:24:23 INFO]: [Skript] Installed dependencies:
[01:24:23 INFO]: [Skript]  - WorldGuard v7.0.8-beta-01+cbb2ba7

Bug Description

When using sorted indices on large lists with both numbers and strings (roughly larger than 1000 or so elements) TimSort errors, complaining the comparator violated its general contract. This does not occur with smaller lists (eg: 100 elements) as I believe Stream#sorted doesn't use TimSort for shorter lists.
I added a String, Number comparator and that fixed the issue, but I don't know if that's a good solution or not. Perhaps just catching the exception and returning the unsorted list is better. Up for debate.

Expected Behavior

It should either sort properly and return the sorted indices, or not sort at all and return the original list.

Steps to Reproduce

command /sort:
    trigger:
        clear {a::*}
        loop 10000 times:
            set {a::%random uuid%} to random number between 0 and 100
        set {a::abc} to "hi"
        send sorted indices of {a::*} in descending order to player

Errors or Screenshots

https://gist.github.com/sovdeeth/382e65dc312991bfae2f32def6e5cc42

Hacky comparator for String, Number that did work as a solution:

                // String - Number
		Comparators.registerComparator(String.class, Number.class, new Comparator<String, Number>() {
			@Override
			public Relation compare(String s1, Number n2) {
				return Relation.get(s1.compareTo(n2.toString()));
			}

			@Override
			public boolean supportsOrdering() {
				return true;
			}
		});

Other

No response

Agreement

  • I have read the guidelines above and affirm I am following them with this report.
@AyhamAl-Ali AyhamAl-Ali added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. priority: low Issues that are not harmful to the experience but are related to useful changes or additions. up for debate When the decision is yet to be debated on the issue in question labels Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. priority: low Issues that are not harmful to the experience but are related to useful changes or additions. up for debate When the decision is yet to be debated on the issue in question
Projects
None yet
Development

No branches or pull requests

2 participants