Struct set_trie::SetTrie[][src]

pub struct SetTrie<K, T>(_);

SetTries allow for efficient subset and superset queries. Think of it as a HashMap, where you want the key to be within or containing a range.

let mut trie = set_trie::SetTrie::new();

trie.insert(&[1, 3, 5], "foo");
trie.insert(&[3], "bar");

assert_eq!(trie.subsets(&[&1, &3, &5, &6]).collect::<Vec<_>>(), vec![&"foo", &"bar"]);
assert_eq!(trie.supersets(&[&5]).collect::<Vec<_>>(), vec![&"foo"])

Restrictions

Keys are required to be Ord, as the trie stores the nodes in sorted order by key. This means that the caller must ensure that provided keys are in sorted order, lest nonsensical results be returned.

Performance

Subsets and Supersets are lazily evaluated. Note that superset queries are far more expensive than subset queries, so attempt to structure your problem around subsets.

Implementations

impl<K, T> SetTrie<K, T>[src]

#[must_use]pub const fn new() -> Self[src]

Create a new, empty SetTrie, without allocating any space for the nodes.

impl<K, T> SetTrie<K, T> where
    K: Ord
[src]

#[must_use]pub fn entry<IK: IntoIterator<Item = K>>(
    &mut self,
    keys: IK
) -> EntryBuilder<'_, K, T, IK::IntoIter>
[src]

A view into a single node in the trie; which must either be created or already exists.

pub fn insert(&mut self, keys: impl IntoIterator<Item = K>, item: T)[src]

Insert the item in the given node. Will create the node if needed.

pub fn insert_many<IK: IntoIterator<Item = K>, IT: IntoIterator<Item = T>>(
    &mut self,
    keys: IK,
    item: IT
)
[src]

Inserts multiple items in the given node. More performant that repeatedly calling insert.

#[must_use]pub fn subsets<'a, 'b>(&'a self, keys: &'b [K]) -> Subset<'a, 'b, K, T>[src]

Iterates over all subsets of keys using DFS, meaning that the keys are visited in order of the query:

let mut trie = set_trie::SetTrie::new();
trie.insert(&[1], "foo");
trie.insert(&[1, 2], "bar");
trie.insert(&[1, 2, 3], "baz");

assert_eq!(trie.subsets(&[&1, &2, &3]).collect::<Vec<_>>(), vec![&"foo", &"bar", &"baz"]);

#[must_use]pub fn values(&self) -> Values<'_, K, T>[src]

Iterates over all values in the trie using DFS, meaning that values are visited in order of the keys stored in the trie.

let mut trie = set_trie::SetTrie::new();
trie.insert(&[1], "foo");
trie.insert(&[1, 2], "bar");
trie.insert(&[1, 2, 3], "baz");

assert_eq!(trie.values().collect::<Vec<_>>(), vec![&"foo", &"bar", &"baz"]);

#[must_use]pub fn supersets<'a, 'b>(&'a self, keys: &'b [K]) -> SuperSet<'a, 'b, K, T>[src]

Iterates over all supersets of keys in the trie using DFS, meaning that values are visited in order of the query.

let mut trie = set_trie::SetTrie::new();
trie.insert(&[1], "foo");
trie.insert(&[1, 2], "bar");
trie.insert(&[1, 2, 3], "baz");

assert_eq!(trie.supersets(&[&1]).collect::<Vec<_>>(), vec![&"foo", &"bar", &"baz"]);

Remarks

Note that the empty set will provide the same result as values. There is currently no fast path in the trie, so if you know that your query contains no keys, use SetTrie::values instead.

Trait Implementations

impl<K: Debug, T: Debug> Debug for SetTrie<K, T>[src]

impl<K: Default, T: Default> Default for SetTrie<K, T>[src]

impl<I, K, T> Extend<(I, T)> for SetTrie<K, T> where
    I: IntoIterator<Item = K>,
    K: Ord
[src]

impl<I, K, T> FromIterator<(I, T)> for SetTrie<K, T> where
    I: IntoIterator<Item = K>,
    K: Ord
[src]

Auto Trait Implementations

impl<K, T> RefUnwindSafe for SetTrie<K, T> where
    K: RefUnwindSafe,
    T: RefUnwindSafe
[src]

impl<K, T> Send for SetTrie<K, T> where
    K: Send,
    T: Send
[src]

impl<K, T> Sync for SetTrie<K, T> where
    K: Sync,
    T: Sync
[src]

impl<K, T> Unpin for SetTrie<K, T> where
    K: Unpin,
    T: Unpin
[src]

impl<K, T> UnwindSafe for SetTrie<K, T> where
    K: UnwindSafe,
    T: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.