Struct ZeroTrie

struct ZeroTrie<Store>(_)

A data structure that compactly maps from byte sequences to integers.

There are several variants of ZeroTrie which are very similar but are optimized for different use cases:

You can create a ZeroTrie directly, in which case the most appropriate backing implementation will be chosen.

Backing Store

The data structure has a flexible backing data store. The only requirement for most functionality is that it implement AsRef<[u8]>. All of the following are valid ZeroTrie types:

Examples

use litemap::LiteMap;
use zerotrie::ZeroTrie;

let mut map = LiteMap::<&[u8], usize>::new_vec();
map.insert("foo".as_bytes(), 1);
map.insert("bar".as_bytes(), 2);
map.insert("bazzoo".as_bytes(), 3);

let trie = ZeroTrie::try_from(&map)?;

assert_eq!(trie.get("foo"), Some(1));
assert_eq!(trie.get("bar"), Some(2));
assert_eq!(trie.get("bazzoo"), Some(3));
assert_eq!(trie.get("unknown"), None);

# Ok::<_, zerotrie::ZeroTrieBuildError>(())

Implementations

impl<Store> ZeroTrie<Store>

fn get<K>(self: &Self, key: K) -> Option<usize>
where
    K: AsRef<[u8]>

Queries the trie for a string.

fn is_empty(self: &Self) -> bool

Returns true if the trie is empty.

fn byte_len(self: &Self) -> usize

Returns the size of the trie in number of bytes.

To get the number of keys in the trie, use .iter().count().

impl<Store> ZeroTrie<Store>

fn into_store(self: Self) -> Store

Takes the byte store from this trie.

fn convert_store<NewStore>(self: Self) -> ZeroTrie<NewStore>
where
    NewStore: From<Store>

Converts this trie's store to a different store implementing the From trait.

For example, use this to change ZeroTrie<Vec<u8>> to ZeroTrie<Cow<[u8]>>.

impl<'a, Store> Yokeable for ZeroTrie<Store>

fn transform(self: &Self) -> &<Self as >::Output
fn transform_owned(self: Self) -> <Self as >::Output
unsafe fn make(this: <Self as >::Output) -> Self
fn transform_mut<F>(self: &'a mut Self, f: F)
where
    F: 'static + for<'b> FnOnce(&'b mut <Self as >::Output)

impl<'zf, Store1, Store2> ZeroFrom for ZeroTrie<Store2>

fn zero_from(other: &'zf ZeroTrie<Store1>) -> Self

impl<Store> Freeze for ZeroTrie<Store>

impl<Store> RefUnwindSafe for ZeroTrie<Store>

impl<Store> Send for ZeroTrie<Store>

impl<Store> StructuralPartialEq for ZeroTrie<Store>

impl<Store> Sync for ZeroTrie<Store>

impl<Store> Unpin for ZeroTrie<Store>

impl<Store> UnsafeUnpin for ZeroTrie<Store>

impl<Store> UnwindSafe for ZeroTrie<Store>

impl<Store: $crate::clone::Clone> Clone for ZeroTrie<Store>

fn clone(self: &Self) -> ZeroTrie<Store>

impl<Store: $crate::cmp::Eq> Eq for ZeroTrie<Store>

impl<Store: $crate::cmp::PartialEq> PartialEq for ZeroTrie<Store>

fn eq(self: &Self, other: &ZeroTrie<Store>) -> bool

impl<Store: $crate::fmt::Debug> Debug for ZeroTrie<Store>

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

impl<Store: $crate::marker::Copy> Copy for ZeroTrie<Store>

impl<T> Any for ZeroTrie<Store>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ZeroTrie<Store>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for ZeroTrie<Store>

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

impl<T> CloneToUninit for ZeroTrie<Store>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> ErasedDestructor for ZeroTrie<Store>

impl<T> From for ZeroTrie<Store>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for ZeroTrie<Store>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for ZeroTrie<Store>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for ZeroTrie<Store>

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

impl<T, U> TryInto for ZeroTrie<Store>

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