Now truly finishing the refactoring
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
use super::bisimilarity_paige_tarkan::{bisimilarity, bisimilarity_ignore_labels};
|
use super::bisimilarity_paige_tarkan::{bisimilarity,
|
||||||
|
bisimilarity_ignore_labels};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn identity_paige_tarjan() {
|
fn identity_paige_tarjan() {
|
||||||
|
|||||||
@ -16,7 +16,7 @@ use petgraph::
|
|||||||
NodeRef,
|
NodeRef,
|
||||||
}};
|
}};
|
||||||
|
|
||||||
pub struct RSDot<'a, G>
|
pub struct Dot<'a, G>
|
||||||
where
|
where
|
||||||
G: IntoEdgeReferences + IntoNodeReferences + DataMap,
|
G: IntoEdgeReferences + IntoNodeReferences + DataMap,
|
||||||
{
|
{
|
||||||
@ -30,14 +30,14 @@ static TYPE: [&str; 2] = ["graph", "digraph"];
|
|||||||
static EDGE: [&str; 2] = ["--", "->"];
|
static EDGE: [&str; 2] = ["--", "->"];
|
||||||
static INDENT: &str = " ";
|
static INDENT: &str = " ";
|
||||||
|
|
||||||
impl<'a, G> RSDot<'a, G>
|
impl<'a, G> Dot<'a, G>
|
||||||
where
|
where
|
||||||
G: IntoNodeReferences + IntoEdgeReferences + DataMap,
|
G: IntoNodeReferences + IntoEdgeReferences + DataMap,
|
||||||
{
|
{
|
||||||
/// Create a `Dot` formatting wrapper with default configuration.
|
/// Create a `Dot` formatting wrapper with default configuration.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(graph: G) -> Self {
|
pub fn new(graph: G) -> Self {
|
||||||
RSDot {
|
Dot {
|
||||||
graph,
|
graph,
|
||||||
get_edge_attributes: &|_, _| String::new(),
|
get_edge_attributes: &|_, _| String::new(),
|
||||||
get_node_attributes: &|_, _| String::new(),
|
get_node_attributes: &|_, _| String::new(),
|
||||||
@ -49,7 +49,7 @@ where
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn with_config(graph: G, config: &'a [Config]) -> Self {
|
pub fn with_config(graph: G, config: &'a [Config]) -> Self {
|
||||||
let config = Configs::extract(config);
|
let config = Configs::extract(config);
|
||||||
RSDot {
|
Dot {
|
||||||
graph,
|
graph,
|
||||||
get_edge_attributes: &|_, _| String::new(),
|
get_edge_attributes: &|_, _| String::new(),
|
||||||
get_node_attributes: &|_, _| String::new(),
|
get_node_attributes: &|_, _| String::new(),
|
||||||
@ -65,7 +65,7 @@ where
|
|||||||
get_node_attributes: &'a dyn Fn(G, G::NodeRef) -> String,
|
get_node_attributes: &'a dyn Fn(G, G::NodeRef) -> String,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let config = Configs::extract(config);
|
let config = Configs::extract(config);
|
||||||
RSDot {
|
Dot {
|
||||||
graph,
|
graph,
|
||||||
get_edge_attributes,
|
get_edge_attributes,
|
||||||
get_node_attributes,
|
get_node_attributes,
|
||||||
@ -167,7 +167,7 @@ macro_rules! make_config_struct {
|
|||||||
|
|
||||||
make_config_struct!();
|
make_config_struct!();
|
||||||
|
|
||||||
impl<G> RSDot<'_, G>
|
impl<G> Dot<'_, G>
|
||||||
where
|
where
|
||||||
G: IntoNodeReferences + IntoEdgeReferences + NodeIndexable + GraphProp + DataMap,
|
G: IntoNodeReferences + IntoEdgeReferences + NodeIndexable + GraphProp + DataMap,
|
||||||
{
|
{
|
||||||
@ -254,7 +254,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G> fmt::Display for RSDot<'_, G>
|
impl<G> fmt::Display for Dot<'_, G>
|
||||||
where
|
where
|
||||||
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp + DataMap,
|
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp + DataMap,
|
||||||
G::EdgeWeight: fmt::Display,
|
G::EdgeWeight: fmt::Display,
|
||||||
@ -265,7 +265,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G> fmt::LowerHex for RSDot<'_, G>
|
impl<G> fmt::LowerHex for Dot<'_, G>
|
||||||
where
|
where
|
||||||
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp + DataMap,
|
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp + DataMap,
|
||||||
G::EdgeWeight: fmt::LowerHex,
|
G::EdgeWeight: fmt::LowerHex,
|
||||||
@ -276,7 +276,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G> fmt::UpperHex for RSDot<'_, G>
|
impl<G> fmt::UpperHex for Dot<'_, G>
|
||||||
where
|
where
|
||||||
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp + DataMap,
|
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp + DataMap,
|
||||||
G::EdgeWeight: fmt::UpperHex,
|
G::EdgeWeight: fmt::UpperHex,
|
||||||
@ -287,7 +287,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G> fmt::Debug for RSDot<'_, G>
|
impl<G> fmt::Debug for Dot<'_, G>
|
||||||
where
|
where
|
||||||
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp + DataMap,
|
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp + DataMap,
|
||||||
G::EdgeWeight: fmt::Debug,
|
G::EdgeWeight: fmt::Debug,
|
||||||
@ -1,5 +1,6 @@
|
|||||||
//! Definitions for generating graphs from a simulation.
|
//! Definitions for generating graphs from a simulation.
|
||||||
|
|
||||||
|
use petgraph::visit::{IntoEdgeReferences, IntoNodeReferences};
|
||||||
use petgraph::{Graph, Directed};
|
use petgraph::{Graph, Directed};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
@ -437,8 +438,6 @@ impl EdgeDisplay {
|
|||||||
|
|
||||||
|
|
||||||
// Node ------------------------------------------------------------------------
|
// Node ------------------------------------------------------------------------
|
||||||
use petgraph::visit::{IntoEdgeReferences, IntoNodeReferences};
|
|
||||||
|
|
||||||
type RSdotGraph = Graph<String, String, Directed, u32>;
|
type RSdotGraph = Graph<String, String, Directed, u32>;
|
||||||
type RSformatNodeTy<'a> =
|
type RSformatNodeTy<'a> =
|
||||||
dyn Fn(
|
dyn Fn(
|
||||||
|
|||||||
@ -16,7 +16,7 @@ pub mod bisimilarity;
|
|||||||
pub mod frequency;
|
pub mod frequency;
|
||||||
pub mod graph;
|
pub mod graph;
|
||||||
pub mod presets;
|
pub mod presets;
|
||||||
pub mod rsdot;
|
pub mod dot;
|
||||||
pub mod serialize;
|
pub mod serialize;
|
||||||
pub mod transitions;
|
pub mod transitions;
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,6 @@ use std::rc::Rc;
|
|||||||
use super::*;
|
use super::*;
|
||||||
use super::graph::MapEdges;
|
use super::graph::MapEdges;
|
||||||
use super::set::Set;
|
use super::set::Set;
|
||||||
use super::system;
|
|
||||||
use super::translator::Translator;
|
use super::translator::Translator;
|
||||||
|
|
||||||
use super::super::grammar;
|
use super::super::grammar;
|
||||||
@ -626,7 +625,7 @@ pub fn dot(
|
|||||||
let edge_formatter =
|
let edge_formatter =
|
||||||
edge_color.generate(Rc::clone(&graph));
|
edge_color.generate(Rc::clone(&graph));
|
||||||
|
|
||||||
let dot = rsdot::RSDot::with_attr_getters(
|
let dot = dot::Dot::with_attr_getters(
|
||||||
&modified_graph,
|
&modified_graph,
|
||||||
&[],
|
&[],
|
||||||
&edge_formatter,
|
&edge_formatter,
|
||||||
|
|||||||
@ -20,22 +20,22 @@ pub struct Translator {
|
|||||||
|
|
||||||
impl Translator {
|
impl Translator {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Translator {
|
Translator {
|
||||||
strings: HashMap::from([("*".into(), 0)]),
|
strings: HashMap::from([("*".into(), 0)]),
|
||||||
reverse: HashMap::from([(0, "*".into())]),
|
reverse: HashMap::from([(0, "*".into())]),
|
||||||
last_id: 1,
|
last_id: 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// converts a string into an id
|
/// converts a string into an id
|
||||||
pub fn encode(&mut self, s: impl Into<String>) -> IdType {
|
pub fn encode(&mut self, s: impl Into<String>) -> IdType {
|
||||||
let s = s.into();
|
let s = s.into();
|
||||||
let id = *(self.strings.entry(s.clone()).or_insert({
|
let id = *(self.strings.entry(s.clone()).or_insert({
|
||||||
self.last_id += 1;
|
self.last_id += 1;
|
||||||
self.last_id
|
self.last_id
|
||||||
}));
|
}));
|
||||||
self.reverse.insert(id, s.clone());
|
self.reverse.insert(id, s.clone());
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode_not_mut(&self, s: impl Into<String>) -> Option<IdType> {
|
pub fn encode_not_mut(&self, s: impl Into<String>) -> Option<IdType> {
|
||||||
@ -44,15 +44,15 @@ impl Translator {
|
|||||||
|
|
||||||
/// converts an id into the corresponding string
|
/// converts an id into the corresponding string
|
||||||
pub fn decode(&self, el: IdType) -> Option<String> {
|
pub fn decode(&self, el: IdType) -> Option<String> {
|
||||||
self.reverse
|
self.reverse
|
||||||
.get(&el)
|
.get(&el)
|
||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Translator {
|
impl Default for Translator {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Translator::new()
|
Translator::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,5 +101,3 @@ impl<'a, T> Formatter<'a, T> {
|
|||||||
Self { data, translator }
|
Self { data, translator }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user