Skip to content

Commit

Permalink
The 'Simple' property now constains directedness and edge weight.
Browse files Browse the repository at this point in the history
  • Loading branch information
Emoun committed Nov 23, 2024
1 parent 15a6d9a commit 5b2420d
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/algo/dfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -269,19 +269,19 @@ 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.
//
// If it is marked visited it means we are either visiting its children, or
// 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()
{}
Expand Down
1 change: 0 additions & 1 deletion src/core/ensure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/property/directedness_ensurers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<C: Ensure> Graph for DirectedGraph<C>
}

impl_ensurer! {
use<C> DirectedGraph<C>: Ensure, Graph, DirectedConstraint
use<C> DirectedGraph<C>: Ensure, Graph, DirectedConstraint, Simple
as (self.0) : C
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/property/rooted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C: Ensure>(VertexInGraph<C>);

impl<C: Ensure> Clone for RootedGraph<C>
Expand Down
2 changes: 1 addition & 1 deletion src/core/property/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EdgeWeight = (), Directedness = Undirected> + NoLoops + Unique {}

#[derive(Clone, Debug)]
pub struct SimpleGraph<C: Ensure>(C);
Expand Down
4 changes: 1 addition & 3 deletions src/core/property/unilateral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -106,7 +104,7 @@ impl<C: Ensure> Weak for UnilateralGraph<C> where C::Graph: Graph<Directedness =
impl<C: Ensure> Unilateral for UnilateralGraph<C> where C::Graph: Graph<Directedness = Directed> {}

impl_ensurer! {
use<C> UnilateralGraph<C>: Ensure, Unilateral, Weak, RemoveVertex, RemoveEdge,
use<C> UnilateralGraph<C>: Ensure, Unilateral, Weak, RemoveVertex, RemoveEdge, Simple,
// A new vertex would be unconnected to the rest of the graph
NewVertex
as (self.0) : C
Expand Down
4 changes: 1 addition & 3 deletions src/core/property/weak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -91,7 +89,7 @@ where
impl<C: Ensure> Weak for WeakGraph<C> where C::Graph: Graph<Directedness = Directed> {}

impl_ensurer! {
use<C> WeakGraph<C>: Ensure, Weak, RemoveVertex, RemoveEdge,
use<C> WeakGraph<C>: Ensure, Weak, RemoveVertex, RemoveEdge, Simple,
// A new vertex wouldn't be connected to the rest of the graph
NewVertex
as (self.0) : C
Expand Down
2 changes: 1 addition & 1 deletion src/core/proxy/edge_weight_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<C: Ensure, Ew> Graph for EdgeWeightMap<C, Ew>
}

impl_ensurer! {
use<C,Ew> EdgeWeightMap<C, Ew>: Ensure, Graph, GraphMut, Reflexive, AddEdge, RemoveEdge
use<C,Ew> EdgeWeightMap<C, Ew>: Ensure, Graph, GraphMut, Reflexive, AddEdge, RemoveEdge, Simple
as (self.0) : C
as (self.1) : fn(
<C::Graph as Graph>::Vertex,
Expand Down

0 comments on commit 5b2420d

Please sign in to comment.