Skip to content

Commit cd13d2f

Browse files
committed
nodeops suggestions from lucas
1 parent 2807c1c commit cd13d2f

File tree

6 files changed

+308
-260
lines changed

6 files changed

+308
-260
lines changed

raphtory/src/db/api/state/lazy_node_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'graph, Op: NodeOp + 'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'gra
173173
let storage = self.graph().core_graph().lock();
174174
self.nodes
175175
.iter_refs()
176-
.map(move |vid| self.op.apply(&storage, vid))
176+
.map(move |vid| self.op.apply(&self.graph(), &storage, vid))
177177
}
178178

179179
fn par_iter_values<'a>(&'a self) -> impl ParallelIterator<Item = Self::Value<'a>> + 'a
Lines changed: 31 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,79 @@
1+
use std::sync::Arc;
12
use crate::{
2-
db::api::{
3-
state::{ops::NodeOpFilter, NodeOp},
4-
view::internal::NodeTimeSemanticsOps,
5-
},
6-
prelude::GraphViewOps,
3+
db::api::{state::NodeOp, view::internal::NodeTimeSemanticsOps},
74
};
85
use itertools::Itertools;
96
use raphtory_api::core::entities::VID;
107
use raphtory_storage::graph::graph::GraphStorage;
8+
use crate::db::api::view::internal::GraphView;
119

1210
#[derive(Debug, Clone)]
13-
pub struct EarliestTime<G> {
14-
pub(crate) graph: G,
15-
}
11+
pub struct EarliestTime;
1612

17-
impl<'graph, G: GraphViewOps<'graph>> NodeOp for EarliestTime<G> {
13+
impl NodeOp for EarliestTime {
1814
type Output = Option<i64>;
1915

20-
fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output {
21-
let semantics = self.graph.node_time_semantics();
16+
fn apply<G: GraphView>(&self, view: &G, storage: &GraphStorage, node: VID) -> Self::Output {
17+
let semantics = view.node_time_semantics();
2218
let node = storage.core_node(node);
23-
semantics.node_earliest_time(node.as_ref(), &self.graph)
24-
}
25-
}
26-
27-
impl<'graph, G: GraphViewOps<'graph>> NodeOpFilter<'graph> for EarliestTime<G> {
28-
type Graph = G;
29-
type Filtered<GH: GraphViewOps<'graph> + 'graph> = EarliestTime<GH>;
30-
31-
fn graph(&self) -> &Self::Graph {
32-
&self.graph
19+
semantics.node_earliest_time(node.as_ref(), view)
3320
}
3421

35-
fn filtered<GH: GraphViewOps<'graph> + 'graph>(
36-
&self,
37-
filtered_graph: GH,
38-
) -> Self::Filtered<GH> {
39-
EarliestTime {
40-
graph: filtered_graph,
41-
}
22+
fn into_dynamic(self) -> Arc<dyn NodeOp<Output = Self::Output>> where Self: Sized {
23+
Arc::new(self)
4224
}
4325
}
4426

4527
#[derive(Debug, Clone)]
46-
pub struct LatestTime<G> {
47-
pub(crate) graph: G,
48-
}
28+
pub struct LatestTime;
4929

50-
impl<'graph, G: GraphViewOps<'graph>> NodeOp for LatestTime<G> {
30+
impl NodeOp for LatestTime {
5131
type Output = Option<i64>;
5232

53-
fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output {
54-
let semantics = self.graph.node_time_semantics();
33+
fn apply<G: GraphView>(&self, view: &G, storage: &GraphStorage, node: VID) -> Self::Output {
34+
let semantics = view.node_time_semantics();
5535
let node = storage.core_node(node);
56-
semantics.node_latest_time(node.as_ref(), &self.graph)
57-
}
58-
}
59-
60-
impl<'graph, G: GraphViewOps<'graph>> NodeOpFilter<'graph> for LatestTime<G> {
61-
type Graph = G;
62-
type Filtered<GH: GraphViewOps<'graph> + 'graph> = LatestTime<GH>;
63-
64-
fn graph(&self) -> &Self::Graph {
65-
&self.graph
36+
semantics.node_latest_time(node.as_ref(), view)
6637
}
6738

68-
fn filtered<GH: GraphViewOps<'graph> + 'graph>(
69-
&self,
70-
filtered_graph: GH,
71-
) -> Self::Filtered<GH> {
72-
LatestTime {
73-
graph: filtered_graph,
74-
}
39+
fn into_dynamic(self) -> Arc<dyn NodeOp<Output = Self::Output>> where Self: Sized {
40+
Arc::new(self)
7541
}
7642
}
7743

7844
#[derive(Debug, Clone)]
79-
pub struct History<G> {
80-
pub(crate) graph: G,
81-
}
45+
pub struct History;
8246

83-
impl<'graph, G: GraphViewOps<'graph>> NodeOp for History<G> {
47+
impl NodeOp for History {
8448
type Output = Vec<i64>;
8549

86-
fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output {
87-
let semantics = self.graph.node_time_semantics();
50+
fn apply<G: GraphView>(&self, view: &G, storage: &GraphStorage, node: VID) -> Self::Output {
51+
let semantics = view.node_time_semantics();
8852
let node = storage.core_node(node);
8953
semantics
90-
.node_history(node.as_ref(), &self.graph)
54+
.node_history(node.as_ref(), view)
9155
.dedup()
9256
.collect()
9357
}
94-
}
95-
96-
impl<'graph, G: GraphViewOps<'graph>> NodeOpFilter<'graph> for History<G> {
97-
type Graph = G;
98-
type Filtered<GH: GraphViewOps<'graph> + 'graph> = History<GH>;
99-
100-
fn graph(&self) -> &Self::Graph {
101-
&self.graph
102-
}
10358

104-
fn filtered<GH: GraphViewOps<'graph> + 'graph>(
105-
&self,
106-
filtered_graph: GH,
107-
) -> Self::Filtered<GH> {
108-
History {
109-
graph: filtered_graph,
110-
}
59+
fn into_dynamic(self) -> Arc<dyn NodeOp<Output = Self::Output>> where Self: Sized {
60+
Arc::new(self)
11161
}
11262
}
11363

11464
#[derive(Debug, Copy, Clone)]
115-
pub struct EdgeHistoryCount<G> {
116-
pub(crate) graph: G,
117-
}
65+
pub struct EdgeHistoryCount;
11866

119-
impl<'graph, G: GraphViewOps<'graph>> NodeOp for EdgeHistoryCount<G> {
67+
impl NodeOp for EdgeHistoryCount {
12068
type Output = usize;
12169

122-
fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output {
70+
fn apply<G: GraphView>(&self, view: &G, storage: &GraphStorage, node: VID) -> Self::Output {
12371
let node = storage.core_node(node);
124-
let ts = self.graph.node_time_semantics();
125-
ts.node_edge_history_count(node.as_ref(), &self.graph)
126-
}
127-
}
128-
129-
impl<'graph, G: GraphViewOps<'graph>> NodeOpFilter<'graph> for EdgeHistoryCount<G> {
130-
type Graph = G;
131-
type Filtered<GH: GraphViewOps<'graph>> = EdgeHistoryCount<GH>;
132-
133-
fn graph(&self) -> &Self::Graph {
134-
&self.graph
72+
let ts = view.node_time_semantics();
73+
ts.node_edge_history_count(node.as_ref(), view)
13574
}
13675

137-
fn filtered<GH: GraphViewOps<'graph>>(&self, graph: GH) -> Self::Filtered<GH> {
138-
EdgeHistoryCount { graph }
76+
fn into_dynamic(self) -> Arc<dyn NodeOp<Output = Self::Output>> where Self: Sized {
77+
Arc::new(self)
13978
}
14079
}

raphtory/src/db/api/state/ops/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
pub(crate) mod history;
2-
pub(crate) mod node;
1+
pub mod history;
2+
pub mod node;
33
mod properties;
44

55
pub use history::*;

0 commit comments

Comments
 (0)