MCPcopy Index your code
hub / github.com/ciphermodelabs/ciphercore / add_node

Method add_node

ciphercore-base/src/graphs.rs:3360–3449  ·  view source on GitHub ↗

Adds an operation node to the graph and returns it. # Arguments `node_dependencies` - vector of nodes necessary to perform the given operation `graph_dependencies` - vector of graphs necessary to perform the given operation `operation` - operation performed by the node # Returns New operation node that gets added

(
        &self,
        node_dependencies: Vec<Node>,
        graph_dependencies: Vec<Graph>,
        operation: Operation,
    )

Source from the content-addressed store, hash-verified

3358 ///
3359 /// New operation node that gets added
3360 pub fn add_node(
3361 &self,
3362 node_dependencies: Vec<Node>,
3363 graph_dependencies: Vec<Graph>,
3364 operation: Operation,
3365 ) -> Result<Node> {
3366 if self.is_finalized() {
3367 return Err(runtime_error!("Can't add a node to a finalized graph"));
3368 }
3369 for dependency in &node_dependencies {
3370 if dependency.get_graph() != *self
3371 || dependency.get_id() >= self.body.borrow().nodes.len() as u64
3372 || self.body.borrow().nodes[dependency.get_id() as usize] != *dependency
3373 {
3374 return Err(runtime_error!(
3375 "Can't add a node with invalid node dependencies"
3376 ));
3377 }
3378 }
3379 for dependency in &graph_dependencies {
3380 if !dependency.is_finalized() {
3381 return Err(runtime_error!(
3382 "Can't add a node with not finilized graph dependency"
3383 ));
3384 }
3385 if dependency.get_id() >= self.get_id() {
3386 return Err(runtime_error!(
3387 "Can't add a node with graph dependency with bigger id. {} >= {}",
3388 dependency.get_id(),
3389 self.get_id()
3390 ));
3391 }
3392 if dependency.get_context() != self.get_context() {
3393 return Err(runtime_error!(
3394 "Can't add a node with graph dependency from different context"
3395 ));
3396 }
3397 }
3398 let id = self.body.borrow().nodes.len() as u64;
3399 let result = Node {
3400 body: Arc::new(AtomicRefCell::new(NodeBody {
3401 graph: self.downgrade(),
3402 node_dependencies: node_dependencies.iter().map(|n| n.downgrade()).collect(),
3403 graph_dependencies: graph_dependencies.iter().map(|g| g.downgrade()).collect(),
3404 operation,
3405 id,
3406 })),
3407 };
3408 {
3409 let mut cell = self.body.borrow_mut();
3410 cell.nodes.push(result.clone());
3411 }
3412 let mut context_has_type_checker = false;
3413 {
3414 let context = self.get_context();
3415 let mut context_cell = context.body.borrow_mut();
3416 let type_checker = &mut context_cell.type_checker;
3417 if type_checker.is_some() {

Callers 15

check_join_typesFunction · 0.80
join_failFunction · 0.80
run_instantiation_passFunction · 0.80
inputMethod · 0.80
zerosMethod · 0.80
onesMethod · 0.80
addMethod · 0.80
subtractMethod · 0.80
multiplyMethod · 0.80
mixed_multiplyMethod · 0.80

Calls 11

is_finalizedMethod · 0.80
downgradeMethod · 0.80
cloneMethod · 0.80
remove_last_nodeMethod · 0.80
try_update_total_sizeMethod · 0.80
get_graphMethod · 0.45
get_idMethod · 0.45
get_contextMethod · 0.45
pushMethod · 0.45
get_typeMethod · 0.45

Tested by

no test coverage detected