Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
abbiecnt committed Aug 27, 2024
1 parent 1a56383 commit 7974085
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Inka

# Platforms
| **OS** | **x64** |
|:-------:|:-------:|
| Windows | Yes |
| Linux | Planned |

# Contributing
See [`CONTRIBUTING.md`][CONTRIBUTING] for contributing to the project.

Expand Down
16 changes: 15 additions & 1 deletion src/section.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::Base;
use core::ptr::NonNull;
use core::slice::from_raw_parts;
use core::slice::{from_raw_parts, SliceIndex};
use std::ops::Index;
use rayon::iter::IndexedParallelIterator;
use rayon::slice::ParallelSlice;

Expand Down Expand Up @@ -37,6 +38,10 @@ impl Section {
unsafe { from_raw_parts(self.base.as_ptr(), self.len) }
}

pub fn contains(&self, pattern: &[u8]) -> bool {
self.find(pattern).is_some()
}

pub fn find(&self, pattern: &[u8]) -> Option<NonNull<u8>> {
self.as_slice()
.par_windows(pattern.len())
Expand All @@ -55,3 +60,12 @@ impl Section {
Self { name, base, len }
}
}

impl<I: SliceIndex<[u8]>> Index<I> for Section {
type Output = I::Output;

#[inline]
fn index(&self, index: I) -> &Self::Output {
self.as_slice().index(index)
}
}

0 comments on commit 7974085

Please sign in to comment.