pub struct DynTrie<T> { /* private fields */ }Expand description
A nibble trie that starts with compact u8 arena indices and automatically promotes to u16/u32/u64 as needed.
Node sizes by PTR width:
- u8: 32 bytes (fits half a cache line)
- u16: 48 bytes (fits a cache line)
- u32: 80 bytes
- u64: 152 bytes
Promotion is transparent: insert checks capacity and promotes before the underlying trie overflows. No vtable dispatch or heap allocation on promotion — just an enum variant swap.
Implementations§
Source§impl<T> DynTrie<T>
impl<T> DynTrie<T>
Sourcepub fn get_mut(&mut self, key: &[u8]) -> Option<&mut T>
pub fn get_mut(&mut self, key: &[u8]) -> Option<&mut T>
Look up a key’s value for mutation. Returns the value if found.
Sourcepub fn insert(&mut self, key: Vec<u8>, value: T) -> Result<usize, ()>
pub fn insert(&mut self, key: Vec<u8>, value: T) -> Result<usize, ()>
Insert a key-value pair. Automatically promotes to a wider PTR type if
the current one is approaching capacity. Returns the key index on
success, or Err(()) on duplicate key.
Sourcepub fn ptr_size(&self) -> usize
pub fn ptr_size(&self) -> usize
Returns the size of the current PTR type in bytes (1, 2, 4, or 8). Useful for debugging and testing promotion.
Sourcepub fn iter_fwd(&self, f: &mut dyn FnMut(&[u8], &T))
pub fn iter_fwd(&self, f: &mut dyn FnMut(&[u8], &T))
Iterate all key-value pairs in forward (ascending) order.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for DynTrie<T>
impl<T> RefUnwindSafe for DynTrie<T>where
T: RefUnwindSafe,
impl<T> Send for DynTrie<T>where
T: Send,
impl<T> Sync for DynTrie<T>where
T: Sync,
impl<T> Unpin for DynTrie<T>where
T: Unpin,
impl<T> UnsafeUnpin for DynTrie<T>
impl<T> UnwindSafe for DynTrie<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more