diff --git a/Cargo.lock b/Cargo.lock index 754ad4f..fdc7d2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,147 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - [[package]] name = "fapprox" version = "0.1.0" -dependencies = [ - "rand", -] - -[[package]] -name = "getrandom" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" -dependencies = [ - "cfg-if", - "libc", - "r-efi", - "wasip2", -] - -[[package]] -name = "libc" -version = "0.2.177" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" - -[[package]] -name = "ppv-lite86" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "proc-macro2" -version = "1.0.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.41" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "r-efi" -version = "5.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" - -[[package]] -name = "rand" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" -dependencies = [ - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" -dependencies = [ - "getrandom", -] - -[[package]] -name = "syn" -version = "2.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f17c7e013e88258aa9543dcbe81aca68a667a9ac37cd69c9fbc07858bfe0e2f" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "unicode-ident" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" - -[[package]] -name = "wasip2" -version = "1.0.1+wasi-0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" -dependencies = [ - "wit-bindgen", -] - -[[package]] -name = "wit-bindgen" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" - -[[package]] -name = "zerocopy" -version = "0.8.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.8.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] diff --git a/Cargo.toml b/Cargo.toml index 94fc960..31d57a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,4 +4,3 @@ version = "0.1.0" edition = "2024" [dependencies] -rand = "0.9.2" diff --git a/src/node/graph_modifier.rs b/src/node/graph_modifier.rs new file mode 100644 index 0000000..df429e4 --- /dev/null +++ b/src/node/graph_modifier.rs @@ -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 } + } + +} diff --git a/src/node/mod.rs b/src/node/mod.rs index 281cbee..6aaa697 100644 --- a/src/node/mod.rs +++ b/src/node/mod.rs @@ -1,6 +1,6 @@ -use crate::node::node_modifier::NodeModifier; +use crate::node::graph_modifier::GraphModifier; -mod node_modifier; +mod graph_modifier; pub struct Node { children: Vec, @@ -31,7 +31,7 @@ impl Node { return (self.function)(inputs); } - pub fn modify_tree<'a>(&'a mut self) -> NodeModifier<'a> { - NodeModifier::from_random(self) + pub fn modify_tree(&self) -> GraphModifier { + GraphModifier::new(self) } } diff --git a/src/node/node_modifier.rs b/src/node/node_modifier.rs deleted file mode 100644 index fb4b449..0000000 --- a/src/node/node_modifier.rs +++ /dev/null @@ -1,24 +0,0 @@ -use crate::node::Node; -use rand::random_range; - -const PICK_STOP_PROBABILITY: u8 = 2; - -pub struct NodeModifier<'a> { - picked_node: &'a mut Node, -} - -impl<'a> NodeModifier<'a> { - pub fn from_random(root: &'a mut Node) -> NodeModifier<'a> { - let mut selected = root; - while random_range(0..PICK_STOP_PROBABILITY) == PICK_STOP_PROBABILITY - 1 { - let len = selected.children.len(); - selected = &mut selected.children[random_range(0..len)]; - } - NodeModifier { - picked_node: selected, - } - } - pub fn from_node(node: &'a mut Node) -> NodeModifier<'a> { - NodeModifier { picked_node: node } - } -}