I begin create a Graph structure

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

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

8
.idea/.gitignore vendored Normal file
View File

@ -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

8
.idea/modules.xml Normal file
View File

@ -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>

11
.idea/untitled.iml Normal file
View File

@ -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>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

7
Cargo.lock generated Normal file
View File

@ -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"

8
Cargo.toml Normal file
View File

@ -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]

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]);
}