From 2f44a32fad2d12656f126aaf5a7ed9aa62cb5e3a Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Fri, 2 Jul 2021 17:27:17 -0700 Subject: [PATCH] Don't implement traits on Vertex directly --- src/ucs.rs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/ucs.rs b/src/ucs.rs index b4764bbb7..e44820691 100644 --- a/src/ucs.rs +++ b/src/ucs.rs @@ -8,7 +8,7 @@ use std::hash::{Hash, Hasher}; use crate::tree_diff::Node; use Edge::*; -#[derive(Debug, Eq, Clone)] +#[derive(Debug, Clone)] struct Vertex<'a> { distance: i64, lhs_next: Option<&'a Node<'a>>, @@ -36,7 +36,7 @@ impl<'a> Vertex<'a> { // equality should only consider LHS/RHS node when deciding if we've // visited a vertex. We define separate wrappers for these two use // cases. -#[derive(Debug, Eq)] +#[derive(Debug)] struct OrdVertex<'a> { v: Vertex<'a>, } @@ -58,6 +58,7 @@ impl<'a> PartialEq for OrdVertex<'a> { self.v.distance == other.v.distance } } +impl<'a> Eq for OrdVertex<'a> {} // A `Vertex` that only considers the underlying `Node`s for equality, // ignoring distance. @@ -299,21 +300,6 @@ fn neighbours<'a>(v: &Vertex<'a>) -> Vec<(Edge, Vertex<'a>)> { res } -impl<'a> PartialEq for Vertex<'a> { - fn eq(&self, other: &Self) -> bool { - self.lhs_next == other.lhs_next && self.rhs_next == other.rhs_next - } -} - -impl<'a> Hash for Vertex<'a> { - fn hash(&self, state: &mut H) { - // Deliberately ignore distance: we want to find equal nodes - // regardless of the distance of different paths to them. - self.lhs_next.hash(state); - self.rhs_next.hash(state); - } -} - #[cfg(test)] mod tests { use super::*;