pub struct TriePosition { /* private fields */ }Expand description
Encapsulates logic for moving around in paged storage for a binary trie.
Implementations§
Source§impl TriePosition
impl TriePosition
Sourcepub fn from_path_and_depth(path: KeyPath, depth: u16) -> Self
pub fn from_path_and_depth(path: KeyPath, depth: u16) -> Self
Create a new TriePosition based on the first depth bits of path.
Panics if depth is zero.
Sourcepub fn from_bitslice(slice: &BitSlice<u8, Msb0>) -> Self
pub fn from_bitslice(slice: &BitSlice<u8, Msb0>) -> Self
Create a new TriePosition based on a bitslice.
Sourcepub fn raw_path(&self) -> [u8; 32]
pub fn raw_path(&self) -> [u8; 32]
Get the raw key at the current position.
Note that if you have called up, this might have bits beyond depth which are set.
Sourcepub fn down(&mut self, bit: bool)
pub fn down(&mut self, bit: bool)
Move the position down by 1, towards either the left or right child.
Panics on depth out of range.
Sourcepub fn up(&mut self, d: u16)
pub fn up(&mut self, d: u16)
Move the position up by d bits.
Panics if d is greater than the current depth.
Sourcepub fn peek_last_bit(&self) -> bool
pub fn peek_last_bit(&self) -> bool
Peek at the last bit of the path.
Panics if at the root.
Sourcepub fn page_id(&self) -> Option<PageId>
pub fn page_id(&self) -> Option<PageId>
Get the page ID this position lands in. Returns None at the root.
Sourcepub fn child_page_index(&self) -> ChildPageIndex
pub fn child_page_index(&self) -> ChildPageIndex
Get the child page index, relative to the current page, where the children of the current node are stored.
Panics if the position is not in the last layer of the page.
Sourcepub fn sibling_child_page_index(&self) -> ChildPageIndex
pub fn sibling_child_page_index(&self) -> ChildPageIndex
Get the child page index, relative to the current page, where the children of the sibling node are stored.
Panics if the position is not in the last layer of the page.
Sourcepub fn child_node_indices(&self) -> ChildNodeIndices
pub fn child_node_indices(&self) -> ChildNodeIndices
Transform a bit-path to the index in a page corresponding to the child node indices.
Panics if the node is not at a depth in the range 1..=5
Sourcepub fn sibling_index(&self) -> usize
pub fn sibling_index(&self) -> usize
Get the index of the sibling node within a page.
Sourcepub fn node_index(&self) -> usize
pub fn node_index(&self) -> usize
Get the index of the current node within a page.
Sourcepub fn depth_in_page(&self) -> usize
pub fn depth_in_page(&self) -> usize
Get the number of bits traversed in the current page.
Note that every page has traversed at least 1 bit, therefore the return value would be
between 1 and DEPTH, with the exception of the root node, which has traversed 0 bits.
Sourcepub fn is_first_layer_in_page(&self) -> bool
pub fn is_first_layer_in_page(&self) -> bool
Fast path for checking whether this is in the first layer in the page.
Get the number of shared bits between this position and other.
This is essentially the depth of a hypothetical internal node which both positions would descend from.
Sourcepub fn subtrie_contains(&self, path: &KeyPath) -> bool
pub fn subtrie_contains(&self, path: &KeyPath) -> bool
Whether the sub-trie indicated by this position would contain a given key-path.
Trait Implementations§
Source§impl Clone for TriePosition
impl Clone for TriePosition
Source§fn clone(&self) -> TriePosition
fn clone(&self) -> TriePosition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TriePosition
impl Debug for TriePosition
Source§impl PartialEq for TriePosition
impl PartialEq for TriePosition
impl Eq for TriePosition
Auto Trait Implementations§
impl Freeze for TriePosition
impl RefUnwindSafe for TriePosition
impl Send for TriePosition
impl Sync for TriePosition
impl Unpin for TriePosition
impl UnwindSafe for TriePosition
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§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.