From 5f731fad0ece36f67b24e6c2d983b132a1449496 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Tue, 30 May 2023 16:30:52 +0200 Subject: [PATCH] dag: Improve trait bounds --- radicle-dag/src/lib.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/radicle-dag/src/lib.rs b/radicle-dag/src/lib.rs index 4e57bf9d..3b8cb0d3 100644 --- a/radicle-dag/src/lib.rs +++ b/radicle-dag/src/lib.rs @@ -5,13 +5,12 @@ use std::{ cmp::Ordering, collections::{BTreeMap, BTreeSet, VecDeque}, fmt, - hash::Hash, ops::{ControlFlow, Deref, Index}, }; /// A node in the graph. #[derive(Clone, Debug, PartialEq, Eq)] -pub struct Node { +pub struct Node { /// The node value, stored by the user. pub value: V, /// Nodes depended on. @@ -20,7 +19,7 @@ pub struct Node { pub dependents: BTreeSet, } -impl Node { +impl Node { fn new(value: V) -> Self { Self { value, @@ -30,13 +29,13 @@ impl Node { } } -impl Borrow for &Node { +impl Borrow for &Node { fn borrow(&self) -> &V { &self.value } } -impl Deref for Node { +impl Deref for Node { type Target = V; fn deref(&self) -> &Self::Target { @@ -46,13 +45,13 @@ impl Deref for Node { /// A directed acyclic graph. #[derive(Clone, Debug, Default, PartialEq, Eq)] -pub struct Dag { +pub struct Dag { graph: BTreeMap>, tips: BTreeSet, roots: BTreeSet, } -impl Dag { +impl Dag { /// Create a new empty DAG. pub fn new() -> Self { Self { @@ -256,7 +255,7 @@ impl Dag { } } -impl Index<&K> for Dag { +impl Index<&K> for Dag { type Output = Node; fn index(&self, key: &K) -> &Self::Output {