Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove unused macro and impl Clone for Node, Edge, Neighbor #570

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 4 additions & 43 deletions src/graph_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,41 +194,18 @@ impl<Ix: fmt::Debug> fmt::Debug for EdgeIndex<Ix> {
write!(f, "EdgeIndex({:?})", self.0)
}
}
/*
* FIXME: Use this impl again, when we don't need to add so many bounds
impl<Ix: IndexType> fmt::Debug for EdgeIndex<Ix>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "EdgeIndex("));
if *self == EdgeIndex::end() {
try!(write!(f, "End"));
} else {
try!(write!(f, "{}", self.index()));
}
write!(f, ")")
}
}
*/

const DIRECTIONS: [Direction; 2] = [Outgoing, Incoming];

/// The graph's node type.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Node<N, Ix = DefaultIx> {
/// Associated node data.
pub weight: N,
/// Next edge in outgoing and incoming edge lists.
next: [EdgeIndex<Ix>; 2],
}

impl<E, Ix> Clone for Node<E, Ix>
where
E: Clone,
Ix: Copy,
{
clone_fields!(Node, weight, next,);
}

impl<N, Ix: IndexType> Node<N, Ix> {
/// Accessor for data structure internals: the first edge in the given direction.
pub fn next_edge(&self, dir: Direction) -> EdgeIndex<Ix> {
Expand All @@ -237,7 +214,7 @@ impl<N, Ix: IndexType> Node<N, Ix> {
}

/// The graph's edge type.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Edge<E, Ix = DefaultIx> {
/// Associated edge data.
pub weight: E,
Expand All @@ -247,14 +224,6 @@ pub struct Edge<E, Ix = DefaultIx> {
node: [NodeIndex<Ix>; 2],
}

impl<E, Ix> Clone for Edge<E, Ix>
where
E: Clone,
Ix: Copy,
{
clone_fields!(Edge, weight, next, node,);
}

impl<E, Ix: IndexType> Edge<E, Ix> {
/// Accessor for data structure internals: the next edge for the given direction.
pub fn next_edge(&self, dir: Direction) -> EdgeIndex<Ix> {
Expand Down Expand Up @@ -438,7 +407,7 @@ fn index_twice<T>(slc: &mut [T], a: usize, b: usize) -> Pair<&mut T> {
if max(a, b) >= slc.len() {
Pair::None
} else if a == b {
Pair::One(&mut slc[max(a, b)])
Pair::One(&mut slc[a])
} else {
// safe because a, b are in bounds and distinct
unsafe {
Expand Down Expand Up @@ -656,7 +625,6 @@ where
}
let ret = self.remove_edge(next);
debug_assert!(ret.is_some());
let _ = ret;
}
}

Expand Down Expand Up @@ -1507,7 +1475,7 @@ where
/// [1]: struct.Graph.html#method.neighbors
/// [2]: struct.Graph.html#method.neighbors_directed
/// [3]: struct.Graph.html#method.neighbors_undirected
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Neighbors<'a, E: 'a, Ix: 'a = DefaultIx> {
/// starting node to skip over
skip_start: NodeIndex<Ix>,
Expand Down Expand Up @@ -1544,13 +1512,6 @@ where
}
}

impl<'a, E, Ix> Clone for Neighbors<'a, E, Ix>
where
Ix: IndexType,
{
clone_fields!(Neighbors, skip_start, edges, next,);
}

impl<'a, E, Ix> Neighbors<'a, E, Ix>
where
Ix: IndexType,
Expand Down
10 changes: 5 additions & 5 deletions src/graph_impl/stable_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1666,14 +1666,14 @@ where
/// assert_eq!(gr[b], 4.);
/// assert_eq!(gr[c], 2.);
/// ```
pub struct WalkNeighbors<Ix> {
#[derive(Clone)]
pub struct WalkNeighbors<Ix>
where
Ix: IndexType,
{
inner: super::WalkNeighbors<Ix>,
}

impl<Ix: IndexType> Clone for WalkNeighbors<Ix> {
clone_fields!(WalkNeighbors, inner);
}

impl<Ix: IndexType> WalkNeighbors<Ix> {
/// Step to the next edge and its endpoint node in the walk for graph `g`.
///
Expand Down
21 changes: 3 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,9 @@ pub mod graph {
#[cfg(feature = "stable_graph")]
pub use crate::graph_impl::stable_graph;

macro_rules! copyclone {
($name:ident) => {
impl Clone for $name {
#[inline]
fn clone(&self) -> Self {
*self
}
}
};
}

// Index into the NodeIndex and EdgeIndex arrays
/// Edge direction.
#[derive(Copy, Debug, PartialEq, PartialOrd, Ord, Eq, Hash)]
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash)]
#[repr(usize)]
pub enum Direction {
/// An `Outgoing` edge is an outward edge *from* the current node.
Expand All @@ -192,8 +181,6 @@ pub enum Direction {
Incoming = 1,
}

copyclone!(Direction);

impl Direction {
/// Return the opposite `Direction`.
#[inline]
Expand All @@ -215,14 +202,12 @@ impl Direction {
pub use crate::Direction as EdgeDirection;

/// Marker type for a directed graph.
#[derive(Copy, Debug)]
#[derive(Copy, Debug, Clone)]
pub enum Directed {}
copyclone!(Directed);

/// Marker type for an undirected graph.
#[derive(Copy, Debug)]
#[derive(Copy, Debug, Clone)]
pub enum Undirected {}
copyclone!(Undirected);

/// A graph's edge type determines whether it has directed edges or not.
pub trait EdgeType {
Expand Down
12 changes: 0 additions & 12 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
macro_rules! clone_fields {
($name:ident, $($field:ident),+ $(,)*) => (
fn clone(&self) -> Self {
$name {
$(
$field : self . $field .clone()
),*
}
}
);
}

macro_rules! iterator_wrap {
(impl () for
struct $name: ident <$($typarm:tt),*> where { $($bounds: tt)* }
Expand Down