I begin create a Graph structure

This commit is contained in:
2023-09-17 21:21:14 +04:00
commit e18b31eece
8 changed files with 102 additions and 0 deletions

53
src/main.rs Normal file
View File

@@ -0,0 +1,53 @@
mod graph {
use std::collections::{HashMap, HashSet};
use std::vec::Vec;
pub struct Graph {
frame_graph : HashMap<u32, Vec<u32>>,
flags_graph : HashSet<(u32, bool)>
}
impl Graph {
pub fn new() -> Graph {
Graph{
frame_graph : HashMap::new(),
flags_graph : HashSet::new(),
}
}
pub fn add(&mut self, parent : u32, children : Vec<u32>){
self.frame_graph.insert(parent, children);
self.flags_graph.insert((parent, false));
for &i in self.frame_graph.get(&parent).unwrap() {
self.flags_graph.insert((i, false));
}
}
pub fn get(&self) -> &Graph {
self.clone()
}
}
}
mod new_class{
use super::graph;
}
fn main(){
use crate::graph::Graph;
let mut graph : Graph = Graph::new();
graph.add(1, vec![2, 3, 4]);
graph.add(2, vec![9, 7, 6, 1]);
graph.add(6, vec![12, 11, 19]);
}