pub enum Node {
Leaf(Box<LeafNode>),
Internal(Box<InternalNode>),
}Expand description
In-memory CHK node — either a leaf with key/value entries or an
internal node referencing other nodes. Mirrors the Python
Node base class hierarchy (LeafNode | InternalNode).
Variants§
Implementations§
Source§impl Node
impl Node
Sourcepub fn key(&self) -> Option<&[u8]>
pub fn key(&self) -> Option<&[u8]>
(b"sha1:...",) key once the node has been serialised, else
None. Mirrors Python’s Node.key().
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Total number of leaf entries reachable through this node.
Mirrors Python’s Node.__len__.
Sourcepub fn maximum_size(&self) -> usize
pub fn maximum_size(&self) -> usize
Maximum byte size allowed for this node when serialised, or
0 for unlimited.
Sourcepub fn refs(&self) -> Result<Vec<Vec<u8>>, Error>
pub fn refs(&self) -> Result<Vec<Vec<u8>>, Error>
CHK references held by this node. Mirrors Node.refs:
leaves never reference other pages (returns []); internal
nodes return their children’s sha1 keys (delegates to
InternalNode::refs, which requires the node to have been
serialised).
Sourcepub fn map(
&mut self,
key: Vec<Vec<u8>>,
value: Vec<u8>,
) -> Result<MapResult, Error>
pub fn map( &mut self, key: Vec<Vec<u8>>, value: Vec<u8>, ) -> Result<MapResult, Error>
Insert (key, value) into this subtree (pure in-memory path).
For leaves, delegates to LeafNode::map. For internal nodes,
returns AssertionFailed — the recursive InternalNode path
needs the store and lives at Node::map_with_store. This
signature exists so LeafNode::split (which only ever creates
fresh in-memory sub-leaves) can recurse via Node::map
without a store argument.
Sourcepub fn serialise<S>(
&mut self,
store: &S,
cache: &dyn PageCache,
) -> Result<Vec<Vec<u8>>, Error>where
S: VersionedFiles + ?Sized,
pub fn serialise<S>(
&mut self,
store: &S,
cache: &dyn PageCache,
) -> Result<Vec<Vec<u8>>, Error>where
S: VersionedFiles + ?Sized,
Serialise this subtree to the store, returning every sha1 key
written (children first, then self). Mirrors Python’s
Node.serialise. Skips children that are unloaded (their
sha1 key is already canonical) or already serialised (key set).
Sourcepub fn unmap_with_store<S>(
self,
store: &S,
cache: &dyn PageCache,
key: &[Vec<u8>],
check_remap: bool,
) -> Result<Node, Error>where
S: VersionedFiles + ?Sized,
pub fn unmap_with_store<S>(
self,
store: &S,
cache: &dyn PageCache,
key: &[Vec<u8>],
check_remap: bool,
) -> Result<Node, Error>where
S: VersionedFiles + ?Sized,
Recursive remove that may demand-load child pages. Returns the replacement node (possibly the same one, possibly a collapsed leaf, possibly the single remaining child if the internal node lost all but one child).
Mirrors Python’s polymorphic unmap(store, key, check_remap).
Raises KeyError-equivalent (AssertionFailed) when the key
is not present.
Sourcepub fn map_with_store<S>(
&mut self,
store: &S,
cache: &dyn PageCache,
key: Vec<Vec<u8>>,
value: Vec<u8>,
) -> Result<MapResult, Error>where
S: VersionedFiles + ?Sized,
pub fn map_with_store<S>(
&mut self,
store: &S,
cache: &dyn PageCache,
key: Vec<Vec<u8>>,
value: Vec<u8>,
) -> Result<MapResult, Error>where
S: VersionedFiles + ?Sized,
Recursive insert that may demand-load child pages from the
store. Mirrors Python’s polymorphic dispatch:
LeafNode.map(store, key, value) for leaves;
InternalNode.map(store, key, value) for internal nodes
(which descends into the matching child, possibly creating a
new wrapping parent if the key falls outside the current
search prefix).
May replace *self with a new node (e.g. an internal node
promoting itself into a larger parent, or a parent collapsing
back into a leaf after _check_remap).
Sourcepub fn iteritems<S>(
&mut self,
store: &S,
cache: &dyn PageCache,
key_filter: Option<&[Vec<Vec<u8>>]>,
) -> Result<Vec<(Vec<Vec<u8>>, Vec<u8>)>, Error>where
S: VersionedFiles + ?Sized,
pub fn iteritems<S>(
&mut self,
store: &S,
cache: &dyn PageCache,
key_filter: Option<&[Vec<Vec<u8>>]>,
) -> Result<Vec<(Vec<Vec<u8>>, Vec<u8>)>, Error>where
S: VersionedFiles + ?Sized,
Iterate (key, value) pairs in this subtree matching
key_filter. Mirrors Python’s polymorphic iteritems:
leaves yield directly; internal nodes recurse through
iter_nodes, demand-loading children as needed.