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

Add ByteRanges #26

Closed
wants to merge 1 commit into from
Closed

Add ByteRanges #26

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 24, 2018

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.

@shepmaster
Copy link
Owner

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
Copy link
Owner

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())
Copy link
Owner

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 };
Copy link
Owner

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:

  1.  let mut x = [a, b];
     x.sort();
     let [a, b] = x;
  2. any::<u8>.prop_map(|a| (a, range(a, u8::max)))

Copy link
Owner

@shepmaster shepmaster Aug 24, 2018

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) }

@RReverser
Copy link
Contributor

What is required for this PR to move forward? I could really use range search for some ASCII character class checks.

@shepmaster
Copy link
Owner

I think it would be acceptable for you to grab this PR, make the changes, and then submit a new PR...

@RReverser
Copy link
Contributor

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 :/

@shepmaster shepmaster deleted the branch shepmaster:master September 18, 2021 13:39
@shepmaster shepmaster closed this Sep 18, 2021
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.

3 participants