pub struct CharwiseDoubleArrayAhoCorasickBuilder { /* private fields */ }
Expand description
Builder for CharwiseDoubleArrayAhoCorasick
.
Implementations
sourceimpl CharwiseDoubleArrayAhoCorasickBuilder
impl CharwiseDoubleArrayAhoCorasickBuilder
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new CharwiseDoubleArrayAhoCorasickBuilder
.
Examples
use daachorse::CharwiseDoubleArrayAhoCorasickBuilder;
let patterns = vec!["全世界", "世界", "に"];
let builder = CharwiseDoubleArrayAhoCorasickBuilder::new();
let pma = builder.build(patterns).unwrap();
let mut it = pma.find_iter("全世界中に");
let m = it.next().unwrap();
assert_eq!((0, 9, 0), (m.start(), m.end(), m.value()));
let m = it.next().unwrap();
assert_eq!((12, 15, 2), (m.start(), m.end(), m.value()));
assert_eq!(None, it.next());
sourcepub const fn match_kind(self, kind: MatchKind) -> Self
pub const fn match_kind(self, kind: MatchKind) -> Self
sourcepub const fn num_free_blocks(self, n: u32) -> Self
pub const fn num_free_blocks(self, n: u32) -> Self
sourcepub fn build<I, P, V>(
self,
patterns: I
) -> Result<CharwiseDoubleArrayAhoCorasick<V>> where
I: IntoIterator<Item = P>,
P: AsRef<str>,
V: Copy + TryFrom<usize>,
pub fn build<I, P, V>(
self,
patterns: I
) -> Result<CharwiseDoubleArrayAhoCorasick<V>> where
I: IntoIterator<Item = P>,
P: AsRef<str>,
V: Copy + TryFrom<usize>,
Builds and returns a new CharwiseDoubleArrayAhoCorasick
from input patterns. The value
i
is automatically associated with patterns[i]
.
Arguments
patterns
- List of patterns.
Errors
DaachorseError
is returned when
patterns
is empty,patterns
contains entries of length zero,patterns
contains duplicate entries,- the conversion from the index
i
to the specified typeV
fails, - the scale of
patterns
exceeds the expected one, or - the scale of the resulting automaton exceeds the expected one.
Examples
use daachorse::CharwiseDoubleArrayAhoCorasickBuilder;
let patterns = vec!["全世界", "世界", "に"];
let pma = CharwiseDoubleArrayAhoCorasickBuilder::new()
.build(patterns)
.unwrap();
let mut it = pma.find_iter("全世界中に");
let m = it.next().unwrap();
assert_eq!((0, 9, 0), (m.start(), m.end(), m.value()));
let m = it.next().unwrap();
assert_eq!((12, 15, 2), (m.start(), m.end(), m.value()));
assert_eq!(None, it.next());
sourcepub fn build_with_values<I, P, V>(
self,
patvals: I
) -> Result<CharwiseDoubleArrayAhoCorasick<V>> where
I: IntoIterator<Item = (P, V)>,
P: AsRef<str>,
V: Copy,
pub fn build_with_values<I, P, V>(
self,
patvals: I
) -> Result<CharwiseDoubleArrayAhoCorasick<V>> where
I: IntoIterator<Item = (P, V)>,
P: AsRef<str>,
V: Copy,
Builds and returns a new CharwiseDoubleArrayAhoCorasick
from input pattern-value pairs.
Arguments
patvals
- List of pattern-value pairs.
Errors
DaachorseError
is returned when
patvals
is empty,patvals
contains patterns of length zero,patvals
contains duplicate patterns,- the scale of
patvals
exceeds the expected one, or - the scale of the resulting automaton exceeds the expected one.
Examples
use daachorse::CharwiseDoubleArrayAhoCorasickBuilder;
let patvals = vec![("全世界", 0), ("世界", 10), ("に", 100)];
let pma = CharwiseDoubleArrayAhoCorasickBuilder::new()
.build_with_values(patvals)
.unwrap();
let mut it = pma.find_iter("全世界中に");
let m = it.next().unwrap();
assert_eq!((0, 9, 0), (m.start(), m.end(), m.value()));
let m = it.next().unwrap();
assert_eq!((12, 15, 100), (m.start(), m.end(), m.value()));
assert_eq!(None, it.next());
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for CharwiseDoubleArrayAhoCorasickBuilder
impl Send for CharwiseDoubleArrayAhoCorasickBuilder
impl Sync for CharwiseDoubleArrayAhoCorasickBuilder
impl Unpin for CharwiseDoubleArrayAhoCorasickBuilder
impl UnwindSafe for CharwiseDoubleArrayAhoCorasickBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more