summaryrefslogtreecommitdiff
path: root/viz/src/lib.rs
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-06-02 14:51:25 +0800
committerJSDurand <mmemmew@gmail.com>2023-06-02 14:51:25 +0800
commit1455da10f943e2aa1bdf26fb2697dafccc61e073 (patch)
tree7d6c51a1040fc6b05bf3a19386e05016f8c0ab0f /viz/src/lib.rs
parent83c66eb77c6affaa9ac4fabd808556613c5bf973 (diff)
viz: finished decycle algorithm
Diffstat (limited to 'viz/src/lib.rs')
-rw-r--r--viz/src/lib.rs54
1 files changed, 45 insertions, 9 deletions
diff --git a/viz/src/lib.rs b/viz/src/lib.rs
index b40c78a..9a15187 100644
--- a/viz/src/lib.rs
+++ b/viz/src/lib.rs
@@ -15,17 +15,53 @@
extern crate graph;
-pub fn add(left: usize, right: usize) -> usize {
- left + right
+use graph::Graph;
+
+use std::{error::Error, path::Path};
+
+pub mod strong_component;
+
+pub mod decycle;
+
+pub trait Action: Sized {
+ type Karmani: Graph;
+
+ type Error: Error;
+
+ fn perform(&self, obj: &mut Self::Karmani) -> Result<(), Self::Error>;
+
+ fn serialize(&self) -> Vec<u8>;
+ fn deserialize(bytes: impl AsRef<[u8]>) -> Result<Option<(Self, usize)>, Self::Error>;
}
-#[cfg(test)]
-mod tests {
- use super::*;
+#[allow(unused)]
+pub fn serialize<A: Action>(
+ actions: Vec<A>,
+ filename: &Path,
+ final_p: bool,
+) -> Result<(), <A as Action>::Error> {
+ Ok(())
+}
- #[test]
- fn it_works() {
- let result = add(2, 2);
- assert_eq!(result, 4);
+pub fn deserialize<A: Action>(
+ bytes: impl AsRef<[u8]>,
+) -> Result<(Vec<A>, <A as Action>::Karmani), <A as Action>::Error> {
+ let mut bytes = bytes.as_ref();
+
+ let mut result_actions = Vec::new();
+ let mut result_karmanayah = Default::default();
+
+ while let Some((action, offset)) = A::deserialize(bytes)? {
+ action.perform(&mut result_karmanayah)?;
+
+ result_actions.push(action);
+
+ bytes = &bytes[offset..];
}
+
+ let result = (result_actions, result_karmanayah);
+
+ Ok(result)
}
+
+// TODO: Figure out the parts to display graphs.