Struct ZeroAsciiIgnoreCaseTrie

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

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);

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

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

impl ZeroAsciiIgnoreCaseTrie<[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<'a> ZeroAsciiIgnoreCaseTrie<&'a [u8]>

fn into_cursor(self: Self) -> ZeroAsciiIgnoreCaseTrieCursor<'a>

Same as [ZeroAsciiIgnoreCaseTrie::cursor()] but moves self to avoid having to doubly anchor the trie to the stack.

impl<Store> ZeroAsciiIgnoreCaseTrie<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::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());
fn as_bytes(self: &Self) -> &[u8]

Returns the bytes contained in the underlying store.

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

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

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

Returns a trie with a store borrowing from this trie.

impl<Store> ZeroAsciiIgnoreCaseTrie<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) -> 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));

impl<Store> ZeroAsciiIgnoreCaseTrie<Store>

fn cursor(self: &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.

impl Borrow for ZeroAsciiIgnoreCaseTrie<&[u8]>

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

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

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

impl<Store> AsRef for ZeroAsciiIgnoreCaseTrie<Store>

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

impl<Store> Freeze for ZeroAsciiIgnoreCaseTrie<Store>

impl<Store> RefUnwindSafe for ZeroAsciiIgnoreCaseTrie<Store>

impl<Store> Send for ZeroAsciiIgnoreCaseTrie<Store>

impl<Store> Sync for ZeroAsciiIgnoreCaseTrie<Store>

impl<Store> Unpin for ZeroAsciiIgnoreCaseTrie<Store>

impl<Store> UnsafeUnpin for ZeroAsciiIgnoreCaseTrie<Store>

impl<Store> UnwindSafe for ZeroAsciiIgnoreCaseTrie<Store>

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

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

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

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

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

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

fn default() -> ZeroAsciiIgnoreCaseTrie<Store>

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

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

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

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

impl<T> Any for ZeroAsciiIgnoreCaseTrie<Store>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ZeroAsciiIgnoreCaseTrie<Store>

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

impl<T> BorrowMut for ZeroAsciiIgnoreCaseTrie<Store>

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

impl<T> CloneToUninit for ZeroAsciiIgnoreCaseTrie<Store>

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

impl<T> ErasedDestructor for ZeroAsciiIgnoreCaseTrie<Store>

impl<T> From for ZeroAsciiIgnoreCaseTrie<Store>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for ZeroAsciiIgnoreCaseTrie<Store>

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

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

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

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

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