Trait stringzilla::StringZilla

source ·
pub trait StringZilla<N>
where N: AsRef<[u8]>,
{ // Required methods fn sz_find(&self, needle: N) -> Option<usize>; fn sz_rfind(&self, needle: N) -> Option<usize>; fn sz_find_char_from(&self, needles: N) -> Option<usize>; fn sz_rfind_char_from(&self, needles: N) -> Option<usize>; fn sz_find_char_not_from(&self, needles: N) -> Option<usize>; fn sz_rfind_char_not_from(&self, needles: N) -> Option<usize>; fn sz_edit_distance(&self, other: N) -> usize; fn sz_alignment_score( &self, other: N, matrix: [[i8; 256]; 256], gap: i8 ) -> isize; }
Expand description

Provides extensions for string searching and manipulation functionalities on types that can reference byte slices (u8). This trait extends the capability of any type implementing AsRef<[u8]>, allowing easy integration of SIMD-accelerated string processing functions.

§Examples

Basic usage on a Vec<u8>:

use stringzilla::StringZilla;

let haystack: &[u8] = &[b'a', b'b', b'c', b'd', b'e'];
let needle: &[u8] = &[b'c', b'd'];

assert_eq!(haystack.sz_find(needle.as_ref()), Some(2));

Searching in a string slice:

use stringzilla::StringZilla;

let haystack = "abcdef";
let needle = "cd";

assert_eq!(haystack.sz_find(needle.as_bytes()), Some(2));

Required Methods§

source

fn sz_find(&self, needle: N) -> Option<usize>

Searches for the first occurrence of needle in self.

§Examples
use stringzilla::StringZilla;

let haystack = "Hello, world!";
assert_eq!(haystack.sz_find("world".as_bytes()), Some(7));
source

fn sz_rfind(&self, needle: N) -> Option<usize>

Searches for the last occurrence of needle in self.

§Examples
use stringzilla::StringZilla;

let haystack = "Hello, world, world!";
assert_eq!(haystack.sz_rfind("world".as_bytes()), Some(14));
source

fn sz_find_char_from(&self, needles: N) -> Option<usize>

Finds the index of the first character in self that is also present in needles.

§Examples
use stringzilla::StringZilla;

let haystack = "Hello, world!";
assert_eq!(haystack.sz_find_char_from("aeiou".as_bytes()), Some(1));
source

fn sz_rfind_char_from(&self, needles: N) -> Option<usize>

Finds the index of the last character in self that is also present in needles.

§Examples
use stringzilla::StringZilla;

let haystack = "Hello, world!";
assert_eq!(haystack.sz_rfind_char_from("aeiou".as_bytes()), Some(8));
source

fn sz_find_char_not_from(&self, needles: N) -> Option<usize>

Finds the index of the first character in self that is not present in needles.

§Examples
use stringzilla::StringZilla;

let haystack = "Hello, world!";
assert_eq!(haystack.sz_find_char_not_from("aeiou".as_bytes()), Some(0));
source

fn sz_rfind_char_not_from(&self, needles: N) -> Option<usize>

Finds the index of the last character in self that is not present in needles.

§Examples
use stringzilla::StringZilla;

let haystack = "Hello, world!";
assert_eq!(haystack.sz_rfind_char_not_from("aeiou".as_bytes()), Some(12));
source

fn sz_edit_distance(&self, other: N) -> usize

Computes the Levenshtein edit distance between self and other.

§Examples
use stringzilla::StringZilla;

let first = "kitten";
let second = "sitting";
assert_eq!(first.sz_edit_distance(second.as_bytes()), 3);
source

fn sz_alignment_score( &self, other: N, matrix: [[i8; 256]; 256], gap: i8 ) -> isize

Computes the alignment score between self and other using the specified substitution matrix and gap penalty.

§Examples
use stringzilla::{sz, StringZilla};

let first = "kitten";
let second = "sitting";
let matrix = sz::unary_substitution_costs();
let gap_penalty = -1;
assert_eq!(first.sz_alignment_score(second.as_bytes(), matrix, gap_penalty), -3);

Implementors§

source§

impl<T, N> StringZilla<N> for T
where T: AsRef<[u8]>, N: AsRef<[u8]>,