feat: Allow comparison of XVector objects (part 1 of 2) #127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is one of two PRs intended to fix a bug identified in Biostrings here: Bioconductor/Biostrings#51. Part 2 of the PR is located here: Bioconductor/XVector#6.
The bug identified was that comparing a
DNAStringwith a single character caused aC stack too close to limiterror. It turns out that the bug ran a lot deeper--comparison betweenXVectorobjects was completely broken. For example:The culprit stems originally from the S4Vectors package.
pcompareis defined forVectorobjects, which usesorderandsameAsPreviousROWto perform element-wise comparisons. However, neither of these methods are written forSharedVectorobjects, so they default to whatever we get from dispatch.orderdispatches to the standardbase::orderfunction, which always causes a stack overflow when called on aSharedVectorobject.sameAsPreviousROWcalls the default method inS4Vector, which calls.XVector.equals, which will always returnc(FALSE, FALSE)orc(FALSE, TRUE)regardless of input size.This PR adds in the functionality required in the S4Vectors package to support comparison between
SharedVectorobjects. This is primarily just a C-level method to order an array -- this was previously in the package, but only supported integer vectors. This comparison usesmemcmpwhen possible, but a separate method is included for numeric types becausememcmphas weird behavior on doubles. Eventually will need to update the code to support the smart dispatch between sorting algorithms like in the other sorting functions, but for now this is sufficient.