Struct ZeroTriePerfectHash

struct ZeroTriePerfectHash<Store: ?Sized> { ... }

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

For more information, see ZeroTrie.

Examples

use litemap::LiteMap;
use zerotrie::ZeroTriePerfectHash;

let mut map = LiteMap::<&[u8], usize>::new_vec();
map.insert("foo".as_bytes(), 1);
map.insert("bår".as_bytes(), 2);
map.insert("båzzøø".as_bytes(), 3);

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

assert_eq!(trie.get("foo".as_bytes()), Some(1));
assert_eq!(trie.get("bår".as_bytes()), Some(2));
assert_eq!(trie.get("båzzøø".as_bytes()), Some(3));
assert_eq!(trie.get("bazzoo".as_bytes()), None);

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

Implementations

impl ZeroTriePerfectHash<[u8]>

fn from_bytes(trie: &[u8]) -> &Self

Casts from a byte slice to a reference to a trie with the same lifetime.

If the bytes are not a valid trie, unexpected behavior may occur.

impl<Store> ZeroTriePerfectHash<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():

use zerotrie::ZeroTriePerfectHash;

// A trie with two values: "abc" and "abcdef"
let trie: &ZeroTriePerfectHash<[u8]> = ZeroTriePerfectHash::from_bytes(b"abc\x80def\x81");

assert_eq!(8, trie.byte_len());
assert_eq!(2, trie.iter().count());
fn as_bytes(self: &Self) -> &[u8]

Returns the bytes contained in the underlying store.

fn as_borrowed(self: &Self) -> &ZeroTriePerfectHash<[u8]>

Returns this trie as a reference transparent over a byte slice.

fn as_borrowed_slice(self: &Self) -> ZeroTriePerfectHash<&[u8]>

Returns a trie with a store borrowing from this trie.

impl<Store> ZeroTriePerfectHash<Store>

const fn from_store(store: Store) -> Self

Create a trie directly from a store.

If the store does not contain valid bytes, unexpected behavior may occur.

fn into_store(self: Self) -> Store

Takes the byte store from this trie.

fn convert_store<X: From<Store>>(self: Self) -> ZeroTriePerfectHash<X>

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

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

Examples

use std::borrow::Cow;
use zerotrie::ZeroTriePerfectHash;

let trie: ZeroTriePerfectHash<Vec<u8>> = ZeroTriePerfectHash::from_bytes(b"abc\x85").to_owned();
let cow: ZeroTriePerfectHash<Cow<[u8]>> = trie.convert_store();

assert_eq!(cow.get(b"abc"), Some(5));

impl<Store> ZeroTriePerfectHash<Store>

const fn into_zerotrie(self: Self) -> ZeroTrie<Store>

Wrap this specific ZeroTrie variant into a ZeroTrie.

impl Borrow for ZeroTriePerfectHash<&[u8]>

fn borrow(self: &Self) -> &ZeroTriePerfectHash<[u8]>

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

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

impl<Store> AsRef for ZeroTriePerfectHash<Store>

fn as_ref(self: &Self) -> &ZeroTriePerfectHash<[u8]>

impl<Store> Freeze for ZeroTriePerfectHash<Store>

impl<Store> RefUnwindSafe for ZeroTriePerfectHash<Store>

impl<Store> Send for ZeroTriePerfectHash<Store>

impl<Store> Sync for ZeroTriePerfectHash<Store>

impl<Store> Unpin for ZeroTriePerfectHash<Store>

impl<Store> UnsafeUnpin for ZeroTriePerfectHash<Store>

impl<Store> UnwindSafe for ZeroTriePerfectHash<Store>

impl<Store: $crate::clone::Clone + ?Sized> Clone for ZeroTriePerfectHash<Store>

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

impl<Store: $crate::cmp::Eq + ?Sized> Eq for ZeroTriePerfectHash<Store>

impl<Store: $crate::cmp::PartialEq + ?Sized> PartialEq for ZeroTriePerfectHash<Store>

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

impl<Store: $crate::default::Default + ?Sized> Default for ZeroTriePerfectHash<Store>

fn default() -> ZeroTriePerfectHash<Store>

impl<Store: $crate::fmt::Debug + ?Sized> Debug for ZeroTriePerfectHash<Store>

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

impl<Store: $crate::marker::Copy + ?Sized> Copy for ZeroTriePerfectHash<Store>

impl<Store: ?Sized> StructuralPartialEq for ZeroTriePerfectHash<Store>

impl<T> Any for ZeroTriePerfectHash<Store>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ZeroTriePerfectHash<Store>

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

impl<T> BorrowMut for ZeroTriePerfectHash<Store>

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

impl<T> CloneToUninit for ZeroTriePerfectHash<Store>

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

impl<T> ErasedDestructor for ZeroTriePerfectHash<Store>

impl<T> From for ZeroTriePerfectHash<Store>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for ZeroTriePerfectHash<Store>

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

impl<T, U> Into for ZeroTriePerfectHash<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 ZeroTriePerfectHash<Store>

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

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

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