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

[BUG] IntQuickSort.sort may behave incorrectly if left > 0 #1111

Open
niemisto opened this issue Nov 6, 2024 · 2 comments
Open

[BUG] IntQuickSort.sort may behave incorrectly if left > 0 #1111

niemisto opened this issue Nov 6, 2024 · 2 comments
Labels

Comments

@niemisto
Copy link

niemisto commented Nov 6, 2024

Describe the bug
IntQuickSort.sort might move some elements from the range [left,right] to the range [0,left-1] during insertion sort. This results both undesired modification in range [0,left-1] and range [left,right] not being in order after the method returns.

To Reproduce

int[] array = new int[] { 4, 2, 3, 1  };
IntQuickSort.sort(array, 1, array.length-1, Integer::compare);
System.out.println(Arrays.toString(array));

This prints [1, 4, 2, 3] instead of expected [4, 1, 2, 3].

Possible solution
The bug seems to be the following line in IntQuickSort.insertionSort:

                while (i > -1 && comparator.compare(key, array[i]) < 0);

Instead of i > -1 the comparison should be i >= left.

Environment:

  • Choco-solver version: 4.10.17
@niemisto niemisto added the bug label Nov 6, 2024
@cprudhom
Copy link
Member

cprudhom commented Nov 6, 2024

Can you give the full path of the class IntQuickSort?

@niemisto
Copy link
Author

niemisto commented Nov 6, 2024

My mistake. Reported this to a wrong project. The bug was in eclipse-collections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants