Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. use std::collections::HashMap;
  2.  
  3. pub struct CircuitBuilder<'a> {
  4. nodes: HashMap<String, Node<'a>>,
  5. nodes_is_no_ouput: HashMap<String, bool>,
  6. factory: LowBindingNodeFactory<'a>,
  7. }
  8.  
  9. #[derive(Clone)]
  10. enum Node<'a> {
  11. Not(NotGate<'a>),
  12. Signal(SignalGate)
  13. }
  14.  
  15. impl<'a> Node<'a> {
  16. fn add_input(&mut self, node: &'a Node) {
  17. match self {
  18. Node::Not(gate) => gate.inputs.push(node),
  19. _ => ()
  20. }
  21. }
  22. }
  23.  
  24. #[derive(Clone)]
  25. struct NotGate<'a> {
  26. inputs: Vec<&'a Node<'a>>,
  27. }
  28.  
  29. #[derive(Clone)]
  30. struct SignalGate;
  31.  
  32. struct LowBindingNodeFactory<'a>(&'a str);
  33.  
  34. impl<'a> CircuitBuilder<'a> {
  35. fn connect_inputs(
  36. &mut self,
  37. node_name: String,
  38. node_links: Vec<String>,
  39. ) -> Option<&'static str> {
  40. for node_link in node_links.iter() {
  41. self.nodes_is_no_ouput.insert(node_link.clone(), true);
  42. match self.nodes.get_mut(&node_name.clone()) {
  43. Some(mut_node) => mut_node.add_input(&self.nodes[&node_link.clone()]),
  44. None => (),
  45. }
  46. //mut_node.add_input(new_node);
  47. //*self.nodes.entry(&node_name.clone()).or_insert(42).add_input(&new_node);
  48. //self.nodes[&node_name.clone()].add_input(&new_node);
  49. }
  50. return None;
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement