53 lines
1023 B
Rust
53 lines
1023 B
Rust
|
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]);
|
||
|
|
||
|
}
|