From 5b2420de517e7ea4eadca7cc6110ed671b61e2e8 Mon Sep 17 00:00:00 2001 From: Emad Jacob Maroun Date: Sat, 23 Nov 2024 23:09:14 +0100 Subject: [PATCH] The 'Simple' property now constains directedness and edge weight. --- src/algo/dfs.rs | 8 ++++---- src/core/ensure.rs | 1 - src/core/property/directedness_ensurers.rs | 2 +- src/core/property/rooted.rs | 2 +- src/core/property/simple.rs | 2 +- src/core/property/unilateral.rs | 4 +--- src/core/property/weak.rs | 4 +--- src/core/proxy/edge_weight_map.rs | 2 +- 8 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/algo/dfs.rs b/src/algo/dfs.rs index a93eb85..3f15eca 100644 --- a/src/algo/dfs.rs +++ b/src/algo/dfs.rs @@ -74,7 +74,7 @@ use std::borrow::Borrow; /// /// 2. Referenced closure: If Dfs takes a reference to a closure, it no longer /// needs to be generic on the closures type. However, it limits where Dfs can -/// be used, since its now bound by the lifetime of the reference. It also +/// be used, since it's now bound by the lifetime of the reference. It also /// doesn't solve the issue with other struct using Dfs, because you can't have /// the closure anywhere when not using the Dfs. /// @@ -269,11 +269,11 @@ where { // The meaning of markers: // - // If its on the stack it means we are still visiting it or its children. + // If it's on the stack it means we are still visiting it or its children. // // If its exit marked, it means when we are finished visiting it and its // children, we will call the 'on_exit' closure on it, and then pop it. - // If its not exit marked, it means this instance of it on the stack was + // If it's not exit marked, it means this instance of it on the stack was // never used for visiting this vertex's children and we just pop it, without // calling the closure. // @@ -281,7 +281,7 @@ where // we are finished doing so. Either way, it shouldn't go on the stack again // at any point. - // Pop any vertices that we are done visiting (and since its on the top of the + // Pop any vertices that we are done visiting (and since it's on the top of the // stack, we must be done visiting its children). while self.advance_next_exit().is_some() {} diff --git a/src/core/ensure.rs b/src/core/ensure.rs index 2d71c75..9c937e2 100644 --- a/src/core/ensure.rs +++ b/src/core/ensure.rs @@ -138,7 +138,6 @@ where /// graph is therefore the first layer. Each layer may need a payload. For /// example, an ensurer guaranteeing that a given vertex exists may have the /// vertex as a payload. -/// pub trait ReleasePayload: Sized + GraphDeref { /// The base graph implementation being ensured diff --git a/src/core/property/directedness_ensurers.rs b/src/core/property/directedness_ensurers.rs index 8ab7651..6c4e7a3 100644 --- a/src/core/property/directedness_ensurers.rs +++ b/src/core/property/directedness_ensurers.rs @@ -45,7 +45,7 @@ impl Graph for DirectedGraph } impl_ensurer! { - use DirectedGraph: Ensure, Graph, DirectedConstraint + use DirectedGraph: Ensure, Graph, DirectedConstraint, Simple as (self.0) : C } diff --git a/src/core/property/rooted.rs b/src/core/property/rooted.rs index de0725e..9ce63f2 100644 --- a/src/core/property/rooted.rs +++ b/src/core/property/rooted.rs @@ -37,7 +37,7 @@ pub trait Rooted: HasVertex } } -/// Ensures the a specific vertex is the root of the graph. +/// Ensures a specific vertex is the root of the graph. pub struct RootedGraph(VertexInGraph); impl Clone for RootedGraph diff --git a/src/core/property/simple.rs b/src/core/property/simple.rs index 7d72f6a..d4c3f34 100644 --- a/src/core/property/simple.rs +++ b/src/core/property/simple.rs @@ -6,7 +6,7 @@ use duplicate::duplicate_item; use std::borrow::Borrow; /// A marker trait for [simple graphs](https://mathworld.wolfram.com/SimpleGraph.html) -pub trait Simple: NoLoops + Unique {} +pub trait Simple: Graph + NoLoops + Unique {} #[derive(Clone, Debug)] pub struct SimpleGraph(C); diff --git a/src/core/property/unilateral.rs b/src/core/property/unilateral.rs index 4c94c1c..1c4cf97 100644 --- a/src/core/property/unilateral.rs +++ b/src/core/property/unilateral.rs @@ -21,8 +21,6 @@ use std::borrow::Borrow; /// directed graphs, for undirected ones, they are equal. For this reason, the /// companion ensurer graph `UnilateralGraph` only allows directed graphs. /// For undirected graph, simply use `ConnectedGraph`. -/// -/// For type safety reasons, the trait itself does not restrict directedness. pub trait Unilateral: Weak {} #[derive(Clone, Debug)] @@ -106,7 +104,7 @@ impl Weak for UnilateralGraph where C::Graph: Graph Unilateral for UnilateralGraph where C::Graph: Graph {} impl_ensurer! { - use UnilateralGraph: Ensure, Unilateral, Weak, RemoveVertex, RemoveEdge, + use UnilateralGraph: Ensure, Unilateral, Weak, RemoveVertex, RemoveEdge, Simple, // A new vertex would be unconnected to the rest of the graph NewVertex as (self.0) : C diff --git a/src/core/property/weak.rs b/src/core/property/weak.rs index 062ecb3..79d6b9a 100644 --- a/src/core/property/weak.rs +++ b/src/core/property/weak.rs @@ -17,8 +17,6 @@ use std::borrow::Borrow; /// directed graphs, for undirected ones, they are equal. For this reason, the /// companion ensurer graph `WeakGraph` only allows directed graphs. For /// undirected graph, simply use `ConnectedGraph`. -/// -/// For type safety reasons, the trait itself does not restrict directedness. pub trait Weak: Graph {} #[derive(Clone, Debug)] @@ -91,7 +89,7 @@ where impl Weak for WeakGraph where C::Graph: Graph {} impl_ensurer! { - use WeakGraph: Ensure, Weak, RemoveVertex, RemoveEdge, + use WeakGraph: Ensure, Weak, RemoveVertex, RemoveEdge, Simple, // A new vertex wouldn't be connected to the rest of the graph NewVertex as (self.0) : C diff --git a/src/core/proxy/edge_weight_map.rs b/src/core/proxy/edge_weight_map.rs index 176c73c..b27a428 100644 --- a/src/core/proxy/edge_weight_map.rs +++ b/src/core/proxy/edge_weight_map.rs @@ -94,7 +94,7 @@ impl Graph for EdgeWeightMap } impl_ensurer! { - use EdgeWeightMap: Ensure, Graph, GraphMut, Reflexive, AddEdge, RemoveEdge + use EdgeWeightMap: Ensure, Graph, GraphMut, Reflexive, AddEdge, RemoveEdge, Simple as (self.0) : C as (self.1) : fn( ::Vertex,