I begin create a Graph structure
This commit is contained in:
commit
e18b31eece
|
@ -0,0 +1 @@
|
||||||
|
/target
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/untitled.iml" filepath="$PROJECT_DIR$/.idea/untitled.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="EMPTY_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,7 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "untitled"
|
||||||
|
version = "0.1.0"
|
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "untitled"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
|
@ -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]);
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue