Skip to content

Commit

Permalink
Various fixes for new errors/warnings. Other various updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Emoun committed Oct 27, 2024
1 parent 2e44c1f commit a06a177
Show file tree
Hide file tree
Showing 33 changed files with 135 additions and 144 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "graphene"
version = "0.1.5"
authors = ["Emad Jacob Maroun <emoun.open@gmail.com>"]
edition = "2018"
edition = "2021"

description = "A general purpose, extensible Graph Theory data type and algorithm library for Rust."

Expand All @@ -19,7 +19,7 @@ categories = ["data-structures","algorithms"]
travis-ci = {repository = "Emoun/graphene"}

[dependencies]
delegate = "0.4.2"
delegate = "0.13.1"
tt-equal = "0.1"
tt-call = "1.0"
num-traits = "0.2"
Expand All @@ -29,4 +29,4 @@ rand = "0.7"
quickcheck = "0.9"
quickcheck_macros = "0.9"
static_assertions = "1.1.0"
duplicate = "0.2.9"
duplicate = "2.0.0"
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ empty_item_single_line=true
force_multiline_blocks=true
format_strings=true
hard_tabs=true
merge_imports=true
imports_granularity="Crate"
newline_style="Unix"
normalize_comments=true
normalize_doc_attributes=true
Expand Down
6 changes: 3 additions & 3 deletions src/common/adjacency_list/impl_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ where
type Vertex = usize;
type VertexWeight = Vw;

fn all_vertices_weighted<'a>(
&'a self,
) -> Box<dyn 'a + Iterator<Item = (Self::Vertex, &'a Self::VertexWeight)>>
fn all_vertices_weighted(
&self,
) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, &Self::VertexWeight)>>
{
Box::new(self.vertices.iter().enumerate().map(|(v, (w, _))| (v, w)))
}
Expand Down
1 change: 0 additions & 1 deletion src/common/adjacency_list/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod impl_graph;

pub use self::impl_graph::*;
use crate::core::{Directed, Directedness};
use std::marker::PhantomData;

Expand Down
23 changes: 12 additions & 11 deletions src/core/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ pub trait Graph
type Directedness: Directedness;

/// Returns copies of all current vertex values in the graph.
fn all_vertices_weighted<'a>(
&'a self,
) -> Box<dyn 'a + Iterator<Item = (Self::Vertex, &'a Self::VertexWeight)>>;
fn all_vertices_weighted(
&self,
) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, &Self::VertexWeight)>>;

/// Returns the weights of all edges that are sourced in v1 and sinked in
/// v2. I.e. all edges where e == (v1,v2,_).
Expand Down Expand Up @@ -216,11 +216,12 @@ pub trait Graph
{
self.edges_between(v1.borrow(), v2.borrow())
.next()
.is_some() || (Self::Directedness::directed()
&& self
.edges_between(v2.borrow(), v1.borrow())
.next()
.is_some())
.is_some()
|| (Self::Directedness::directed()
&& self
.edges_between(v2.borrow(), v1.borrow())
.next()
.is_some())
}
}

Expand All @@ -232,9 +233,9 @@ pub trait Graph
/// methods plus some additional utilities.
pub trait GraphMut: Graph
{
fn all_vertices_weighted_mut<'a>(
&'a mut self,
) -> Box<dyn 'a + Iterator<Item = (Self::Vertex, &'a mut Self::VertexWeight)>>;
fn all_vertices_weighted_mut(
&mut self,
) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, &mut Self::VertexWeight)>>;

fn edges_between_mut<'a: 'b, 'b>(
&'a mut self,
Expand Down
4 changes: 1 addition & 3 deletions src/core/property/acyclic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use crate::{
use std::borrow::Borrow;

/// An acyclic graph
pub trait Acyclic: NoLoops
{
}
pub trait Acyclic: NoLoops {}

#[derive(Clone, Debug)]
pub struct AcyclicGraph<C: Ensure>(C);
Expand Down
4 changes: 1 addition & 3 deletions src/core/property/connected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use std::borrow::Borrow;
///
/// A graph is connected if there is a path from any vertex to any other vertex.
/// Graphs with one or zero vertices count as connected.
pub trait Connected: Unilateral
{
}
pub trait Connected: Unilateral {}

#[derive(Clone, Debug)]
pub struct ConnectedGraph<C: Ensure>(C);
Expand Down
12 changes: 6 additions & 6 deletions src/core/property/directedness_ensurers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ impl<C: Ensure> Graph for DirectedGraph<C>

delegate! {
to self.0.graph() {
fn all_vertices_weighted<'a>(
&'a self,
) -> Box<dyn 'a + Iterator<Item = (Self::Vertex, &'a Self::VertexWeight)>>;
fn all_vertices_weighted(
&self,
) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, &Self::VertexWeight)>>;

fn edges_between<'a: 'b, 'b>(
&'a self,
Expand Down Expand Up @@ -70,9 +70,9 @@ impl<C: Ensure> Graph for UndirectedGraph<C>

delegate! {
to self.0.graph() {
fn all_vertices_weighted<'a>(
&'a self,
) -> Box<dyn 'a + Iterator<Item = (Self::Vertex, &'a Self::VertexWeight)>>;
fn all_vertices_weighted(
&self,
) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, &Self::VertexWeight)>>;

fn edges_between<'a: 'b, 'b>(
&'a self,
Expand Down
16 changes: 7 additions & 9 deletions src/core/property/impl_ensurer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ macro_rules! impl_properties {

delegate::delegate! {
to $crate::core::GraphDeref::graph(&self$($delegate)+){
fn all_vertices_weighted<'a>(
&'a self,
) -> Box<dyn 'a + Iterator<Item = (Self::Vertex, &'a Self::VertexWeight)>>;
fn all_vertices_weighted(
&self,
) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, &Self::VertexWeight)>>;

fn edges_between<'a: 'b, 'b>(
&'a self,
Expand Down Expand Up @@ -275,11 +275,9 @@ macro_rules! impl_properties {
@implement {
delegate::delegate! {
to $crate::core::GraphDerefMut::graph_mut(&mut self$($delegate)+) {
fn all_vertices_weighted_mut<'a>(
&'a mut self,
) -> Box<dyn 'a + Iterator<
Item = (Self::Vertex, &'a mut Self::VertexWeight)
>>;
fn all_vertices_weighted_mut(
&mut self,
) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, &mut Self::VertexWeight)>>;

fn edges_between_mut<'a: 'b, 'b>(
&'a mut self,
Expand Down Expand Up @@ -511,7 +509,7 @@ macro_rules! impl_properties {
@implement {
delegate::delegate!{
to $crate::core::GraphDeref::graph(&self$($delegate)+) {
fn exit_edges<'a>(&'a self) -> Box<dyn 'a + Iterator<Item=
fn exit_edges(&self) -> Box<dyn '_ + Iterator<Item=
(Self::Vertex, Self::Vertex)>>;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/core/property/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ mod unique;
mod weak;

pub use self::{
acyclic::*, base_props::*, connected::*, directedness_ensurers::*, has_vertex::*,
impl_ensurer::*, no_loops::*, reflexive::*, rooted::*, subgraph::*, unilateral::*, unique::*,
weak::*,
acyclic::*, base_props::*, connected::*, directedness_ensurers::*, has_vertex::*, no_loops::*,
reflexive::*, rooted::*, subgraph::*, unilateral::*, unique::*, weak::*,
};
use crate::core::{
proxy::{EdgeProxyGraph, ProxyVertex, VertexProxyGraph},
Expand Down
4 changes: 1 addition & 3 deletions src/core/property/no_loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use std::borrow::Borrow;
/// In graph theory, a loop is an edge that connects a vertex to itself.
/// This trait guarantees that there are no loops in the graph and that no loops
/// can be added to it.
pub trait NoLoops: Graph
{
}
pub trait NoLoops: Graph {}

pub struct NoLoopsGraph<C: Ensure>(C);

Expand Down
2 changes: 1 addition & 1 deletion src/core/property/subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::core::{Edge, Graph};
pub trait Subgraph: Graph
{
/// Edges who's sources are in this subgraph but who's sinks aren't.
fn exit_edges<'a>(&'a self) -> Box<dyn 'a + Iterator<Item = (Self::Vertex, Self::Vertex)>>;
fn exit_edges(&self) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, Self::Vertex)>>;

/// Whether this subgraph can reach a vertex in the other subgraph, either
/// by sharing a vertex with it, or having an axit edge to one of its
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 @@ -23,9 +23,7 @@ use std::borrow::Borrow;
/// For undirected graph, simply use `ConnectedGraph`.
///
/// For type safety reasons, the trait itself does not restrict directedness.
pub trait Unilateral: Weak
{
}
pub trait Unilateral: Weak {}

#[derive(Clone, Debug)]
pub struct UnilateralGraph<C: Ensure>(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 @@ -19,9 +19,7 @@ use std::borrow::Borrow;
/// undirected graph, simply use `ConnectedGraph`.
///
/// For type safety reasons, the trait itself does not restrict directedness.
pub trait Weak: Graph
{
}
pub trait Weak: Graph {}

#[derive(Clone, Debug)]
pub struct WeakGraph<C: Ensure>(C)
Expand Down
16 changes: 8 additions & 8 deletions src/core/proxy/edge_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::core::{
Directedness, Edge, Ensure, Graph, GraphDerefMut, GraphMut,
};
use delegate::delegate;
use std::borrow::Borrow;
use std::{borrow::Borrow, cell::UnsafeCell};

/// A wrapper around a graph, that allows for addition and removal
/// of edges, without mutating the underlying graph.
Expand Down Expand Up @@ -55,9 +55,9 @@ impl<C: Ensure> Graph for EdgeProxyGraph<C>

delegate! {
to self.graph.graph() {
fn all_vertices_weighted<'a>(
&'a self,
) -> Box<dyn 'a + Iterator<Item = (Self::Vertex, &'a Self::VertexWeight)>>;
fn all_vertices_weighted(
&self,
) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, &Self::VertexWeight)>>;
}
}

Expand Down Expand Up @@ -94,9 +94,9 @@ where
{
delegate! {
to self.graph.graph_mut() {
fn all_vertices_weighted_mut<'a>(
&'a mut self,
) -> Box<dyn 'a + Iterator<Item = (Self::Vertex, &'a mut Self::VertexWeight)>>;
fn all_vertices_weighted_mut(
&mut self,
) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, &mut Self::VertexWeight)>>;
}
}

Expand All @@ -109,7 +109,7 @@ where
// Safe because &mut () can't mutate anything
Box::new(
self.edges_between(source, sink)
.map(|w| unsafe { &mut *((w as *const ()) as *mut ()) }),
.map(|_| unsafe { &mut *UnsafeCell::new(()).get() }),
)
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/proxy/reverse_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ where

delegate! {
to self.0.graph() {
fn all_vertices_weighted<'a>(&'a self) -> Box<dyn 'a + Iterator<Item=
(Self::Vertex, &'a Self::VertexWeight)>>;
fn all_vertices_weighted(&self) -> Box<dyn '_ + Iterator<Item=
(Self::Vertex, &Self::VertexWeight)>>;
}
}

Expand All @@ -53,8 +53,8 @@ where
{
delegate! {
to self.0.graph_mut() {
fn all_vertices_weighted_mut<'a>(&'a mut self) -> Box<dyn 'a + Iterator<Item=
(Self::Vertex, &'a mut Self::VertexWeight)>>;
fn all_vertices_weighted_mut(&mut self) -> Box<dyn '_ + Iterator<Item=
(Self::Vertex, &mut Self::VertexWeight)>>;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/proxy/subgraph_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ impl<C: Ensure> Graph for SubgraphProxy<C>
type Vertex = <C::Graph as Graph>::Vertex;
type VertexWeight = <C::Graph as Graph>::VertexWeight;

fn all_vertices_weighted<'a>(
&'a self,
) -> Box<dyn 'a + Iterator<Item = (Self::Vertex, &'a Self::VertexWeight)>>
fn all_vertices_weighted(
&self,
) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, &Self::VertexWeight)>>
{
Box::new(
self.graph
Expand Down
6 changes: 3 additions & 3 deletions src/core/proxy/undirected_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ where

delegate! {
to self.0.graph() {
fn all_vertices_weighted<'a>(
&'a self,
) -> Box<dyn 'a + Iterator<Item = (Self::Vertex, &'a Self::VertexWeight)>>;
fn all_vertices_weighted(
&self,
) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, &Self::VertexWeight)>>;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/proxy/vertex_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ impl<C: Ensure> Graph for VertexProxyGraph<C>
type Vertex = ProxyVertex<<C::Graph as Graph>::Vertex>;
type VertexWeight = ();

fn all_vertices_weighted<'a>(
&'a self,
) -> Box<dyn 'a + Iterator<Item = (Self::Vertex, &'a Self::VertexWeight)>>
fn all_vertices_weighted(
&self,
) -> Box<dyn '_ + Iterator<Item = (Self::Vertex, &Self::VertexWeight)>>
{
Box::new(
self.graph
Expand Down
4 changes: 2 additions & 2 deletions tests/algo/bfs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::mock_graph::{arbitrary::Arb, MockGraph};
use duplicate::duplicate;
use duplicate::duplicate_item;
use graphene::{
algo::Bfs,
core::{
Expand All @@ -9,7 +9,7 @@ use graphene::{
};
use std::collections::HashSet;

#[duplicate(
#[duplicate_item(
directedness; [ Directed ]; [ Undirected ]
)]
mod __
Expand Down
4 changes: 2 additions & 2 deletions tests/algo/dfs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Tests `Dfs`
use crate::mock_graph::{arbitrary::Arb, MockGraph, MockVertex};
use duplicate::duplicate;
use duplicate::duplicate_item;
use graphene::{
algo::Dfs,
core::{
Expand All @@ -11,7 +11,7 @@ use graphene::{
};
use std::cell::Cell;

#[duplicate(
#[duplicate_item(
directedness; [ Directed ]; [ Undirected ]
)]
mod __
Expand Down
4 changes: 2 additions & 2 deletions tests/algo/dijkstra_shortest_paths.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::mock_graph::arbitrary::{Arb, VerticesIn};
/// tests `DijkstraShortestPath`
use crate::mock_graph::{MockEdgeWeight, MockGraph};
use duplicate::duplicate;
use duplicate::duplicate_item;
use graphene::{
algo::DijkstraShortestPaths,
core::{
Expand All @@ -11,7 +11,7 @@ use graphene::{
};
use std::collections::{HashMap, HashSet};

#[duplicate(
#[duplicate_item(
directedness; [ Directed ]; [ Undirected ]
)]
mod __
Expand Down
Loading

0 comments on commit a06a177

Please sign in to comment.