Struct trie_rs::inc_search::IncSearch

source ·
pub struct IncSearch<'a, Label, Value> { /* private fields */ }
Expand description

An incremental search of the trie.

Implementations§

source§

impl<'a, Label: Ord, Value> IncSearch<'a, Label, Value>

source

pub fn new(trie: &'a Trie<Label, Value>) -> Self

Create a new incremental search for a trie.

source

pub fn resume(trie: &'a Trie<Label, Value>, position: Position) -> Self

Resume an incremental search at a particular point.

use trie_rs::{Trie, inc_search::{Answer, IncSearch}};
use louds_rs::LoudsNodeNum;

let trie: Trie<u8> = ["hello", "bye"].into_iter().collect();
let mut inc_search = trie.inc_search();

assert_eq!(inc_search.query_until("he"), Ok(Answer::Prefix));
let position = LoudsNodeNum::from(inc_search);

// inc_search is dropped.
let mut inc_search2 = IncSearch::resume(&trie.0, position);
assert_eq!(inc_search2.query_until("llo"), Ok(Answer::Match));
source

pub fn peek(&self, chr: &Label) -> Option<Answer>

Query but do not change the node we’re looking at on the trie.

source

pub fn query(&mut self, chr: &Label) -> Option<Answer>

Query the trie and go to node if there is a match.

source

pub fn query_until( &mut self, query: impl AsRef<[Label]> ) -> Result<Answer, usize>

Query the trie with a sequence. Will return Err(index of query) on first failure to match.

source

pub fn value(&self) -> Option<&'a Value>

Return the value at current node. There should be one for any node where answer.is_match() is true.

source

pub fn goto_longest_prefix(&mut self) -> Result<usize, usize>

Go to the longest shared prefix.

source

pub fn prefix<C, M>(&self) -> C
where C: TryFromIterator<Label, M>, Label: Clone,

Return the current prefix for this search.

source

pub fn prefix_len(&self) -> usize

Returne the length of the current prefix for this search.

source

pub fn reset(&mut self)

Reset the query.

Trait Implementations§

source§

impl<'a, Label: Clone, Value: Clone> Clone for IncSearch<'a, Label, Value>

source§

fn clone(&self) -> IncSearch<'a, Label, Value>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a, Label: Debug, Value: Debug> Debug for IncSearch<'a, Label, Value>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, L, V> From<IncSearch<'a, L, V>> for Position

Retrieve the position the search is on. Useful for hanging on to a search without having to fight the borrow checker because its borrowing a trie.

source§

fn from(inc_search: IncSearch<'a, L, V>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a, Label, Value> Freeze for IncSearch<'a, Label, Value>

§

impl<'a, Label, Value> RefUnwindSafe for IncSearch<'a, Label, Value>
where Label: RefUnwindSafe, Value: RefUnwindSafe,

§

impl<'a, Label, Value> Send for IncSearch<'a, Label, Value>
where Label: Sync, Value: Sync,

§

impl<'a, Label, Value> Sync for IncSearch<'a, Label, Value>
where Label: Sync, Value: Sync,

§

impl<'a, Label, Value> Unpin for IncSearch<'a, Label, Value>

§

impl<'a, Label, Value> UnwindSafe for IncSearch<'a, Label, Value>
where Label: RefUnwindSafe, Value: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.