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

Sorts column data using fastutil .sort methods #778

Merged
merged 2 commits into from
Mar 10, 2020

Conversation

emilianbold
Copy link
Contributor

Thanks for contributing.

Description

Sorts the fastutil collections using the proper sort method and avoids accessing the backing array via .elements() since it will generally have invalid data or zeros in there.

Closes issue #775

Testing

Two tests, and everything existing still runs which is promising.

@@ -30,6 +29,14 @@ public void unique() {
assertArrayEquals(arr, new double[] {1.0, 2.0, 3.0, 4.0, 5.0});
}

@Test
public void createThenSortAscending() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is this different than the existing sortAscending test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you create an empty column like DoubleColumn.create("test") it actually creates a DEFAULT_ARRAY_SIZE array which has zeros. It showcases the bug nicely.

@@ -297,12 +296,12 @@ public BooleanColumn copy() {

@Override
public void sortAscending() {
ByteArrays.mergeSort(data.elements());
data.sort(descendingByteComparator.reversed() /* or ByteComparators.NATURAL_COMPARATOR */);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is kind of a double negative. I'd prefer the ByteComparators.NATURAL_COMPARATOR option rather than reversing a reverse comparator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'd use the natural comparators all over the place. But incrementally it made sense in a way to use whatever comparator you had there (just in case there was some specific logic -- I didn't really check them all).

I will update the PR to use those comparators.

}

@Override
public void sortDescending() {
ByteArrays.mergeSort(data.elements(), descendingByteComparator);
data.sort(descendingByteComparator);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps we should remove descendingByteComparator and use ByteComparators.OPPOSITE_COMPARATOR here for consistency if we change sortAscending

@emilianbold
Copy link
Contributor Author

See the updated PR.

@benmccann
Copy link
Collaborator

Thanks for the fix!

@benmccann benmccann merged commit 0db7d75 into jtablesaw:master Mar 10, 2020
@emilianbold emilianbold deleted the sortascending branch March 10, 2020 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants