pub struct ZeroTrie<Store>(/* private fields */);Expand description
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:
ZeroTrieSimpleAsciiis the most compact structure. Very fast for small data. Only stores ASCII-encoded strings. Can be const-constructed!ZeroTriePerfectHashis also compact, but it also supports arbitrary binary strings. It also scales better to large data. Cannot be const-constructed.ZeroTrieExtendedCapacitycan be used if more than 2^32 bytes are required.
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:
ZeroTrie<[u8]>(dynamically sized type: must be stored in a reference or Box)ZeroTrie<&[u8]>(borrows its data from a u8 buffer)ZeroTrie<Vec<u8>>(fully owned data)ZeroTrie<ZeroVec<u8>>(the recommended borrowed-or-owned signature)Cow<ZeroTrie<[u8]>>(another borrowed-or-owned signature)ZeroTrie<Cow<[u8]>>(another borrowed-or-owned signature)
§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);
Implementations§
Source§impl<Store> ZeroTrie<Store>
impl<Store> ZeroTrie<Store>
Sourcepub fn into_store(self) -> Store
pub fn into_store(self) -> Store
Takes the byte store from this trie.
Sourcepub fn convert_store<NewStore>(self) -> ZeroTrie<NewStore>where
NewStore: From<Store>,
pub fn convert_store<NewStore>(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]>>.
Trait Implementations§
Source§impl<'a, Store> Yokeable<'a> for ZeroTrie<Store>where
Store: 'static,
Self: Sized,
impl<'a, Store> Yokeable<'a> for ZeroTrie<Store>where
Store: 'static,
Self: Sized,
Source§type Output = ZeroTrie<Store>
type Output = ZeroTrie<Store>
This type MUST be
Self with the 'static replaced with 'a, i.e. Self<'a>Source§fn transform_owned(self) -> Self::Output
fn transform_owned(self) -> Self::Output
Source§impl<'zf, Store1, Store2> ZeroFrom<'zf, ZeroTrie<Store1>> for ZeroTrie<Store2>where
Store2: ZeroFrom<'zf, Store1>,
Available on crate feature zerofrom only.
impl<'zf, Store1, Store2> ZeroFrom<'zf, ZeroTrie<Store1>> for ZeroTrie<Store2>where
Store2: ZeroFrom<'zf, Store1>,
Available on crate feature
zerofrom only.impl<Store: Copy> Copy for ZeroTrie<Store>
impl<Store: Eq> Eq for ZeroTrie<Store>
impl<Store> StructuralPartialEq for ZeroTrie<Store>
Auto Trait Implementations§
impl<Store> Freeze for ZeroTrie<Store>where
Store: Freeze,
impl<Store> RefUnwindSafe for ZeroTrie<Store>where
Store: RefUnwindSafe,
impl<Store> Send for ZeroTrie<Store>where
Store: Send,
impl<Store> Sync for ZeroTrie<Store>where
Store: Sync,
impl<Store> Unpin for ZeroTrie<Store>where
Store: Unpin,
impl<Store> UnwindSafe for ZeroTrie<Store>where
Store: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more