fn scan<K, V, T, S, E>(
    _correlation_id: CorrelationId,
    txn: &T,
    store: &S,
    key_bytes: &[u8],
    root: &Trie<K, V>,
) -> Result<TrieScan<K, V>, E>
where
    K: ToBytes + FromBytes + Clone,
    V: ToBytes + FromBytes + Clone,
    T: Readable<Handle = S::Handle>,
    S: TrieStore<K, V>,
    S::Error: From<T::Error>,
    E: From<S::Error> + From<bytesrepr::Error>,
{
    let path = key_bytes;

    let mut current = root.to_owned();
    let mut depth: usize = 0;
    let mut acc: Parents<K, V> = Vec::new();

    loop {
        match current {
            leaf @ Trie::Leaf { .. } => {
                return Ok(TrieScan::new(leaf, acc));
            }
            Trie::Node { pointer_block } => {
                let index = {
                    assert!(depth < path.len(), "depth must be < {}", path.len());
                    path[depth]
                };
                let maybe_pointer: Option<Pointer> = {
                    let index: usize = index.into();
                    assert!(index < RADIX, "index must be < {}", RADIX);
                    pointer_block[index]
                };
                let pointer = match maybe_pointer {
                    Some(pointer) => pointer,
                    None => {
                        return Ok(TrieScan::new(Trie::Node { pointer_block }, acc));
                    }
                };
                match store.get(txn, pointer.hash())? {
                    Some(next) => {
                        current = next;
                        depth += 1;
                        acc.push((index, Trie::Node { pointer_block }))
                    }
                    None => {
                        panic!(
                            "No trie value at key: {:?} (reading from path: {:?})",
                            pointer.hash(),
                            path
                        );
                    }
                }
            }
            Trie::Extension { affix, pointer } => {
                let sub_path = &path[depth..depth + affix.len()];
                if sub_path != affix.as_slice() {
                    return Ok(TrieScan::new(Trie::Extension { affix, pointer }, acc));
                }
                match store.get(txn, pointer.hash())? {
                    Some(next) => {
                        let index = {
                            assert!(depth < path.len(), "depth must be < {}", path.len());
                            path[depth]
                        };
                        current = next;
                        depth += affix.len();
                        acc.push((index, Trie::Extension { affix, pointer }))
                    }
                    None => {
                        panic!(
                            "No trie value at key: {:?} (reading from path: {:?})",
                            pointer.hash(),
                            path
                        );
                    }
                }
            }
        }
    }
}
/// Returns a [`TrieScan`] from the given key at a given root in a given store.
/// A scan consists of the deepest trie variant found at that key, a.k.a. the
/// "tip", along the with the parents of that variant. Parents are ordered by
/// their depth from the root (shallow to deep).
Returns a [`TrieScan`] from the given key at a given root in a given store.
A scan consists of the deepest trie variant found at that key, a.k.a. the
"tip", along the with the parents of that variant. Parents are ordered by
their depth from the root (shallow to deep).
Returns a [ ` TrieScan ` ] from the given key at a given root in a given store . A scan consists of the deepest trie variant found at that key a . k . a . the " tip " along the with the parents of that variant . Parents are ordered by their depth from the root ( shallow to deep ) .
fn scan<K, V, T, S, E>(
    _correlation_id: CorrelationId,
    txn: &T,
    store: &S,
    key_bytes: &[u8],
    root: &Trie<K, V>,
) -> Result<TrieScan<K, V>, E>
where
    K: ToBytes + FromBytes + Clone,
    V: ToBytes + FromBytes + Clone,
    T: Readable<Handle = S::Handle>,
    S: TrieStore<K, V>,
    S::Error: From<T::Error>,
    E: From<S::Error> + From<bytesrepr::Error>,
{
    let path = key_bytes;
    let mut current = root.to_owned();
    let mut depth: usize = 0;
    let mut acc: Parents<K, V> = Vec::new();
    loop {
        match current {
            leaf @ Trie::Leaf { .. } => {
                return Ok(TrieScan::new(leaf, acc));
            }
            Trie::Node { pointer_block } => {
                let index = {
                    assert!(depth < path.len(), "depth must be < {}", path.len());
                    path[depth]
                };
                let maybe_pointer: Option<Pointer> = {
                    let index: usize = index.into();
                    assert!(index < RADIX, "index must be < {}", RADIX);
                    pointer_block[index]
                };
                let pointer = match maybe_pointer {
                    Some(pointer) => pointer,
                    None => {
                        return Ok(TrieScan::new(Trie::Node { pointer_block }, acc));
                    }
                };
                match store.get(txn, pointer.hash())? {
                    Some(next) => {
                        current = next;
                        depth += 1;
                        acc.push((index, Trie::Node { pointer_block }))
                    }
                    None => {
                        panic!(
                            "No trie value at key: {:?} (reading from path: {:?})",
                            pointer.hash(),
                            path
                        );
                    }
                }
            }
            Trie::Extension { affix, pointer } => {
                let sub_path = &path[depth..depth + affix.len()];
                if sub_path != affix.as_slice() {
                    return Ok(TrieScan::new(Trie::Extension { affix, pointer }, acc));
                }
                match store.get(txn, pointer.hash())? {
                    Some(next) => {
                        let index = {
                            assert!(depth < path.len(), "depth must be < {}", path.len());
                            path[depth]
                        };
                        current = next;
                        depth += affix.len();
                        acc.push((index, Trie::Extension { affix, pointer }))
                    }
                    None => {
                        panic!(
                            "No trie value at key: {:?} (reading from path: {:?})",
                            pointer.hash(),
                            path
                        );
                    }
                }
            }
        }
    }
}
fn scan < K , V , T , S , E > ( _correlation_id : CorrelationId , txn : & T , store : & S , key_bytes : & [ u8 ] , root : & Trie < K , V > , ) -> Result < TrieScan < K , V > , E > where K : ToBytes + FromBytes + Clone , V : ToBytes + FromBytes + Clone , T : Readable < Handle = S :: Handle > , S : TrieStore < K , V > , S :: Error : From < T :: Error > , E : From < S :: Error > + From < bytesrepr :: Error > , { let path = key_bytes ; let mut current = root . to_owned ( ) ; let mut depth : usize = 0 ; let mut acc : Parents < K , V > = Vec :: new ( ) ; loop { match current { leaf @ Trie :: Leaf { .. } => { return Ok ( TrieScan :: new ( leaf , acc ) ) ; } Trie :: Node { pointer_block } => { let index = { assert ! ( depth path len ( ) " " path len ( ) ) ; path [ depth ] } ; let maybe_pointer : Option < Pointer > = { let index : usize = index . into ( ) ; assert ! ( index RADIX " " RADIX ) ; pointer_block [ index ] } ; let pointer = match maybe_pointer { Some ( pointer ) => pointer , None => { return Ok ( TrieScan :: new ( Trie :: Node { pointer_block } , acc ) ) ; } } ; match store . get ( txn , pointer . hash ( ) ) ? { Some ( next ) => { current = next ; depth += 1 ; acc . push ( ( index , Trie :: Node { pointer_block } ) ) } None => { panic ! ( " " pointer hash ( ) path ) ; } } } Trie :: Extension { affix , pointer } => { let sub_path = & path [ depth .. depth + affix . len ( ) ] ; if sub_path != affix . as_slice ( ) { return Ok ( TrieScan :: new ( Trie :: Extension { affix , pointer } , acc ) ) ; } match store . get ( txn , pointer . hash ( ) ) ? { Some ( next ) => { let index = { assert ! ( depth path len ( ) " " path len ( ) ) ; path [ depth ] } ; current = next ; depth += affix . len ( ) ; acc . push ( ( index , Trie :: Extension { affix , pointer } ) ) } None => { panic ! ( " " pointer hash ( ) path ) ; } } } } } }
Returns a [`TrieScan`] from the given key at a given root in a given store.
Returns a [ ` TrieScan ` ] from the given key at a given root in a given store .
_correlation_id
CorrelationId
txn
&T
store
&S
key_bytes
&[u8]
root
&Trie<K, V>
_correlation_id
CorrelationId
txn
&T
store
&S
key_bytes
&[u8]
root
&Trie<K, V>