Struct zerotrie::ZeroAsciiIgnoreCaseTrie
source · #[repr(transparent)]pub struct ZeroAsciiIgnoreCaseTrie<Store: ?Sized> { /* private fields */ }
Expand description
A data structure that compactly maps from ASCII strings to integers in a case-insensitive way.
§Examples
use litemap::LiteMap;
use zerotrie::ZeroAsciiIgnoreCaseTrie;
let mut map = LiteMap::new_vec();
map.insert(&b"foo"[..], 1);
map.insert(b"Bar", 2);
map.insert(b"Bazzoo", 3);
let trie = ZeroAsciiIgnoreCaseTrie::try_from(&map)?;
assert_eq!(trie.get(b"foo"), Some(1));
assert_eq!(trie.get(b"bar"), Some(2));
assert_eq!(trie.get(b"BAR"), Some(2));
assert_eq!(trie.get(b"bazzoo"), Some(3));
assert_eq!(trie.get(b"unknown"), None);
Strings with different cases of the same character at the same offset are not allowed:
use litemap::LiteMap;
use zerotrie::ZeroAsciiIgnoreCaseTrie;
let mut map = LiteMap::new_vec();
map.insert(&b"bar"[..], 1);
// OK: 'r' and 'Z' are different letters
map.insert(b"baZ", 2);
// Bad: we already inserted 'r' so we cannot also insert 'R' at the same position
map.insert(b"baR", 2);
ZeroAsciiIgnoreCaseTrie::try_from(&map).expect_err("mixed-case strings!");
Implementations§
source§impl<Store> ZeroAsciiIgnoreCaseTrie<Store>
impl<Store> ZeroAsciiIgnoreCaseTrie<Store>
sourcepub fn cursor(&self) -> ZeroAsciiIgnoreCaseTrieCursor<'_>
pub fn cursor(&self) -> ZeroAsciiIgnoreCaseTrieCursor<'_>
Gets a cursor into the current trie.
Useful to query a trie with data that is not a slice.
This is currently supported only on ZeroTrieSimpleAscii
and ZeroAsciiIgnoreCaseTrie
.
§Examples
Get a value out of a trie by writing it to the cursor:
use core::fmt::Write;
use zerotrie::ZeroAsciiIgnoreCaseTrie;
// A trie with two values: "aBc" and "aBcdEf"
let trie = ZeroAsciiIgnoreCaseTrie::from_bytes(b"aBc\x80dEf\x81");
// Get out the value for "abc" (case-insensitive!)
let mut cursor = trie.cursor();
write!(&mut cursor, "abc");
assert_eq!(cursor.take_value(), Some(0));
For more examples, see ZeroTrieSimpleAscii::cursor
.
source§impl<'a> ZeroAsciiIgnoreCaseTrie<&'a [u8]>
impl<'a> ZeroAsciiIgnoreCaseTrie<&'a [u8]>
sourcepub fn into_cursor(self) -> ZeroAsciiIgnoreCaseTrieCursor<'a>
pub fn into_cursor(self) -> ZeroAsciiIgnoreCaseTrieCursor<'a>
Same as ZeroAsciiIgnoreCaseTrie::cursor()
but moves self to avoid
having to doubly anchor the trie to the stack.
source§impl<Store> ZeroAsciiIgnoreCaseTrie<Store>
impl<Store> ZeroAsciiIgnoreCaseTrie<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) -> ZeroAsciiIgnoreCaseTrie<X>
pub fn convert_store<X: From<Store>>(self) -> ZeroAsciiIgnoreCaseTrie<X>
Converts this trie’s store to a different store implementing the From
trait.
For example, use this to change ZeroAsciiIgnoreCaseTrie<Vec<u8>>
to ZeroAsciiIgnoreCaseTrie<Cow<[u8]>>
.
§Examples
use std::borrow::Cow;
use zerotrie::ZeroAsciiIgnoreCaseTrie;
let trie: ZeroAsciiIgnoreCaseTrie<Vec<u8>> = ZeroAsciiIgnoreCaseTrie::from_bytes(b"abc\x85").to_owned();
let cow: ZeroAsciiIgnoreCaseTrie<Cow<[u8]>> = trie.convert_store();
assert_eq!(cow.get(b"abc"), Some(5));
source§impl<Store> ZeroAsciiIgnoreCaseTrie<Store>
impl<Store> ZeroAsciiIgnoreCaseTrie<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::ZeroAsciiIgnoreCaseTrie;
// A trie with two values: "abc" and "abcdef"
let trie: &ZeroAsciiIgnoreCaseTrie<[u8]> = ZeroAsciiIgnoreCaseTrie::from_bytes(b"abc\x80def\x81");
assert_eq!(8, trie.byte_len());
assert_eq!(2, trie.iter().count());
sourcepub fn as_borrowed(&self) -> &ZeroAsciiIgnoreCaseTrie<[u8]>
pub fn as_borrowed(&self) -> &ZeroAsciiIgnoreCaseTrie<[u8]>
Returns this trie as a reference transparent over a byte slice.
sourcepub fn as_borrowed_slice(&self) -> ZeroAsciiIgnoreCaseTrie<&[u8]>
pub fn as_borrowed_slice(&self) -> ZeroAsciiIgnoreCaseTrie<&[u8]>
Returns a trie with a store borrowing from this trie.
source§impl<Store> ZeroAsciiIgnoreCaseTrie<Store>
impl<Store> ZeroAsciiIgnoreCaseTrie<Store>
sourcepub fn to_owned(&self) -> ZeroAsciiIgnoreCaseTrie<Vec<u8>>
pub fn to_owned(&self) -> ZeroAsciiIgnoreCaseTrie<Vec<u8>>
Converts a possibly-borrowed $name to an owned one.
✨ Enabled with the alloc
Cargo feature.
§Examples
use zerotrie::ZeroAsciiIgnoreCaseTrie;
let trie: &ZeroAsciiIgnoreCaseTrie<[u8]> = ZeroAsciiIgnoreCaseTrie::from_bytes(b"abc\x85");
let owned: ZeroAsciiIgnoreCaseTrie<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 = (String, usize)> + '_
pub fn iter(&self) -> impl Iterator<Item = (String, usize)> + '_
Returns an iterator over the key/value pairs in this trie.
✨ Enabled with the alloc
Cargo feature.
§Examples
use zerotrie::ZeroAsciiIgnoreCaseTrie;
// A trie with two values: "abc" and "abcdef"
let trie: &ZeroAsciiIgnoreCaseTrie<[u8]> = ZeroAsciiIgnoreCaseTrie::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 ZeroAsciiIgnoreCaseTrie<[u8]>
impl ZeroAsciiIgnoreCaseTrie<[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 ZeroAsciiIgnoreCaseTrie<Vec<u8>>
impl ZeroAsciiIgnoreCaseTrie<Vec<u8>>
source§impl<Store> ZeroAsciiIgnoreCaseTrie<Store>
impl<Store> ZeroAsciiIgnoreCaseTrie<Store>
sourcepub fn to_btreemap(&self) -> BTreeMap<String, usize>
pub fn to_btreemap(&self) -> BTreeMap<String, usize>
Exports the data from this ZeroTrie type into a BTreeMap.
✨ Enabled with the alloc
Cargo feature.
§Examples
use zerotrie::ZeroAsciiIgnoreCaseTrie;
use std::collections::BTreeMap;
let trie = ZeroAsciiIgnoreCaseTrie::from_bytes(b"abc\x81def\x82");
let items = trie.to_btreemap();
assert_eq!(items.len(), 2);
let recovered_trie: ZeroAsciiIgnoreCaseTrie<Vec<u8>> = items
.into_iter()
.collect();
assert_eq!(trie.as_bytes(), recovered_trie.as_bytes());
pub(crate) fn to_btreemap_bytes(&self) -> BTreeMap<Box<[u8]>, usize>
Trait Implementations§
source§impl<Store> AsRef<ZeroAsciiIgnoreCaseTrie<[u8]>> for ZeroAsciiIgnoreCaseTrie<Store>
impl<Store> AsRef<ZeroAsciiIgnoreCaseTrie<[u8]>> for ZeroAsciiIgnoreCaseTrie<Store>
source§fn as_ref(&self) -> &ZeroAsciiIgnoreCaseTrie<[u8]>
fn as_ref(&self) -> &ZeroAsciiIgnoreCaseTrie<[u8]>
source§impl Borrow<ZeroAsciiIgnoreCaseTrie<[u8]>> for ZeroAsciiIgnoreCaseTrie<&[u8]>
impl Borrow<ZeroAsciiIgnoreCaseTrie<[u8]>> for ZeroAsciiIgnoreCaseTrie<&[u8]>
source§impl Borrow<ZeroAsciiIgnoreCaseTrie<[u8]>> for ZeroAsciiIgnoreCaseTrie<Box<[u8]>>
impl Borrow<ZeroAsciiIgnoreCaseTrie<[u8]>> for ZeroAsciiIgnoreCaseTrie<Box<[u8]>>
source§impl Borrow<ZeroAsciiIgnoreCaseTrie<[u8]>> for ZeroAsciiIgnoreCaseTrie<Vec<u8>>
impl Borrow<ZeroAsciiIgnoreCaseTrie<[u8]>> for ZeroAsciiIgnoreCaseTrie<Vec<u8>>
source§impl<Store: Clone + ?Sized> Clone for ZeroAsciiIgnoreCaseTrie<Store>
impl<Store: Clone + ?Sized> Clone for ZeroAsciiIgnoreCaseTrie<Store>
source§fn clone(&self) -> ZeroAsciiIgnoreCaseTrie<Store>
fn clone(&self) -> ZeroAsciiIgnoreCaseTrie<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 ZeroAsciiIgnoreCaseTrie<Store>
impl<Store: Default + ?Sized> Default for ZeroAsciiIgnoreCaseTrie<Store>
source§fn default() -> ZeroAsciiIgnoreCaseTrie<Store>
fn default() -> ZeroAsciiIgnoreCaseTrie<Store>
source§impl<Store> From<&ZeroAsciiIgnoreCaseTrie<Store>> for BTreeMap<String, usize>
impl<Store> From<&ZeroAsciiIgnoreCaseTrie<Store>> for BTreeMap<String, usize>
source§fn from(other: &ZeroAsciiIgnoreCaseTrie<Store>) -> Self
fn from(other: &ZeroAsciiIgnoreCaseTrie<Store>) -> Self
source§impl<'a, K> FromIterator<(K, usize)> for ZeroAsciiIgnoreCaseTrie<Vec<u8>>
impl<'a, K> FromIterator<(K, usize)> for ZeroAsciiIgnoreCaseTrie<Vec<u8>>
source§impl<Store: PartialEq + ?Sized> PartialEq for ZeroAsciiIgnoreCaseTrie<Store>
impl<Store: PartialEq + ?Sized> PartialEq for ZeroAsciiIgnoreCaseTrie<Store>
source§fn eq(&self, other: &ZeroAsciiIgnoreCaseTrie<Store>) -> bool
fn eq(&self, other: &ZeroAsciiIgnoreCaseTrie<Store>) -> bool
self
and other
values to be equal, and is used by ==
.source§impl ToOwned for ZeroAsciiIgnoreCaseTrie<[u8]>
impl ToOwned for ZeroAsciiIgnoreCaseTrie<[u8]>
source§fn to_owned(&self) -> Self::Owned
fn to_owned(&self) -> Self::Owned
This impl allows ZeroAsciiIgnoreCaseTrie
to be used inside of a Cow
.
Note that it is also possible to use ZeroAsciiIgnoreCaseTrie<ZeroVec<u8>>
for a similar result.
✨ Enabled with the alloc
Cargo feature.
§Examples
use std::borrow::Cow;
use zerotrie::ZeroAsciiIgnoreCaseTrie;
let trie: Cow<ZeroAsciiIgnoreCaseTrie<[u8]>> = Cow::Borrowed(ZeroAsciiIgnoreCaseTrie::from_bytes(b"abc\x85"));
assert_eq!(trie.get(b"abc"), Some(5));
1.63.0 · source§fn clone_into(&self, target: &mut Self::Owned)
fn clone_into(&self, target: &mut Self::Owned)
source§impl<'zf, Store1, Store2> ZeroFrom<'zf, ZeroAsciiIgnoreCaseTrie<Store1>> for ZeroAsciiIgnoreCaseTrie<Store2>where
Store2: ZeroFrom<'zf, Store1>,
impl<'zf, Store1, Store2> ZeroFrom<'zf, ZeroAsciiIgnoreCaseTrie<Store1>> for ZeroAsciiIgnoreCaseTrie<Store2>where
Store2: ZeroFrom<'zf, Store1>,
source§fn zero_from(other: &'zf ZeroAsciiIgnoreCaseTrie<Store1>) -> Self
fn zero_from(other: &'zf ZeroAsciiIgnoreCaseTrie<Store1>) -> Self
C
into a struct that may retain references into C
.source§impl<S: ?Sized> ZeroTrieWithOptions for ZeroAsciiIgnoreCaseTrie<S>
impl<S: ?Sized> ZeroTrieWithOptions for ZeroAsciiIgnoreCaseTrie<S>
All branch nodes are binary search and nodes use case-insensitive matching.
const OPTIONS: ZeroTrieBuilderOptions = _
impl<Store: Copy + ?Sized> Copy for ZeroAsciiIgnoreCaseTrie<Store>
impl<Store: Eq + ?Sized> Eq for ZeroAsciiIgnoreCaseTrie<Store>
impl<Store: ?Sized> StructuralPartialEq for ZeroAsciiIgnoreCaseTrie<Store>
Auto Trait Implementations§
impl<Store> Freeze for ZeroAsciiIgnoreCaseTrie<Store>
impl<Store> RefUnwindSafe for ZeroAsciiIgnoreCaseTrie<Store>where
Store: RefUnwindSafe + ?Sized,
impl<Store> Send for ZeroAsciiIgnoreCaseTrie<Store>
impl<Store> Sync for ZeroAsciiIgnoreCaseTrie<Store>
impl<Store> Unpin for ZeroAsciiIgnoreCaseTrie<Store>
impl<Store> UnwindSafe for ZeroAsciiIgnoreCaseTrie<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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)