Genome builder basics
This commit is contained in:
parent
23d9ab696c
commit
fdb5e59eff
5 changed files with 86 additions and 5 deletions
|
|
@ -1,8 +1,8 @@
|
|||
use crate::genetics::{gene::Gene, edge::Edge};
|
||||
|
||||
pub struct PlantGenome {
|
||||
genes: Vec<Gene>,
|
||||
edges: Vec<Edge>
|
||||
pub(crate) genes: Vec<Gene>,
|
||||
pub(crate) edges: Vec<Edge>
|
||||
}
|
||||
|
||||
impl PlantGenome {
|
||||
|
|
@ -16,13 +16,13 @@ impl PlantGenome {
|
|||
if let None = parent && self.genes.len() > 0 {
|
||||
return Some(PlantGenomeInsertError::RootExists);
|
||||
}
|
||||
if let Some(_) = self.genes.iter().find(|g| **g == gene){
|
||||
if self.genes.contains(&gene){
|
||||
return Some(PlantGenomeInsertError::GeneExists);
|
||||
}
|
||||
|
||||
if let Some(parent_gene) = parent {
|
||||
let edge = Edge::new(parent_gene,gene.clone());
|
||||
if let Some(_) = self.edges.iter().find(|e| **e == edge) {
|
||||
if self.edges.contains(&edge) {
|
||||
return Some(PlantGenomeInsertError::EdgeExists);
|
||||
}
|
||||
self.edges.push(edge);
|
||||
|
|
@ -32,7 +32,7 @@ impl PlantGenome {
|
|||
self.update_graph();
|
||||
return None;
|
||||
}
|
||||
fn update_graph(&mut self) {
|
||||
pub(crate) fn update_graph(&mut self) {
|
||||
// Sort by parent to guarantee root at [0]
|
||||
self.edges.sort();
|
||||
}
|
||||
|
|
@ -46,6 +46,7 @@ impl PlantGenome {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PlantGenomeInsertError {
|
||||
GeneExists,
|
||||
EdgeExists,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue