Skip to main content

MemoryApplier

Struct MemoryApplier 

Source
pub struct MemoryApplier { /* private fields */ }
Expand description

The stock Applier: it keeps nodes in memory under ids that stay stable for the life of the node.

Implementations§

Source§

impl MemoryApplier

Source

pub fn new() -> Self

Creates an applier with no nodes.

Source

pub fn slots_handle(&self) -> Rc<RefCell<SlotTable>>

The slot table that composition during layout writes to, shared with the layout pass that lends this applier.

Source

pub fn scene_node_attached_to( &mut self, node_id: NodeId, root: NodeId, ) -> Option<NodeId>

Resolves a scene-scope candidate the way structural records are resolved: to its nearest non-virtual ancestor, and only while still attached to root. A node detached after recording must not reach the scoped scene update — an id the graph cannot resolve forces it to give up and rebuild the whole scene.

Source

pub fn scene_nodes_attached_to( &mut self, nodes: impl IntoIterator<Item = NodeId>, root: NodeId, ) -> Vec<Option<NodeId>>

Self::scene_node_attached_to for each of nodes, in order, with every ancestor looked up at most once: a batch costs the distinct ancestors of its nodes, not each node’s depth.

Source

pub fn scene_nodes_attached_to_into( &mut self, nodes: impl IntoIterator<Item = NodeId>, root: NodeId, output: &mut Vec<Option<NodeId>>, scratch: &mut SceneNodeAttachmentScratch, )

Fills output with Self::scene_nodes_attached_to results, reusing its storage and the ancestry cache in scratch across batches.

Each distinct ancestor is inspected at most once per call. The cache is cleared for each call, so graph mutations are observed by the next batch.

use cranpose_core::{MemoryApplier, NodeId, SceneNodeAttachmentScratch};

let mut applier = MemoryApplier::new();
let mut scratch = SceneNodeAttachmentScratch::default();
let mut attached: Vec<Option<NodeId>> = Vec::new();
let root = NodeId::default();
applier.scene_nodes_attached_to_into([], root, &mut attached, &mut scratch);
assert!(attached.is_empty());
Source

pub fn take_structural_change_parents_attached_to( &mut self, root: NodeId, ) -> Vec<NodeId> ⓘ

Drains the parents recorded via Applier::record_structural_change, keeping only nodes still attached to root (a parent that was itself removed is covered by its own surviving ancestor’s record). A virtual parent — a subcompose slot wrapper the render graph never contains — is reported as its nearest non-virtual ancestor: that is the node whose graph child set the change altered, and an id the graph cannot resolve would force the scoped scene update to give up and rebuild.

Source

pub fn take_structural_change_parents_into(&mut self, output: &mut Vec<NodeId>)

Takes the recorded structural-change candidates into reusable storage. Candidates are not resolved or attachment-filtered; callers that route them into scenes should use Self::scene_nodes_attached_to_into.

use cranpose_core::MemoryApplier;

let mut applier = MemoryApplier::new();
let mut nodes = Vec::new();
applier.take_structural_change_parents_into(&mut nodes);
assert!(nodes.is_empty());
Source

pub fn with_node<N: Node + 'static, R>( &mut self, id: NodeId, f: impl FnOnce(&mut N) -> R, ) -> Result<R, NodeError>

Runs f on the node id as an N. Returns an error if the node does not exist or is not an N.

Source

pub fn len(&self) -> usize

Returns the number of live nodes.

Source

pub fn capacity(&self) -> usize

Returns the number of slots in the dense node table, both live and free.

Source

pub fn tombstone_count(&self) -> usize

Returns the number of free slots in the dense node table.

Source

pub fn freelist_len(&self) -> usize

Returns the number of freed table slots that new nodes can reuse.

Source

pub fn debug_recycled_node_count(&self) -> usize

Returns the number of pooled recycled nodes of all types.

Source

pub fn debug_recycled_node_count_for<N: Node + 'static>(&self) -> usize

Returns the number of pooled recycled nodes of type N.

Source

pub fn debug_stats(&self) -> MemoryApplierDebugStats

Returns the sizes of the applier’s tables, for leak and memory checks.

Source

pub fn is_empty(&self) -> bool

Returns true if the applier holds no live nodes.

Source

pub fn for_each_node_mut(&mut self, visit: impl FnMut(&mut dyn Node))

Calls visit with every live node, dense and high-id alike.

Source

pub fn debug_live_node_heap_bytes(&self) -> usize

Returns the heap bytes that the live nodes take, including what they own.

Source

pub fn debug_recycled_node_heap_bytes(&self) -> usize

Returns the heap bytes that the pooled recycled nodes take, including what they own.

Source

pub fn set_runtime_handle(&mut self, handle: RuntimeHandle)

Gives the applier the runtime of its composition, so code that runs during layout with only the applier in hand can reach the runtime.

Source

pub fn clear_runtime_handle(&mut self)

Removes the runtime handle.

Source

pub fn runtime_handle(&self) -> Option<RuntimeHandle>

Returns the runtime handle set with set_runtime_handle, if any.

Source

pub fn dump_tree(&self, root: Option<NodeId>) -> String

Returns an indented text outline of the tree below root for debugging, or a (no root) line when root is None.

Source

pub fn get_ref(&self, id: NodeId) -> Result<&dyn Node, NodeError>

Borrows a live node without requiring exclusive access to the tree. Returns NodeError::Missing when id does not name a live node.

Trait Implementations§

Source§

impl Applier for MemoryApplier

Source§

fn record_structural_change(&mut self, parent_id: NodeId)

Records that parent_id’s child list changed structurally this frame (insert, remove, move, or reparent). Incremental scene consumers drain the recorded parents and re-patch those subtrees so removed nodes are evicted from a persistent render graph even when the frame’s scene update is otherwise scoped to unrelated dirty nodes.
Source§

fn create(&mut self, node: Box<dyn Node>) -> NodeId

Stores node and returns its new id.
Source§

fn node_generation(&self, id: NodeId) -> u32

Returns the current generation for a node index. Generation is incremented when an index is reused from the freelist, preventing stale slot entries from matching recycled nodes.
Source§

fn get_mut(&mut self, id: NodeId) -> Result<&mut dyn Node, NodeError>

Returns the node id for change, or an error if there is none.
Source§

fn remove(&mut self, id: NodeId) -> Result<(), NodeError>

Removes the node id and the nodes below it.
Source§

fn begin_bubble_batch(&mut self)

Opens a batch of commands, in which no layout pass runs: within it a dirty bubble may stop at an ancestor an earlier one passed (Self::note_bubble_pass). Batches nest.
Source§

fn end_bubble_batch(&mut self)

Closes the batch Self::begin_bubble_batch opened.
Source§

fn forget_bubble_passes(&mut self)

Forgets what the open batch’s bubbles passed: a node changed its parent, or other code ran, so their marks may no longer reach the root.
Source§

fn note_bubble_pass(&mut self, id: NodeId, flags: u8) -> bool

Notes that a dirty bubble carrying flags passed the ancestor id. true when one carrying all of them passed it earlier in the open batch: that one marked every ancestor above id, so this one may stop. An applier that keeps no notes answers false.
Source§

fn insert_with_id( &mut self, id: NodeId, node: Box<dyn Node>, ) -> Result<(), NodeError>

Inserts a node with a pre-assigned ID. Read more
Source§

fn insert_recycled_node_or_create( &mut self, stable_id: NodeId, node: Box<dyn Node>, ) -> RecycledNodeInsertion

Reinserts a recycled node at its retained stable ID, or creates a fresh ID if that retained ID is no longer available.
Source§

fn compact(&mut self)

Trim trailing tombstones/unused capacity after structural changes.
Source§

fn take_recycled_node(&mut self, key: TypeId) -> Option<RecycledNode>

Returns a previously recycled node shell and its stable ID for the requested concrete type.
Source§

fn set_recycled_node_origin(&mut self, id: NodeId, warm_origin: bool)

Marks whether a reinserted recycled node originated from the warm recycle path.
Source§

fn seed_recycled_node_shell( &mut self, key: TypeId, recycle_pool_limit: Option<usize>, shell: Box<dyn Node>, )

Seeds a warm recyclable shell for future reuse without requiring a prior removal.
Source§

fn record_fresh_recyclable_creation(&mut self, key: TypeId)

Records that the current apply pass had to allocate a fresh recyclable shell for this type.
Source§

fn clear_recycled_nodes(&mut self)

Drops any recyclable shells that should not survive beyond the current apply pass.
Source§

fn as_any(&self) -> &dyn Any
where Self: Sized,

Returns the applier as Any, for downcasting to its concrete type.
Source§

fn as_any_mut(&mut self) -> &mut dyn Any
where Self: Sized,

Returns the applier as Any, for downcasting to its concrete type.
Source§

impl Default for MemoryApplier

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.