#[repr(transparent)]pub struct ZeroTrieExtendedCapacity<Store: ?Sized> { /* private fields */ }
Expand description
A data structure that maps from a large number of byte strings to integers.
For more information, see ZeroTrie
.
Implementations§
Source§impl<Store> ZeroTrieExtendedCapacity<Store>
impl<Store> ZeroTrieExtendedCapacity<Store>
Sourcepub const fn into_zerotrie(self) -> ZeroTrie<Store>
pub const fn into_zerotrie(self) -> ZeroTrie<Store>
Wrap this specific ZeroTrie variant into a ZeroTrie.
Source§impl<Store> ZeroTrieExtendedCapacity<Store>
impl<Store> ZeroTrieExtendedCapacity<Store>
Sourcepub const fn from_store(store: Store) -> Self
pub 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.
Sourcepub fn take_store(self) -> Store
pub fn take_store(self) -> Store
Takes the byte store from this trie.
Sourcepub fn convert_store<X: From<Store>>(self) -> ZeroTrieExtendedCapacity<X>
pub fn convert_store<X: From<Store>>(self) -> ZeroTrieExtendedCapacity<X>
Converts this trie’s store to a different store implementing the From
trait.
For example, use this to change ZeroTrieExtendedCapacity<Vec<u8>>
to ZeroTrieExtendedCapacity<Cow<[u8]>>
.
§Examples
use std::borrow::Cow;
use zerotrie::ZeroTrieExtendedCapacity;
let trie: ZeroTrieExtendedCapacity<Vec<u8>> = ZeroTrieExtendedCapacity::from_bytes(b"abc\x85").to_owned();
let cow: ZeroTrieExtendedCapacity<Cow<[u8]>> = trie.convert_store();
assert_eq!(cow.get(b"abc"), Some(5));
Source§impl<Store> ZeroTrieExtendedCapacity<Store>
impl<Store> ZeroTrieExtendedCapacity<Store>
Sourcepub fn byte_len(&self) -> usize
pub fn byte_len(&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::ZeroTrieExtendedCapacity;
// A trie with two values: "abc" and "abcdef"
let trie: &ZeroTrieExtendedCapacity<[u8]> = ZeroTrieExtendedCapacity::from_bytes(b"abc\x80def\x81");
assert_eq!(8, trie.byte_len());
assert_eq!(2, trie.iter().count());
Sourcepub fn as_borrowed(&self) -> &ZeroTrieExtendedCapacity<[u8]>
pub fn as_borrowed(&self) -> &ZeroTrieExtendedCapacity<[u8]>
Returns this trie as a reference transparent over a byte slice.
Sourcepub fn as_borrowed_slice(&self) -> ZeroTrieExtendedCapacity<&[u8]>
pub fn as_borrowed_slice(&self) -> ZeroTrieExtendedCapacity<&[u8]>
Returns a trie with a store borrowing from this trie.
Source§impl<Store> ZeroTrieExtendedCapacity<Store>
impl<Store> ZeroTrieExtendedCapacity<Store>
Sourcepub fn to_owned(&self) -> ZeroTrieExtendedCapacity<Vec<u8>>
pub fn to_owned(&self) -> ZeroTrieExtendedCapacity<Vec<u8>>
Converts a possibly-borrowed $name to an owned one.
✨ Enabled with the alloc
Cargo feature.
§Examples
use zerotrie::ZeroTrieExtendedCapacity;
let trie: &ZeroTrieExtendedCapacity<[u8]> = ZeroTrieExtendedCapacity::from_bytes(b"abc\x85");
let owned: ZeroTrieExtendedCapacity<Vec<u8>> = trie.to_owned();
assert_eq!(trie.get(b"abc"), Some(5));
assert_eq!(owned.get(b"abc"), Some(5));
Sourcepub fn iter(&self) -> impl Iterator<Item = (Vec<u8>, usize)> + '_
pub fn iter(&self) -> impl Iterator<Item = (Vec<u8>, usize)> + '_
Returns an iterator over the key/value pairs in this trie.
✨ Enabled with the alloc
Cargo feature.
§Examples
use zerotrie::ZeroTrieExtendedCapacity;
// A trie with two values: "abc" and "abcdef"
let trie: &ZeroTrieExtendedCapacity<[u8]> = ZeroTrieExtendedCapacity::from_bytes(b"abc\x80def\x81");
let mut it = trie.iter();
assert_eq!(it.next(), Some(("abc".into(), 0)));
assert_eq!(it.next(), Some(("abcdef".into(), 1)));
assert_eq!(it.next(), None);
Source§impl ZeroTrieExtendedCapacity<[u8]>
impl ZeroTrieExtendedCapacity<[u8]>
Sourcepub fn from_bytes(trie: &[u8]) -> &Self
pub 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.
Source§impl<Store> ZeroTrieExtendedCapacity<Store>
impl<Store> ZeroTrieExtendedCapacity<Store>
Sourcepub fn to_btreemap(&self) -> BTreeMap<Vec<u8>, usize>
pub fn to_btreemap(&self) -> BTreeMap<Vec<u8>, usize>
Exports the data from this ZeroTrie type into a BTreeMap.
✨ Enabled with the alloc
Cargo feature.
§Examples
use zerotrie::ZeroTrieExtendedCapacity;
use std::collections::BTreeMap;
let trie = ZeroTrieExtendedCapacity::from_bytes(b"abc\x81def\x82");
let items = trie.to_btreemap();
assert_eq!(items.len(), 2);
let recovered_trie: ZeroTrieExtendedCapacity<Vec<u8>> = items
.into_iter()
.collect();
assert_eq!(trie.as_bytes(), recovered_trie.as_bytes());
Source§impl<Store> ZeroTrieExtendedCapacity<Store>
impl<Store> ZeroTrieExtendedCapacity<Store>
Sourcepub fn to_litemap(&self) -> LiteMap<Vec<u8>, usize>
pub fn to_litemap(&self) -> LiteMap<Vec<u8>, usize>
Exports the data from this ZeroTrie type into a LiteMap.
✨ Enabled with the litemap
Cargo feature.
§Examples
use zerotrie::ZeroTrieExtendedCapacity;
use litemap::LiteMap;
let trie = ZeroTrieExtendedCapacity::from_bytes(b"abc\x81def\x82");
let items = trie.to_litemap();
assert_eq!(items.len(), 2);
let recovered_trie: ZeroTrieExtendedCapacity<Vec<u8>> = items
.iter()
.map(|(k, v)| (k, *v))
.collect();
assert_eq!(trie.as_bytes(), recovered_trie.as_bytes());
Trait Implementations§
Source§impl<Store> AsRef<ZeroTrieExtendedCapacity<[u8]>> for ZeroTrieExtendedCapacity<Store>
impl<Store> AsRef<ZeroTrieExtendedCapacity<[u8]>> for ZeroTrieExtendedCapacity<Store>
Source§fn as_ref(&self) -> &ZeroTrieExtendedCapacity<[u8]>
fn as_ref(&self) -> &ZeroTrieExtendedCapacity<[u8]>
Source§impl Borrow<ZeroTrieExtendedCapacity<[u8]>> for ZeroTrieExtendedCapacity<&[u8]>
impl Borrow<ZeroTrieExtendedCapacity<[u8]>> for ZeroTrieExtendedCapacity<&[u8]>
Source§impl Borrow<ZeroTrieExtendedCapacity<[u8]>> for ZeroTrieExtendedCapacity<Box<[u8]>>
impl Borrow<ZeroTrieExtendedCapacity<[u8]>> for ZeroTrieExtendedCapacity<Box<[u8]>>
Source§impl Borrow<ZeroTrieExtendedCapacity<[u8]>> for ZeroTrieExtendedCapacity<Vec<u8>>
impl Borrow<ZeroTrieExtendedCapacity<[u8]>> for ZeroTrieExtendedCapacity<Vec<u8>>
Source§impl<Store: Clone + ?Sized> Clone for ZeroTrieExtendedCapacity<Store>
impl<Store: Clone + ?Sized> Clone for ZeroTrieExtendedCapacity<Store>
Source§fn clone(&self) -> ZeroTrieExtendedCapacity<Store>
fn clone(&self) -> ZeroTrieExtendedCapacity<Store>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<Store: Default + ?Sized> Default for ZeroTrieExtendedCapacity<Store>
impl<Store: Default + ?Sized> Default for ZeroTrieExtendedCapacity<Store>
Source§fn default() -> ZeroTrieExtendedCapacity<Store>
fn default() -> ZeroTrieExtendedCapacity<Store>
Source§impl<'de, 'data, Store> Deserialize<'de> for ZeroTrieExtendedCapacity<Store>
impl<'de, 'data, Store> Deserialize<'de> for ZeroTrieExtendedCapacity<Store>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<Store> From<&ZeroTrieExtendedCapacity<Store>> for BTreeMap<Vec<u8>, usize>
impl<Store> From<&ZeroTrieExtendedCapacity<Store>> for BTreeMap<Vec<u8>, usize>
Source§fn from(other: &ZeroTrieExtendedCapacity<Store>) -> Self
fn from(other: &ZeroTrieExtendedCapacity<Store>) -> Self
Source§impl<Store> From<&ZeroTrieExtendedCapacity<Store>> for LiteMap<Vec<u8>, usize>
impl<Store> From<&ZeroTrieExtendedCapacity<Store>> for LiteMap<Vec<u8>, usize>
Source§fn from(other: &ZeroTrieExtendedCapacity<Store>) -> Self
fn from(other: &ZeroTrieExtendedCapacity<Store>) -> Self
Source§impl<'a, K> FromIterator<(K, usize)> for ZeroTrieExtendedCapacity<Vec<u8>>
impl<'a, K> FromIterator<(K, usize)> for ZeroTrieExtendedCapacity<Vec<u8>>
Source§impl<Store: PartialEq + ?Sized> PartialEq for ZeroTrieExtendedCapacity<Store>
impl<Store: PartialEq + ?Sized> PartialEq for ZeroTrieExtendedCapacity<Store>
Source§fn eq(&self, other: &ZeroTrieExtendedCapacity<Store>) -> bool
fn eq(&self, other: &ZeroTrieExtendedCapacity<Store>) -> bool
self
and other
values to be equal, and is used by ==
.Source§impl<Store> Serialize for ZeroTrieExtendedCapacity<Store>
impl<Store> Serialize for ZeroTrieExtendedCapacity<Store>
Source§impl ToOwned for ZeroTrieExtendedCapacity<[u8]>
impl ToOwned for ZeroTrieExtendedCapacity<[u8]>
Source§fn to_owned(&self) -> Self::Owned
fn to_owned(&self) -> Self::Owned
This impl allows ZeroTrieExtendedCapacity
to be used inside of a Cow
.
Note that it is also possible to use ZeroTrieExtendedCapacity<ZeroVec<u8>>
for a similar result.
✨ Enabled with the alloc
Cargo feature.
§Examples
use std::borrow::Cow;
use zerotrie::ZeroTrieExtendedCapacity;
let trie: Cow<ZeroTrieExtendedCapacity<[u8]>> = Cow::Borrowed(ZeroTrieExtendedCapacity::from_bytes(b"abc\x85"));
assert_eq!(trie.get(b"abc"), Some(5));
Source§type Owned = ZeroTrieExtendedCapacity<Box<[u8]>>
type Owned = ZeroTrieExtendedCapacity<Box<[u8]>>
1.63.0 · Source§fn clone_into(&self, target: &mut Self::Owned)
fn clone_into(&self, target: &mut Self::Owned)
Source§impl<Store> VarULE for ZeroTrieExtendedCapacity<Store>where
Store: VarULE,
impl<Store> VarULE for ZeroTrieExtendedCapacity<Store>where
Store: VarULE,
Source§fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>
fn validate_byte_slice(bytes: &[u8]) -> Result<(), ZeroVecError>
&[u8]
. Read moreSource§unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &Self
unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &Self
&[u8]
, and return it as &Self
with the same lifetime, assuming
that this byte slice has previously been run through Self::parse_byte_slice()
with
success. Read moreSource§fn parse_byte_slice(bytes: &[u8]) -> Result<&Self, ZeroVecError>
fn parse_byte_slice(bytes: &[u8]) -> Result<&Self, ZeroVecError>
Source§fn as_byte_slice(&self) -> &[u8] ⓘ
fn as_byte_slice(&self) -> &[u8] ⓘ
Source§impl<'zf, Store1, Store2> ZeroFrom<'zf, ZeroTrieExtendedCapacity<Store1>> for ZeroTrieExtendedCapacity<Store2>where
Store2: ZeroFrom<'zf, Store1>,
impl<'zf, Store1, Store2> ZeroFrom<'zf, ZeroTrieExtendedCapacity<Store1>> for ZeroTrieExtendedCapacity<Store2>where
Store2: ZeroFrom<'zf, Store1>,
Source§fn zero_from(other: &'zf ZeroTrieExtendedCapacity<Store1>) -> Self
fn zero_from(other: &'zf ZeroTrieExtendedCapacity<Store1>) -> Self
C
into a struct that may retain references into C
.impl<Store: Copy + ?Sized> Copy for ZeroTrieExtendedCapacity<Store>
impl<Store: Eq + ?Sized> Eq for ZeroTrieExtendedCapacity<Store>
impl<Store: ?Sized> StructuralPartialEq for ZeroTrieExtendedCapacity<Store>
Auto Trait Implementations§
impl<Store> Freeze for ZeroTrieExtendedCapacity<Store>
impl<Store> RefUnwindSafe for ZeroTrieExtendedCapacity<Store>where
Store: RefUnwindSafe + ?Sized,
impl<Store> Send for ZeroTrieExtendedCapacity<Store>
impl<Store> Sync for ZeroTrieExtendedCapacity<Store>
impl<Store> Unpin for ZeroTrieExtendedCapacity<Store>
impl<Store> UnwindSafe for ZeroTrieExtendedCapacity<Store>where
Store: UnwindSafe + ?Sized,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> EncodeAsVarULE<T> for T
impl<T> EncodeAsVarULE<T> for T
Source§fn encode_var_ule_as_slices<R>(&self, cb: impl FnOnce(&[&[u8]]) -> R) -> R
fn encode_var_ule_as_slices<R>(&self, cb: impl FnOnce(&[&[u8]]) -> R) -> R
cb
with a piecewise list of byte slices that when concatenated
produce the memory pattern of the corresponding instance of T
. Read moreSource§fn encode_var_ule_len(&self) -> usize
fn encode_var_ule_len(&self) -> usize
VarULE
typeSource§fn encode_var_ule_write(&self, dst: &mut [u8])
fn encode_var_ule_write(&self, dst: &mut [u8])
VarULE
type to the dst
buffer. dst
should
be the size of Self::encode_var_ule_len()