Sets the name of a node. A given name should be unique. # Arguments `node` - node `name` - name of a node # Returns This context # Example ``` # use ciphercore_base::graphs::create_context; # use ciphercore_base::data_types::{scalar_type, BIT}; let c = create_context().unwrap(); let g = c.create_graph().unwrap(); let t = scalar_type(BIT); let n = g.input(t).unwrap(); c.set_node_name(n, "XOR
(&self, node: Node, name: &str)
| 4212 | /// c.set_node_name(n, "XOR").unwrap(); |
| 4213 | /// ``` |
| 4214 | pub fn set_node_name(&self, node: Node, name: &str) -> Result<Context> { |
| 4215 | if node.get_graph().get_context() != *self { |
| 4216 | return Err(runtime_error!( |
| 4217 | "The node to be named is in a different context" |
| 4218 | )); |
| 4219 | } |
| 4220 | if self.is_finalized() { |
| 4221 | return Err(runtime_error!( |
| 4222 | "Can't set a node name in a finalized context" |
| 4223 | )); |
| 4224 | } |
| 4225 | let node_id = node.get_id(); |
| 4226 | let graph_id = node.get_graph().get_id(); |
| 4227 | let mut cell = self.body.borrow_mut(); |
| 4228 | if cell.nodes_names.get(&(graph_id, node_id)).is_some() { |
| 4229 | return Err(runtime_error!("Can't set the node name twice")); |
| 4230 | } |
| 4231 | if cell.nodes_names_inverse.get(&graph_id).is_none() { |
| 4232 | cell.nodes_names_inverse.insert(graph_id, HashMap::new()); |
| 4233 | } |
| 4234 | let graph_map_inverse = cell |
| 4235 | .nodes_names_inverse |
| 4236 | .get_mut(&graph_id) |
| 4237 | .expect("Should not be here!"); |
| 4238 | if graph_map_inverse.get(name).is_some() { |
| 4239 | return Err(runtime_error!( |
| 4240 | "Node names must be unique (within the graph)" |
| 4241 | )); |
| 4242 | } |
| 4243 | graph_map_inverse.insert(name.to_owned(), node_id); |
| 4244 | cell.nodes_names |
| 4245 | .insert((graph_id, node_id), name.to_owned()); |
| 4246 | Ok(self.clone()) |
| 4247 | } |
| 4248 | |
| 4249 | /// Returns the name of a node. |
| 4250 | /// |