diff --git a/docbrown/src/db/edge.rs b/docbrown/src/db/edge.rs index e08f92f0..f67c9c31 100644 --- a/docbrown/src/db/edge.rs +++ b/docbrown/src/db/edge.rs @@ -8,6 +8,7 @@ use crate::core::tgraph::{EdgeRef, VertexRef}; use crate::core::Direction; use crate::core::Prop; +use crate::db::graph_window::WindowedGraph; use crate::db::vertex::VertexView; use crate::db::view_api::{BoxedIter, EdgeListOps, GraphViewOps, TimeOps}; use std::collections::HashMap; @@ -21,8 +22,7 @@ pub struct EdgeView { /// A view of an edge in the graph. pub graph: G, /// A reference to the edge. - edge: EdgeRef, - window: Option>, + pub edge: EdgeRef, } impl Debug for EdgeView { @@ -47,19 +47,7 @@ impl EdgeView { /// /// A new `EdgeView`. pub(crate) fn new(graph: G, edge: EdgeRef) -> Self { - EdgeView { - graph, - edge, - window: None, - } - } - - pub(crate) fn new_windowed(graph: G, edge: EdgeRef, window: Option>) -> EdgeView { - EdgeView { - graph, - edge, - window, - } + EdgeView { graph, edge } } /// Returns a reference to the underlying edge reference. @@ -102,15 +90,7 @@ impl EdgeView { } pub fn history(&self) -> Vec { - match self.window.clone() { - Some(_) => self.graph.edge_timestamps(self.edge, self.window.clone()), - None => self.graph.edge_timestamps( - self.edge, - Some( - self.graph.earliest_time().unwrap_or(0)..self.graph.latest_time().unwrap_or(0), - ), - ), - } + self.graph.edge_timestamps(self.edge, None) } pub fn properties(&self, include_static: bool) -> HashMap { @@ -213,14 +193,7 @@ impl EdgeView { g_id: self.edge.src_g_id, pid: None, }; - - match &self.window { - None => self.graph.vertex_edges_t(vertex, Direction::OUT, None), - Some(w) => { - self.graph - .vertex_edges_window_t(vertex, w.start, w.end, Direction::OUT, None) - } - } + self.graph.vertex_edges_t(vertex, Direction::OUT, None) } /// Gets the first time an edge was seen @@ -245,27 +218,20 @@ impl EdgeView { } impl TimeOps for EdgeView { - type WindowedViewType = EdgeView; + type WindowedViewType = EdgeView>; fn start(&self) -> Option { - match &self.window { - None => self.graph.start(), - Some(w) => Some(w.start), - } + self.graph.start() } fn end(&self) -> Option { - match &self.window { - None => self.graph.end(), - Some(w) => Some(w.end), - } + self.graph.end() } fn window(&self, t_start: i64, t_end: i64) -> Self::WindowedViewType { - Self { - graph: self.graph.clone(), + EdgeView { + graph: self.graph.window(t_start, t_end), edge: self.edge, - window: Some(self.actual_start(t_start)..self.actual_end(t_end)), } } } diff --git a/docbrown/src/db/graph_window.rs b/docbrown/src/db/graph_window.rs index 06398056..095ec70e 100644 --- a/docbrown/src/db/graph_window.rs +++ b/docbrown/src/db/graph_window.rs @@ -44,6 +44,7 @@ use crate::core::{ use crate::db::view_api::internal::GraphViewInternalOps; use crate::db::view_api::time::TimeOps; use crate::db::view_api::GraphViewOps; +use std::cmp::{max, min}; use std::{collections::HashMap, ops::Range}; /// A struct that represents a windowed view of a `Graph`. @@ -813,7 +814,11 @@ impl GraphViewInternalOps for WindowedGraph { /// - `GraphError` - Raised if edge does not exist fn edge_timestamps(&self, e: EdgeRef, window: Option>) -> Vec { - self.graph.edge_timestamps(e, window) + let window = match window { + Some(Range { start, end, .. }) => self.actual_start(start)..self.actual_end(end), + None => self.t_start..self.t_end, + }; + self.graph.edge_timestamps(e, Some(window)) } /// Get all temporal properties of a vertex @@ -1052,6 +1057,16 @@ impl WindowedGraph { t_end, } } + + /// the larger of `t_start` and `self.start()` (useful for creating nested windows) + fn actual_start(&self, t_start: i64) -> i64 { + max(t_start, self.t_start) + } + + /// the smaller of `t_end` and `self.end()` (useful for creating nested windows) + fn actual_end(&self, t_end: i64) -> i64 { + min(t_end, self.t_end) + } } #[cfg(test)] diff --git a/docbrown/src/db/path.rs b/docbrown/src/db/path.rs index 943936e4..bd656461 100644 --- a/docbrown/src/db/path.rs +++ b/docbrown/src/db/path.rs @@ -1,6 +1,7 @@ use crate::core::tgraph::VertexRef; use crate::core::{Direction, Prop}; use crate::db::edge::EdgeView; +use crate::db::graph_window::WindowedGraph; use crate::db::vertex::VertexView; use crate::db::view_api::BoxedIter; use crate::db::view_api::*; @@ -10,7 +11,7 @@ use std::ops::Range; use std::sync::Arc; #[derive(Copy, Clone)] -pub(crate) enum Operations { +pub enum Operations { Neighbours { dir: Direction, }, @@ -44,9 +45,8 @@ impl Operations { #[derive(Clone)] pub struct PathFromGraph { - graph: G, - operations: Arc>, - window: Option>, + pub graph: G, + pub operations: Arc>, } impl PathFromGraph { @@ -54,19 +54,16 @@ impl PathFromGraph { PathFromGraph { graph, operations: Arc::new(vec![operation]), - window: None, } } pub fn iter(&self) -> Box> + Send> { let g = self.graph.clone(); let ops = self.operations.clone(); - let w = self.window.clone(); - Box::new(self.graph.vertex_refs().map(move |v| PathFromVertex { + Box::new(g.vertex_refs().map(move |v| PathFromVertex { graph: g.clone(), vertex: v, operations: ops.clone(), - window: w.clone(), })) } } @@ -202,90 +199,58 @@ impl VertexViewOps for PathFromGraph { fn neighbours(&self) -> Self { let mut new_ops = (*self.operations).clone(); let dir = Direction::BOTH; - match &self.window { - None => new_ops.push(Operations::Neighbours { dir }), - Some(window) => new_ops.push(Operations::NeighboursWindow { - dir, - t_start: window.start, - t_end: window.end, - }), - } + new_ops.push(Operations::Neighbours { dir }); Self { graph: self.graph.clone(), operations: Arc::new(new_ops), - window: None, } } fn in_neighbours(&self) -> Self { let mut new_ops = (*self.operations).clone(); let dir = Direction::IN; - match &self.window { - None => new_ops.push(Operations::Neighbours { dir }), - Some(window) => new_ops.push(Operations::NeighboursWindow { - dir, - t_start: window.start, - t_end: window.end, - }), - } + new_ops.push(Operations::Neighbours { dir }); Self { graph: self.graph.clone(), operations: Arc::new(new_ops), - window: None, } } fn out_neighbours(&self) -> Self { let mut new_ops = (*self.operations).clone(); let dir = Direction::OUT; - match &self.window { - None => new_ops.push(Operations::Neighbours { dir }), - Some(window) => new_ops.push(Operations::NeighboursWindow { - dir, - t_start: window.start, - t_end: window.end, - }), - } + new_ops.push(Operations::Neighbours { dir }); Self { graph: self.graph.clone(), operations: Arc::new(new_ops), - window: None, } } } impl TimeOps for PathFromGraph { - type WindowedViewType = Self; + type WindowedViewType = PathFromGraph>; fn start(&self) -> Option { - match &self.window { - None => self.graph.start(), - Some(w) => Some(w.start), - } + self.graph.start() } fn end(&self) -> Option { - match &self.window { - None => self.graph.end(), - Some(w) => Some(w.end), - } + self.graph.end() } fn window(&self, t_start: i64, t_end: i64) -> Self::WindowedViewType { - Self { - graph: self.graph.clone(), + PathFromGraph { + graph: self.graph.window(t_start, t_end), operations: self.operations.clone(), - window: Some(self.actual_start(t_start)..self.actual_end(t_end)), } } } #[derive(Clone)] pub struct PathFromVertex { - graph: G, - vertex: VertexRef, - operations: Arc>, - window: Option>, + pub graph: G, + pub vertex: VertexRef, + pub operations: Arc>, } impl PathFromVertex { @@ -297,12 +262,7 @@ impl PathFromVertex { .iter() .fold(init, |it, op| Box::new(op.op(g.clone(), it))) .map(move |v| VertexView::new(g.clone(), v)); - let window = self.window.clone(); - if let Some(window) = window { - Box::new(iter.map(move |v| v.window(window.start, window.end))) - } else { - Box::new(iter) - } + Box::new(iter) } pub(crate) fn new>( @@ -314,7 +274,6 @@ impl PathFromVertex { graph, vertex: vertex.into(), operations: Arc::new(vec![operation]), - window: None, } } } @@ -403,84 +362,53 @@ impl VertexViewOps for PathFromVertex { fn neighbours(&self) -> Self { let mut new_ops = (*self.operations).clone(); let dir = Direction::BOTH; - match &self.window { - None => new_ops.push(Operations::Neighbours { dir }), - Some(window) => new_ops.push(Operations::NeighboursWindow { - dir, - t_start: window.start, - t_end: window.end, - }), - } + new_ops.push(Operations::Neighbours { dir }); Self { graph: self.graph.clone(), vertex: self.vertex, operations: Arc::new(new_ops), - window: None, } } fn in_neighbours(&self) -> Self { let mut new_ops = (*self.operations).clone(); let dir = Direction::IN; - match &self.window { - None => new_ops.push(Operations::Neighbours { dir }), - Some(window) => new_ops.push(Operations::NeighboursWindow { - dir, - t_start: window.start, - t_end: window.end, - }), - } + new_ops.push(Operations::Neighbours { dir }); Self { graph: self.graph.clone(), vertex: self.vertex, operations: Arc::new(new_ops), - window: None, } } fn out_neighbours(&self) -> Self { let mut new_ops = (*self.operations).clone(); let dir = Direction::OUT; - match &self.window { - None => new_ops.push(Operations::Neighbours { dir }), - Some(window) => new_ops.push(Operations::NeighboursWindow { - dir, - t_start: window.start, - t_end: window.end, - }), - } + new_ops.push(Operations::Neighbours { dir }); Self { graph: self.graph.clone(), vertex: self.vertex, operations: Arc::new(new_ops), - window: None, } } } impl TimeOps for PathFromVertex { - type WindowedViewType = Self; + type WindowedViewType = PathFromVertex>; fn start(&self) -> Option { - match &self.window { - None => self.graph.start(), - Some(w) => Some(w.start), - } + self.graph.start() } fn end(&self) -> Option { - match &self.window { - None => self.graph.end(), - Some(w) => Some(w.end), - } + self.graph.end() } fn window(&self, t_start: i64, t_end: i64) -> Self::WindowedViewType { - Self { - graph: self.graph.clone(), + PathFromVertex { + graph: self.graph.window(t_start, t_end), vertex: self.vertex, operations: self.operations.clone(), - window: Some(self.actual_start(t_start)..self.actual_end(t_end)), } } } diff --git a/docbrown/src/db/vertex.rs b/docbrown/src/db/vertex.rs index 6e4534e1..2d1926c0 100644 --- a/docbrown/src/db/vertex.rs +++ b/docbrown/src/db/vertex.rs @@ -3,6 +3,7 @@ use crate::core::tgraph::VertexRef; use crate::core::{Direction, Prop}; use crate::db::edge::{EdgeList, EdgeView}; +use crate::db::graph_window::WindowedGraph; use crate::db::path::{Operations, PathFromVertex}; use crate::db::view_api::vertex::VertexViewOps; use crate::db::view_api::{BoxedIter, GraphViewOps, TimeOps, VertexListOps}; @@ -12,8 +13,7 @@ use std::ops::Range; #[derive(Debug, Clone)] pub struct VertexView { pub graph: G, - pub(crate) vertex: VertexRef, - window: Option>, + pub vertex: VertexRef, } impl From> for VertexRef { @@ -31,22 +31,7 @@ impl From<&VertexView> for VertexRef { impl VertexView { /// Creates a new `VertexView` wrapping a vertex reference and a graph. pub(crate) fn new(graph: G, vertex: VertexRef) -> VertexView { - VertexView { - graph, - vertex, - window: None, - } - } - pub(crate) fn new_windowed( - graph: G, - vertex: VertexRef, - window: Option>, - ) -> VertexView { - VertexView { - graph, - vertex, - window, - } + VertexView { graph, vertex } } } @@ -69,21 +54,11 @@ impl VertexViewOps for VertexView { } fn earliest_time(&self) -> Option { - match &self.window { - None => self.graph.vertex_earliest_time(self.vertex), - Some(w) => self - .graph - .vertex_earliest_time_window(self.vertex, w.start, w.end), - } + self.graph.vertex_earliest_time(self.vertex) } fn latest_time(&self) -> Option { - match &self.window { - None => self.graph.vertex_latest_time(self.vertex), - Some(w) => self - .graph - .vertex_latest_time_window(self.vertex, w.start, w.end), - } + self.graph.vertex_latest_time(self.vertex) } fn property(&self, name: String, include_static: bool) -> Option { @@ -104,22 +79,11 @@ impl VertexViewOps for VertexView { } fn property_history(&self, name: String) -> Vec<(i64, Prop)> { - match &self.window { - None => self.graph.temporal_vertex_prop_vec(self.vertex, name), - Some(w) => { - self.graph - .temporal_vertex_prop_vec_window(self.vertex, name, w.start, w.end) - } - } + self.graph.temporal_vertex_prop_vec(self.vertex, name) } fn history(&self) -> Vec { - match &self.window { - None => self.graph.vertex_timestamps(self.vertex), - Some(w) => self - .graph - .vertex_timestamps_window(self.vertex, w.start, w.end), - } + self.graph.vertex_timestamps(self.vertex) } fn properties(&self, include_static: bool) -> HashMap { @@ -146,12 +110,7 @@ impl VertexViewOps for VertexView { } fn property_histories(&self) -> HashMap> { - match &self.window { - None => self.graph.temporal_vertex_props(self.vertex), - Some(w) => self - .graph - .temporal_vertex_props_window(self.vertex, w.start, w.end), - } + self.graph.temporal_vertex_props(self.vertex) } fn property_names(&self, include_static: bool) -> Vec { @@ -183,168 +142,80 @@ impl VertexViewOps for VertexView { fn degree(&self) -> usize { let dir = Direction::BOTH; - match &self.window { - None => self.graph.degree(self.vertex, dir, None), - Some(w) => self - .graph - .degree_window(self.vertex, w.start, w.end, dir, None), - } + self.graph.degree(self.vertex, dir, None) } fn in_degree(&self) -> usize { let dir = Direction::IN; - match &self.window { - None => self.graph.degree(self.vertex, dir, None), - Some(w) => self - .graph - .degree_window(self.vertex, w.start, w.end, dir, None), - } + self.graph.degree(self.vertex, dir, None) } fn out_degree(&self) -> usize { let dir = Direction::OUT; - match &self.window { - None => self.graph.degree(self.vertex, dir, None), - Some(w) => self - .graph - .degree_window(self.vertex, w.start, w.end, dir, None), - } + self.graph.degree(self.vertex, dir, None) } fn edges(&self) -> EdgeList { let g = self.graph.clone(); let dir = Direction::BOTH; - match &self.window { - None => Box::new( - self.graph - .vertex_edges_all_layers(self.vertex, dir) - .map(move |e| EdgeView::new(g.clone(), e)), - ), - Some(w) => { - let w = w.clone(); - Box::new( - self.graph - .vertex_edges_window(self.vertex, w.start, w.end, dir, None) - .map(move |e| EdgeView::new_windowed(g.clone(), e, Some(w.clone()))), - ) - } - } + Box::new( + g.vertex_edges_all_layers(self.vertex, dir) + .map(move |e| EdgeView::new(g.clone(), e)), + ) } fn in_edges(&self) -> EdgeList { let g = self.graph.clone(); let dir = Direction::IN; - match &self.window { - None => Box::new( - self.graph - .vertex_edges_all_layers(self.vertex, dir) - .map(move |e| EdgeView::new(g.clone(), e)), - ), - Some(w) => { - let w = w.clone(); - Box::new( - self.graph - .vertex_edges_window(self.vertex, w.start, w.end, dir, None) - .map(move |e| EdgeView::new_windowed(g.clone(), e, Some(w.clone()))), - ) - } - } + Box::new( + g.vertex_edges_all_layers(self.vertex, dir) + .map(move |e| EdgeView::new(g.clone(), e)), + ) } fn out_edges(&self) -> EdgeList { let g = self.graph.clone(); let dir = Direction::OUT; - match &self.window { - None => Box::new( - self.graph - .vertex_edges_all_layers(self.vertex, dir) - .map(move |e| EdgeView::new(g.clone(), e)), - ), - Some(w) => { - let w = w.clone(); - Box::new( - self.graph - .vertex_edges_window(self.vertex, w.start, w.end, dir, None) - .map(move |e| EdgeView::new_windowed(g.clone(), e, Some(w.clone()))), - ) - } - } + Box::new( + g.vertex_edges_all_layers(self.vertex, dir) + .map(move |e| EdgeView::new(g.clone(), e)), + ) } fn neighbours(&self) -> PathFromVertex { let g = self.graph.clone(); let dir = Direction::BOTH; - match &self.window { - None => PathFromVertex::new(g, self, Operations::Neighbours { dir }), - Some(w) => PathFromVertex::new( - g, - self, - Operations::NeighboursWindow { - dir, - t_start: w.start, - t_end: w.end, - }, - ), - } + PathFromVertex::new(g, self, Operations::Neighbours { dir }) } fn in_neighbours(&self) -> PathFromVertex { let g = self.graph.clone(); let dir = Direction::IN; - match &self.window { - None => PathFromVertex::new(g, self, Operations::Neighbours { dir }), - Some(w) => PathFromVertex::new( - g, - self, - Operations::NeighboursWindow { - dir, - t_start: w.start, - t_end: w.end, - }, - ), - } + PathFromVertex::new(g, self, Operations::Neighbours { dir }) } fn out_neighbours(&self) -> PathFromVertex { let g = self.graph.clone(); let dir = Direction::OUT; - match &self.window { - None => PathFromVertex::new(g, self, Operations::Neighbours { dir }), - Some(w) => PathFromVertex::new( - g, - self, - Operations::NeighboursWindow { - dir, - t_start: w.start, - t_end: w.end, - }, - ), - } + PathFromVertex::new(g, self, Operations::Neighbours { dir }) } } impl TimeOps for VertexView { - type WindowedViewType = VertexView; + type WindowedViewType = VertexView>; fn start(&self) -> Option { - match &self.window { - None => self.graph.start(), - Some(w) => Some(w.start), - } + self.graph.start() } fn end(&self) -> Option { - match &self.window { - None => self.graph.end(), - Some(w) => Some(w.end), - } + self.graph.end() } fn window(&self, t_start: i64, t_end: i64) -> Self::WindowedViewType { - Self { - graph: self.graph.clone(), + VertexView { + graph: self.graph.window(t_start, t_end), vertex: self.vertex, - window: Some(self.actual_start(t_start)..self.actual_end(t_end)), } } } @@ -366,7 +237,7 @@ impl VertexListOps for Box> + Box::new(self.map(|v| v.end().map(|t| t - 1))) } - fn window(self, t_start: i64, t_end: i64) -> BoxedIter> { + fn window(self, t_start: i64, t_end: i64) -> BoxedIter>> { Box::new(self.map(move |v| v.window(t_start, t_end))) } @@ -488,7 +359,7 @@ impl VertexListOps for BoxedIter>> { self, t_start: i64, t_end: i64, - ) -> BoxedIter>> { + ) -> BoxedIter>>> { Box::new(self.map(move |it| it.window(t_start, t_end))) } diff --git a/docbrown/src/db/vertices.rs b/docbrown/src/db/vertices.rs index 0bd922e7..35ba7797 100644 --- a/docbrown/src/db/vertices.rs +++ b/docbrown/src/db/vertices.rs @@ -1,6 +1,7 @@ use crate::core::tgraph::VertexRef; use crate::core::{Direction, Prop}; use crate::db::edge::EdgeView; +use crate::db::graph_window::WindowedGraph; use crate::db::path::{Operations, PathFromGraph}; use crate::db::vertex::VertexView; use crate::db::view_api::BoxedIter; @@ -10,24 +11,17 @@ use std::ops::Range; #[derive(Clone)] pub struct Vertices { - graph: G, - window: Option>, + pub graph: G, } impl Vertices { - pub(crate) fn new(graph: G) -> Vertices { - Self { - graph, - window: None, - } + pub fn new(graph: G) -> Vertices { + Self { graph } } + pub fn iter(&self) -> Box> + Send> { let g = self.graph.clone(); - let w = self.window.clone(); - Box::new( - g.vertex_refs() - .map(move |v| VertexView::new_windowed(g.clone(), v, w.clone())), - ) + Box::new(g.vertex_refs().map(move |v| VertexView::new(g.clone(), v))) } pub fn len(&self) -> usize { @@ -127,71 +121,34 @@ impl VertexViewOps for Vertices { fn neighbours(&self) -> PathFromGraph { let dir = Direction::BOTH; - match &self.window { - None => PathFromGraph::new(self.graph.clone(), Operations::Neighbours { dir }), - Some(w) => PathFromGraph::new( - self.graph.clone(), - Operations::NeighboursWindow { - dir, - t_start: w.start, - t_end: w.end, - }, - ), - } + PathFromGraph::new(self.graph.clone(), Operations::Neighbours { dir }) } fn in_neighbours(&self) -> PathFromGraph { let dir = Direction::IN; - match &self.window { - None => PathFromGraph::new(self.graph.clone(), Operations::Neighbours { dir }), - Some(w) => PathFromGraph::new( - self.graph.clone(), - Operations::NeighboursWindow { - dir, - t_start: w.start, - t_end: w.end, - }, - ), - } + PathFromGraph::new(self.graph.clone(), Operations::Neighbours { dir }) } fn out_neighbours(&self) -> PathFromGraph { let dir = Direction::OUT; - match &self.window { - None => PathFromGraph::new(self.graph.clone(), Operations::Neighbours { dir }), - Some(w) => PathFromGraph::new( - self.graph.clone(), - Operations::NeighboursWindow { - dir, - t_start: w.start, - t_end: w.end, - }, - ), - } + PathFromGraph::new(self.graph.clone(), Operations::Neighbours { dir }) } } impl TimeOps for Vertices { - type WindowedViewType = Self; + type WindowedViewType = Vertices>; fn start(&self) -> Option { - match &self.window { - None => self.graph.start(), - Some(w) => Some(w.start), - } + self.graph.start() } fn end(&self) -> Option { - match &self.window { - None => self.graph.end(), - Some(w) => Some(w.end), - } + self.graph.end() } fn window(&self, t_start: i64, t_end: i64) -> Self::WindowedViewType { - Self { - graph: self.graph.clone(), - window: Some(self.actual_start(t_start)..self.actual_end(t_end)), + Vertices { + graph: self.graph.window(t_start, t_end), } } } diff --git a/docbrown/src/db/view_api/time.rs b/docbrown/src/db/view_api/time.rs index ff52ecab..07f9032e 100644 --- a/docbrown/src/db/view_api/time.rs +++ b/docbrown/src/db/view_api/time.rs @@ -12,22 +12,6 @@ pub trait TimeOps { /// Return the timestamp of the default for perspectives of the view (if any). fn end(&self) -> Option; - /// the larger of `t_start` and `self.start()` (useful for creating nested windows) - fn actual_start(&self, t_start: i64) -> i64 { - match self.start() { - None => t_start, - Some(start) => max(t_start, start), - } - } - - /// the smaller of `t_end` and `self.end()` (useful for creating nested windows) - fn actual_end(&self, t_end: i64) -> i64 { - match self.end() { - None => t_end, - Some(end) => min(t_end, end), - } - } - /// Create a view including all events between `t_start` (inclusive) and `t_end` (exclusive) fn window(&self, t_start: i64, t_end: i64) -> Self::WindowedViewType; diff --git a/docbrown/src/db/view_api/vertex.rs b/docbrown/src/db/view_api/vertex.rs index 4824b777..87b08ac2 100644 --- a/docbrown/src/db/view_api/vertex.rs +++ b/docbrown/src/db/view_api/vertex.rs @@ -1,4 +1,5 @@ use crate::core::Prop; +use crate::db::graph_window::WindowedGraph; use crate::db::vertex::VertexView; use crate::db::view_api::edge::EdgeListOps; use crate::db::view_api::{BoxedIter, GraphViewOps, TimeOps}; @@ -199,10 +200,10 @@ pub trait VertexListOps: self, t_start: i64, t_end: i64, - ) -> BoxedIter>>; + ) -> BoxedIter>>>; /// Create views for the vertices including all events until `end` (inclusive) - fn at(self, end: i64) -> BoxedIter>> { + fn at(self, end: i64) -> BoxedIter>>> { self.window(i64::MIN, end.saturating_add(1)) } diff --git a/python/src/edge.rs b/python/src/edge.rs index 6289743f..8edabc28 100644 --- a/python/src/edge.rs +++ b/python/src/edge.rs @@ -10,6 +10,7 @@ use crate::utils::*; use crate::vertex::PyVertex; use crate::wrappers::prop::Prop; use docbrown::db::edge::EdgeView; +use docbrown::db::graph_window::WindowedGraph; use docbrown::db::view_api::time::WindowSet; use docbrown::db::view_api::*; use itertools::Itertools; @@ -30,6 +31,17 @@ impl From> for PyEdge { } } +impl From>> for PyEdge { + fn from(value: EdgeView>) -> Self { + Self { + edge: EdgeView { + graph: DynamicGraph::new(value.graph), + edge: value.edge, + }, + } + } +} + /// PyEdge is a Python class that represents an edge in the graph. /// An edge is a directed connection between two vertices. #[pymethods] diff --git a/python/src/vertex.rs b/python/src/vertex.rs index 2f1abf81..fc39b255 100644 --- a/python/src/vertex.rs +++ b/python/src/vertex.rs @@ -8,6 +8,7 @@ use crate::utils::{expanding_impl, extract_vertex_ref, rolling_impl, window_impl use crate::wrappers::iterators::*; use crate::wrappers::prop::Prop; use docbrown::core::tgraph::VertexRef; +use docbrown::db::graph_window::WindowedGraph; use docbrown::db::path::{PathFromGraph, PathFromVertex}; use docbrown::db::vertex::VertexView; use docbrown::db::vertices::Vertices; @@ -32,6 +33,17 @@ impl From> for PyVertex { } } +impl From>> for PyVertex { + fn from(value: VertexView>) -> Self { + Self { + vertex: VertexView { + graph: DynamicGraph::new(value.graph), + vertex: value.vertex, + }, + } + } +} + /// Converts a python vertex into a rust vertex. impl From for VertexRef { fn from(value: PyVertex) -> Self { @@ -396,6 +408,14 @@ impl From> for PyVertices { } } +impl From>> for PyVertices { + fn from(value: Vertices>) -> Self { + Self { + vertices: Vertices::new(DynamicGraph::new(value.graph)), + } + } +} + /// Operations on a list of vertices. /// These use all the same functions as a normal vertex except it returns a list of results. #[pymethods] @@ -746,6 +766,17 @@ impl From> for PyPathFromGraph { } } +impl From>> for PyPathFromGraph { + fn from(value: PathFromGraph>) -> Self { + Self { + path: PathFromGraph { + graph: DynamicGraph::new(value.graph), + operations: value.operations, + }, + } + } +} + #[pyclass(name = "PathFromVertex")] pub struct PyPathFromVertex { path: PathFromVertex, @@ -757,6 +788,18 @@ impl From> for PyPathFromVertex { } } +impl From>> for PyPathFromVertex { + fn from(value: PathFromVertex>) -> Self { + Self { + path: PathFromVertex { + graph: DynamicGraph::new(value.graph), + vertex: value.vertex, + operations: value.operations, + }, + } + } +} + #[pymethods] impl PyPathFromVertex { fn __iter__(&self) -> PyVertexIterator {