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

Fix issue when two filter "excludes" have the same string length #22

Merged
merged 1 commit into from
May 5, 2021

Conversation

DefaultRyan
Copy link
Member

@DefaultRyan DefaultRyan commented May 5, 2021

Found an issue where supplying multiple excludes with the same length caused bad behavior in Release and asserts in Debug.

Added test cases, and the second test case, "filter_excludes_same_length" was hitting an assert in debug due to a malformed sorting predicate in the filter class. In the test case, both compare({"N.N3", false}, {"N.N4", false}) and compare({"N.N4", false}, {"N.N3", false}) would return true, violating sorting constraints.

For the curious, std::sort (and the other C++ sortings I can think of) require a Strict Weak Ordering. What this means in C++ terms is, given a comparison object compare, the following requirements must be met:

  • compare(a, a) == false for all a
  • If compare(a, b) == true then compare(b, a) == false
  • If compare(a, b) == true and compare(b, c) == true then compare(a, c) == true
  • If compare(a, b) == false and compare(b, a) == false and compare(b, c) == false and compare(c, b) == false then compare(a, c) == false and compare(c, a) == false (aka transitivity of equivalence)

Fixes #21

@DefaultRyan DefaultRyan requested a review from kennykerr May 5, 2021 18:43
@DefaultRyan DefaultRyan linked an issue May 5, 2021 that may be closed by this pull request
Copy link
Contributor

@kennykerr kennykerr left a comment

Choose a reason for hiding this comment

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

Looks good to me. @Scottj1s may also want to take a peek.

Copy link

@roywill roywill left a comment

Choose a reason for hiding this comment

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

:shipit:

@Scottj1s
Copy link
Member

Scottj1s commented May 5, 2021

Thanks Ryan, and for adding test cases

@DefaultRyan DefaultRyan merged commit 866c5f4 into master May 5, 2021
@DefaultRyan DefaultRyan deleted the defaultryan/filter branch May 5, 2021 20:47
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.

reader::filter can't handle two excludes of the same length
4 participants