Gigagraph

This commit is contained in:
Rendo 2025-11-06 18:42:08 +05:00
commit d07c660e2a
6 changed files with 24 additions and 50 deletions

View file

@ -0,0 +1,12 @@
use crate::node::Node;
pub struct GraphModifier<'a> {
root: &'a Node,
}
impl<'a> GraphModifier<'a> {
pub fn new(root: &Node) -> GraphModifier {
GraphModifier { root }
}
}

37
src/node/mod.rs Normal file
View file

@ -0,0 +1,37 @@
use crate::node::graph_modifier::GraphModifier;
mod graph_modifier;
pub struct Node {
children: Vec<Node>,
function: fn(Vec<f64>) -> f64,
}
impl Node {
pub fn new(children: Option<Vec<Node>>, function: Option<fn(Vec<f64>) -> f64>) -> Self {
Self {
children: children.unwrap_or(vec![]),
function: function.unwrap_or(|_| 0f64),
}
}
pub fn empty() -> Self {
Self {
children: vec![],
function: |_| 0f64,
}
}
pub fn get_value(&self) -> f64 {
if self.children.len() == 0 {
return (self.function)(vec![0f64]);
}
let mut inputs: Vec<f64> = vec![];
for node in &self.children {
inputs.push(node.get_value());
}
return (self.function)(inputs);
}
pub fn modify_tree(&self) -> GraphModifier {
GraphModifier::new(self)
}
}