logos.std.data.persistent.bt.mutate

Module std · package logos-std

Types

structInsertOutcome

struct InsertOutcome

Outcome of a recursive insert: whether an existing key was replaced, and whether the visited node split.

Fields

hit: bool

True if key already existed (value was replaced, not inserted).

right: Option

The new right sibling produced by a split.

right_max: K::ViewInStore

Max key of right’s subtree, valid only when right_max_present.

right_max_present: bool

True if right_max holds a valid value (K isn’t Default-able in general).

split: bool

True if the node split during this insert; right/right_max* are then valid.

structRemoveOutcome

struct RemoveOutcome

Outcome of a recursive remove: whether the key was found, and whether the visited node underflowed and needs the parent to rebalance.

Fields

hit: bool

True if the key was found and removed.

underflow: bool

True if the node is now below min_keys and the parent must rebalance it.

Functions

fnbt_insert

fn bt_insert(root: &mut Arc<dyn BTreeNode>, key: K::ViewInStore, val: V::ViewInStore, qkey: K::ViewInStore, cur_snapshot_id: <cfg-slot-type>, id_ctr_p: *mut <cfg-slot-type>) -> Option

Inserts key/val into the tree rooted at root, growing a new root when the old root splits. Returns the previous value if key already existed (mirrors Rust BTreeMap::insert).

fnbt_remove

fn bt_remove(root: &mut Arc<dyn BTreeNode>, qkey: K::ViewInStore, cur_snapshot_id: <cfg-slot-type>, id_ctr_p: *mut <cfg-slot-type>) -> bool

Removes qkey from the tree rooted at root, collapsing the root while it’s a branch with a single remaining child. Returns true if the key was found and removed.

fninsert_rec

fn insert_rec(arc: &mut Arc<dyn BTreeNode>, key: K::ViewInStore, val: V::ViewInStore, qkey: K::ViewInStore, cur_snapshot_id: <cfg-slot-type>, id_ctr_p: *mut <cfg-slot-type>) -> InsertOutcome<K, STORE_CFG, CFG>

Recursively inserts key/val (positioned by qkey) into the subtree rooted at arc, CoW-cloning any node not owned by cur_snapshot_id and splitting on overflow. Returns an InsertOutcome reporting whether an existing key was replaced and whether arc split.

fnnode_max_key

fn node_max_key(arc: &Arc<dyn BTreeNode>) -> K::ViewInStore

Returns the max key of arc’s subtree, relying on the leaf/branch max-key invariant.

fnrebalance_branch_child

fn rebalance_branch_child(parent_branch: *mut BranchNode<K, STORE_CFG, CFG>, i: i64, cur_snapshot_id: <cfg-slot-type>, id_ctr_p: *mut <cfg-slot-type>) -> void

Rebalances branch child i of parent_branch after underflow: merges with a sibling when the combined length fits max_keys, otherwise borrows one (key, child) pair from whichever sibling has more keys.

fnrebalance_leaf_child

fn rebalance_leaf_child(parent_branch: *mut BranchNode<K, STORE_CFG, CFG>, i: i64, cur_snapshot_id: <cfg-slot-type>, id_ctr_p: *mut <cfg-slot-type>) -> void

Rebalances leaf child i of parent_branch after underflow: merges with a sibling when the combined length fits max_keys, otherwise borrows one entry from whichever sibling has more keys.

fnremove_rec

fn remove_rec(arc: &mut Arc<dyn BTreeNode>, qkey: K::ViewInStore, cur_snapshot_id: <cfg-slot-type>, id_ctr_p: *mut <cfg-slot-type>) -> RemoveOutcome

Recursively removes qkey from the subtree rooted at arc, CoW-cloning any node not owned by cur_snapshot_id and rebalancing children that underflow. Returns a RemoveOutcome reporting whether the key was found and whether arc itself underflowed.

fnsplit_branch

fn split_branch(branch: *mut BranchNode<K, STORE_CFG, CFG>, new_id: <cfg-slot-type>, snapshot_id: <cfg-slot-type>) -> Arc<dyn BTreeNode>

Splits branch in half, moving the upper half of keys/children/subtree_size into a freshly allocated right branch; branch keeps the lower half.

fnsplit_leaf

fn split_leaf(leaf: *mut LeafNode<K, V, STORE_CFG, CFG>, new_id: <cfg-slot-type>, snapshot_id: <cfg-slot-type>) -> Arc<dyn BTreeNode>

Splits leaf in half, moving the upper half of entries into a freshly allocated right leaf; leaf keeps the lower half. Panics if keys.len() != vals.len().

fnvec_arc_insert_at

fn vec_arc_insert_at(v: *mut Vec<Arc<dyn BTreeNode>>, idx: i64, new_arc: Arc<dyn BTreeNode>) -> void

Inserts new_arc at index idx in v, shifting later elements right. Caller must ensure idx <= v.len(); the shift is whole-handle swaps (no refcount churn).