Fastrie

Struct Fastrie 

Source
pub struct Fastrie<'v, 'd, V> { /* private fields */ }

Implementations§

Source§

impl<V> Fastrie<'_, '_, V>

Source

pub const fn from_prebuilt<'v, 'd>( index_width: IndexWidth, values: &'v [V], data: &'d [u8], ) -> Fastrie<'v, 'd, V>

§Example
use fastrie::*;

let mut builder = FastrieBuilderNode::new(IndexWidth(3));
builder.add(b"hell", 1);
builder.add(b"hello", 2);
builder.add(b"world", 4);
let build = builder.prebuild();

// `build.data` can be written as bytes to a file, or embedded directly into code as a literal byte array/slice.

let trie = Fastrie::from_prebuilt(build.index_width, &build.values, &build.data);
assert!(trie.contains_key(b"hello"));
let query = b"hello world!";
let mat = trie.longest_matching_prefix(query).unwrap();
assert_eq!(mat.end, 4);
assert_eq!(&query[..=mat.end], b"hello");
assert_eq!(mat.value, &2);
let query = b"hell's kitchen";
let mat = trie.longest_matching_prefix(query).unwrap();
assert_eq!(mat.end, 3);
assert_eq!(&query[..=mat.end], b"hell");
assert_eq!(mat.value, &1);
Source

pub fn memory_size(&self) -> usize

Source

pub fn contains_key(&self, key: &[u8]) -> bool

Source

pub fn longest_matching_prefix( &self, text: &[u8], ) -> Option<FastrieMatch<'_, V>>

Auto Trait Implementations§

§

impl<'v, 'd, V> Freeze for Fastrie<'v, 'd, V>

§

impl<'v, 'd, V> RefUnwindSafe for Fastrie<'v, 'd, V>
where V: RefUnwindSafe,

§

impl<'v, 'd, V> Send for Fastrie<'v, 'd, V>
where V: Sync,

§

impl<'v, 'd, V> Sync for Fastrie<'v, 'd, V>
where V: Sync,

§

impl<'v, 'd, V> Unpin for Fastrie<'v, 'd, V>

§

impl<'v, 'd, V> UnwindSafe for Fastrie<'v, 'd, V>
where V: 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.