-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add ByteRanges #26
Add ByteRanges #26
Conversation
Some unnamed jerk just merged some code that causes conflicts here ;-) |
//! | ||
//! fn main() { | ||
//! let raw_data = [0x00, 0x01, 0x10, 0xFF, 0x42]; | ||
//! // Search for the first byte that's either 0x70...0x7F, 0xFD, 0xFE, or 0xFF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say the nomenclature should be the same here:
0x70...0x7F, or 0xFD...0xFF
I then wonder if it should be Rust-standard:
0x70..=0x7F, or 0xFD..=0xFF
I then wonder if we can use an actual RangeInclusive
instead of a tuple
T: PartialOrd, | ||
{ | ||
fn find_any_in_ranges(&self, ranges: &[(T, T)]) -> Option<usize> { | ||
self.iter().position(|c| ranges.iter().position(|r| r.0 <= *c && *c <= r.1).is_some()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut ranges: [(u8, u8); 8] = pairs; | ||
for (ref lo, hi) in ranges.iter_mut() { | ||
let extra = *hi; | ||
*hi = if extra > 255_u8 - lo { 255_u8 } else { lo + extra }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be clearer as either of these pseudocode:
-
let mut x = [a, b]; x.sort(); let [a, b] = x;
-
any::<u8>.prop_map(|a| (a, range(a, u8::max)))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or if a > b { mem::swap(a, b) }
What is required for this PR to move forward? I could really use range search for some ASCII character class checks. |
I think it would be acceptable for you to grab this PR, make the changes, and then submit a new PR... |
I played with this PR as-is - it works, but found out that SIMD version it actually quite slower than regular comparisons, so now I'm not even sure if it's worth it :/ |
This adds support for finding bytes in a set of ranges of bytes.
I hereby license this contribution under the dual MIT/Apache-2.0 license, allowing licensees to choose either at their option.