MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / recover_original_graph

Method recover_original_graph

ciphercore-base/src/graphs.rs:3747–3790  ·  view source on GitHub ↗
(
        serializable_graph: SerializableGraph,
        context: Context,
    )

Source from the content-addressed store, hash-verified

3745
3746impl SerializableContextBody {
3747 fn recover_original_graph(
3748 serializable_graph: SerializableGraph,
3749 context: Context,
3750 ) -> Result<Graph> {
3751 let result_graph = context.create_graph()?;
3752 for node in &serializable_graph.nodes {
3753 let mut node_dependencies = vec![];
3754 for id in &node.node_dependencies {
3755 let current_nodes = &result_graph.body.borrow().nodes;
3756 if *id >= current_nodes.len() as u64 {
3757 return Err(runtime_error!("Non-existent node dependency"));
3758 }
3759 node_dependencies.push(current_nodes[*id as usize].clone());
3760 }
3761 let mut graph_dependencies = vec![];
3762 for id in &node.graph_dependencies {
3763 let context = result_graph.get_context();
3764 let current_graphs = &context.body.borrow().graphs;
3765 if *id >= current_graphs.len() as u64 {
3766 return Err(runtime_error!("Non-existent graph dependency"));
3767 }
3768 graph_dependencies.push(current_graphs[*id as usize].clone());
3769 }
3770 result_graph.add_node(
3771 node_dependencies,
3772 graph_dependencies,
3773 node.operation.clone(),
3774 )?;
3775 }
3776 if let Some(id) = serializable_graph.output_node {
3777 let rebuilt_output_node = {
3778 let current_nodes = &result_graph.body.borrow().nodes;
3779 if id >= current_nodes.len() as u64 {
3780 return Err(runtime_error!("Non-existent output node"));
3781 }
3782 current_nodes[id as usize].clone()
3783 };
3784 result_graph.set_output_node(rebuilt_output_node)?;
3785 }
3786 if serializable_graph.finalized {
3787 result_graph.finalize()?;
3788 }
3789 Ok(result_graph)
3790 }
3791
3792 fn recover_original_context(&self) -> Result<Context> {
3793 let result_context = create_context()?;

Callers

nothing calls this directly

Calls 7

cloneMethod · 0.80
add_nodeMethod · 0.80
create_graphMethod · 0.45
pushMethod · 0.45
get_contextMethod · 0.45
set_output_nodeMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected