pub struct CommandTrieBuilder<T> { /* private fields */ }Expand description
Mutable trie used during the build phase.
Call Self::build to produce a frozen CommandTrie when you are
done inserting.
Implementations§
Source§impl<T> CommandTrieBuilder<T>
impl<T> CommandTrieBuilder<T>
Sourcepub fn insert(&mut self, key: &str, value: T) -> Option<T>
pub fn insert(&mut self, key: &str, value: T) -> Option<T>
Insert key with value. Returns the previous value, if any.
Any &str is accepted; the radix splits on UTF-8 char boundaries so
every internal edge label remains valid UTF-8.
Sourcepub fn remove(&mut self, key: &str) -> Option<T>
pub fn remove(&mut self, key: &str) -> Option<T>
Remove key and return its value, if present. Maintains the radix
invariant by pruning empty branches and merging single-child
passthroughs with their parent edge.
Sourcepub fn build(self) -> CommandTrie<T>
pub fn build(self) -> CommandTrie<T>
Freeze the builder into a compact, read-only CommandTrie.
Performs one DFS over the builder trie and writes the result into
four contiguous slabs (nodes, labels, children,
child_first_bytes). After this call the frozen trie has exactly
four heap allocations regardless of trie size.
§Panics
If the trie’s total node count, total label bytes, or total edge
count would exceed u16::MAX (65,535). The frozen representation
stores every offset and node id as a u16 to halve the structural
slabs. The worst case for N inserted entries is 2N + 1 nodes,
so this caps the trie at roughly 32,767 entries — enough for
any realistic command set.
Trait Implementations§
Source§impl<T: Clone> Clone for CommandTrieBuilder<T>
impl<T: Clone> Clone for CommandTrieBuilder<T>
Source§fn clone(&self) -> CommandTrieBuilder<T>
fn clone(&self) -> CommandTrieBuilder<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for CommandTrieBuilder<T>
impl<T: Debug> Debug for CommandTrieBuilder<T>
Source§impl<T> Default for CommandTrieBuilder<T>
impl<T> Default for CommandTrieBuilder<T>
Source§impl<K: AsRef<str>, T> Extend<(K, T)> for CommandTrieBuilder<T>
impl<K: AsRef<str>, T> Extend<(K, T)> for CommandTrieBuilder<T>
Source§fn extend<I: IntoIterator<Item = (K, T)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (K, T)>>(&mut self, iter: I)
Insert each (key, value) from iter.
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<K: AsRef<str>, T> FromIterator<(K, T)> for CommandTrieBuilder<T>
impl<K: AsRef<str>, T> FromIterator<(K, T)> for CommandTrieBuilder<T>
Source§fn from_iter<I: IntoIterator<Item = (K, T)>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = (K, T)>>(iter: I) -> Self
Build a CommandTrieBuilder from an iterator of (key, value) pairs.