From 1455da10f943e2aa1bdf26fb2697dafccc61e073 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Fri, 2 Jun 2023 14:51:25 +0800 Subject: viz: finished decycle algorithm --- viz/src/lib.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'viz/src/lib.rs') 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; + fn deserialize(bytes: impl AsRef<[u8]>) -> Result, Self::Error>; } -#[cfg(test)] -mod tests { - use super::*; +#[allow(unused)] +pub fn serialize( + actions: Vec, + filename: &Path, + final_p: bool, +) -> Result<(), ::Error> { + Ok(()) +} - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); +pub fn deserialize( + bytes: impl AsRef<[u8]>, +) -> Result<(Vec, ::Karmani), ::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. -- cgit v1.2.3-18-g5258