|
| 1 | +use std::sync::Arc; |
1 | 2 | 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}, |
7 | 4 | }; |
8 | 5 | use itertools::Itertools; |
9 | 6 | use raphtory_api::core::entities::VID; |
10 | 7 | use raphtory_storage::graph::graph::GraphStorage; |
| 8 | +use crate::db::api::view::internal::GraphView; |
11 | 9 |
|
12 | 10 | #[derive(Debug, Clone)] |
13 | | -pub struct EarliestTime<G> { |
14 | | - pub(crate) graph: G, |
15 | | -} |
| 11 | +pub struct EarliestTime; |
16 | 12 |
|
17 | | -impl<'graph, G: GraphViewOps<'graph>> NodeOp for EarliestTime<G> { |
| 13 | +impl NodeOp for EarliestTime { |
18 | 14 | type Output = Option<i64>; |
19 | 15 |
|
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(); |
22 | 18 | 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) |
33 | 20 | } |
34 | 21 |
|
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) |
42 | 24 | } |
43 | 25 | } |
44 | 26 |
|
45 | 27 | #[derive(Debug, Clone)] |
46 | | -pub struct LatestTime<G> { |
47 | | - pub(crate) graph: G, |
48 | | -} |
| 28 | +pub struct LatestTime; |
49 | 29 |
|
50 | | -impl<'graph, G: GraphViewOps<'graph>> NodeOp for LatestTime<G> { |
| 30 | +impl NodeOp for LatestTime { |
51 | 31 | type Output = Option<i64>; |
52 | 32 |
|
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(); |
55 | 35 | 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) |
66 | 37 | } |
67 | 38 |
|
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) |
75 | 41 | } |
76 | 42 | } |
77 | 43 |
|
78 | 44 | #[derive(Debug, Clone)] |
79 | | -pub struct History<G> { |
80 | | - pub(crate) graph: G, |
81 | | -} |
| 45 | +pub struct History; |
82 | 46 |
|
83 | | -impl<'graph, G: GraphViewOps<'graph>> NodeOp for History<G> { |
| 47 | +impl NodeOp for History { |
84 | 48 | type Output = Vec<i64>; |
85 | 49 |
|
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(); |
88 | 52 | let node = storage.core_node(node); |
89 | 53 | semantics |
90 | | - .node_history(node.as_ref(), &self.graph) |
| 54 | + .node_history(node.as_ref(), view) |
91 | 55 | .dedup() |
92 | 56 | .collect() |
93 | 57 | } |
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 | | - } |
103 | 58 |
|
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) |
111 | 61 | } |
112 | 62 | } |
113 | 63 |
|
114 | 64 | #[derive(Debug, Copy, Clone)] |
115 | | -pub struct EdgeHistoryCount<G> { |
116 | | - pub(crate) graph: G, |
117 | | -} |
| 65 | +pub struct EdgeHistoryCount; |
118 | 66 |
|
119 | | -impl<'graph, G: GraphViewOps<'graph>> NodeOp for EdgeHistoryCount<G> { |
| 67 | +impl NodeOp for EdgeHistoryCount { |
120 | 68 | type Output = usize; |
121 | 69 |
|
122 | | - fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output { |
| 70 | + fn apply<G: GraphView>(&self, view: &G, storage: &GraphStorage, node: VID) -> Self::Output { |
123 | 71 | 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) |
135 | 74 | } |
136 | 75 |
|
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) |
139 | 78 | } |
140 | 79 | } |
0 commit comments