MatrixGraph: implement Build naively
diff --git a/src/matrix_graph.rs b/src/matrix_graph.rs
index f81398b..f20692e 100644
--- a/src/matrix_graph.rs
+++ b/src/matrix_graph.rs
@@ -36,6 +36,8 @@
Visitable,
};
+use crate::data::Build;
+
pub use crate::graph::IndexType;
// The following types are used to control the max size of the adjacency matrix. Since the maximum
@@ -902,7 +904,7 @@
type EdgeType = Ty;
}
-impl<'a, N, E, Ty: EdgeType, Null: Nullable<Wrapped=E>> Data for &'a MatrixGraph<N, E, Ty, Null> {
+impl<N, E, Ty: EdgeType, Null: Nullable<Wrapped=E>> Data for MatrixGraph<N, E, Ty, Null> {
type NodeWeight = N;
type EdgeWeight = E;
}
@@ -956,7 +958,7 @@
impl<N, E, Ty: EdgeType, Null: Nullable<Wrapped=E>> NodeIndexable for MatrixGraph<N, E, Ty, Null> {
fn node_bound(&self) -> usize {
- MatrixGraph::node_count(self)
+ self.node_count()
}
fn to_index(&self, ix: NodeIndex) -> usize {
ix.index()
@@ -969,6 +971,26 @@
impl<N, E, Ty: EdgeType, Null: Nullable<Wrapped=E>> NodeCompactIndexable for MatrixGraph<N, E, Ty, Null> {
}
+impl<N, E, Ty: EdgeType, Null: Nullable<Wrapped=E>> Build for MatrixGraph<N, E, Ty, Null> {
+ fn add_node(&mut self, weight: Self::NodeWeight) -> Self::NodeId {
+ self.add_node(weight)
+ }
+
+ fn add_edge(&mut self, a: Self::NodeId, b: Self::NodeId, weight: Self::EdgeWeight) -> Option<Self::EdgeId> {
+ if !self.has_edge(a, b) {
+ MatrixGraph::update_edge(self, a, b, weight);
+ Some((a, b))
+ } else {
+ None
+ }
+ }
+
+ fn update_edge(&mut self, a: Self::NodeId, b: Self::NodeId, weight: Self::EdgeWeight) -> Self::EdgeId {
+ MatrixGraph::update_edge(self, a, b, weight);
+ (a, b)
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;