Skip to content
This repository was archived by the owner on Apr 26, 2023. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 10 additions & 44 deletions docbrown/src/db/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,8 +22,7 @@ pub struct EdgeView<G: GraphViewOps> {
/// A view of an edge in the graph.
pub graph: G,
/// A reference to the edge.
edge: EdgeRef,
window: Option<Range<i64>>,
pub edge: EdgeRef,
}

impl<G: GraphViewOps> Debug for EdgeView<G> {
Expand All @@ -47,19 +47,7 @@ impl<G: GraphViewOps> EdgeView<G> {
///
/// 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<Range<i64>>) -> EdgeView<G> {
EdgeView {
graph,
edge,
window,
}
EdgeView { graph, edge }
}

/// Returns a reference to the underlying edge reference.
Expand Down Expand Up @@ -102,15 +90,7 @@ impl<G: GraphViewOps> EdgeView<G> {
}

pub fn history(&self) -> Vec<i64> {
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<String, Prop> {
Expand Down Expand Up @@ -213,14 +193,7 @@ impl<G: GraphViewOps> EdgeView<G> {
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
Expand All @@ -245,27 +218,20 @@ impl<G: GraphViewOps> EdgeView<G> {
}

impl<G: GraphViewOps> TimeOps for EdgeView<G> {
type WindowedViewType = EdgeView<G>;
type WindowedViewType = EdgeView<WindowedGraph<G>>;

fn start(&self) -> Option<i64> {
match &self.window {
None => self.graph.start(),
Some(w) => Some(w.start),
}
self.graph.start()
}

fn end(&self) -> Option<i64> {
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)),
}
}
}
Expand Down
17 changes: 16 additions & 1 deletion docbrown/src/db/graph_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -813,7 +814,11 @@ impl<G: GraphViewOps> GraphViewInternalOps for WindowedGraph<G> {
/// - `GraphError` - Raised if edge does not exist

fn edge_timestamps(&self, e: EdgeRef, window: Option<Range<i64>>) -> Vec<i64> {
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
Expand Down Expand Up @@ -1052,6 +1057,16 @@ impl<G: GraphViewInternalOps> WindowedGraph<G> {
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)]
Expand Down
Loading