Skip to content

Commit bda5e77

Browse files
committed
add review suggestions
1 parent e8eb639 commit bda5e77

26 files changed

+290
-333
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::{
2323
};
2424

2525
#[derive(Clone)]
26-
pub struct LazyNodeState<'graph, Op, G, GH, F = Const<bool>> {
26+
pub struct LazyNodeState<'graph, Op, G, GH = G, F = Const<bool>> {
2727
nodes: Nodes<'graph, G, GH, F>,
2828
pub(crate) op: Op,
2929
}
@@ -305,7 +305,7 @@ mod test {
305305
db::api::{
306306
state::{
307307
lazy_node_state::LazyNodeState,
308-
ops::node::{Degree, NodeOp},
308+
ops::node::NodeOp,
309309
},
310310
view::IntoDynamic,
311311
},
@@ -314,6 +314,7 @@ mod test {
314314
use raphtory_api::core::{entities::VID, Direction};
315315
use raphtory_storage::core_ops::CoreGraphOps;
316316
use std::sync::Arc;
317+
use crate::db::api::state::ops::Degree;
317318

318319
struct TestWrapper<Op: NodeOp>(Op);
319320
#[test]

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use raphtory_storage::graph::{graph::GraphStorage, nodes::node_storage_ops::Node
1010
use std::sync::Arc;
1111
use raphtory_api::core::storage::arc_str::OptionAsStr;
1212
use raphtory_storage::core_ops::CoreGraphOps;
13+
use crate::db::api::state::ops::TypeId;
1314
use crate::db::api::view::internal::GraphView;
15+
use crate::db::graph::create_node_type_filter;
1416
use crate::db::graph::views::filter::internal::CreateFilter;
1517
use crate::db::graph::views::filter::model::node_filter::NodeFilter;
1618
use crate::db::graph::views::filter::node_filtered_graph::NodeFilteredGraph;
@@ -136,4 +138,84 @@ impl<G: GraphView> NodeOp for NodePropertyFilterOp<G> {
136138
self.filter
137139
.matches_node(&self.graph, self.prop_id, node.as_ref())
138140
}
141+
}
142+
143+
#[derive(Debug, Clone, PartialEq, Eq)]
144+
pub struct OrOp<L, R> {
145+
pub(crate) left: L,
146+
pub(crate) right: R,
147+
}
148+
149+
impl<L, R> NodeOp for OrOp<L, R>
150+
where
151+
L: NodeOp<Output = bool>,
152+
R: NodeOp<Output = bool>,
153+
{
154+
type Output = bool;
155+
156+
fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output {
157+
self.left.apply(storage, node) || self.right.apply(storage, node)
158+
}
159+
}
160+
161+
impl<L, R> IntoDynNodeOp for OrOp<L, R> where Self: NodeOp + 'static {}
162+
163+
164+
#[derive(Debug, Clone, PartialEq, Eq)]
165+
pub struct AndOp<L, R> {
166+
pub(crate) left: L,
167+
pub(crate) right: R,
168+
}
169+
170+
impl<L, R> NodeOp for AndOp<L, R>
171+
where
172+
L: NodeOp<Output = bool>,
173+
R: NodeOp<Output = bool>,
174+
{
175+
type Output = bool;
176+
177+
fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output {
178+
self.left.apply(storage, node) && self.right.apply(storage, node)
179+
}
180+
}
181+
182+
impl<L, R> IntoDynNodeOp for AndOp<L, R> where Self: NodeOp + 'static {}
183+
184+
#[derive(Debug, Clone, PartialEq, Eq)]
185+
pub struct NotOp<T>(pub(crate) T);
186+
187+
impl<T> IntoDynNodeOp for NotOp<T> where Self: NodeOp + 'static {}
188+
189+
impl<T> NodeOp for NotOp<T>
190+
where
191+
T: NodeOp<Output = bool>,
192+
{
193+
type Output = bool;
194+
195+
fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output {
196+
!self.0.apply(storage, node)
197+
}
198+
}
199+
200+
pub type NodeTypeFilterOp = Mask<TypeId>;
201+
202+
impl NodeTypeFilterOp {
203+
pub fn new_from_values<I: IntoIterator<Item = V>, V: AsRef<str>>(
204+
node_types: I,
205+
view: impl GraphView,
206+
) -> Self {
207+
let mask = create_node_type_filter(view.node_meta().node_type_meta(), node_types);
208+
TypeId.mask(mask)
209+
}
210+
}
211+
212+
#[cfg(test)]
213+
mod test {
214+
use crate::db::api::state::ops::{Const, NodeFilterOp};
215+
216+
#[test]
217+
fn test_const() {
218+
let c = Const(true);
219+
assert!(!c.is_filtered());
220+
}
139221
}

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,74 @@ mod properties;
66
pub use history::*;
77
pub use node::*;
88
pub use properties::*;
9+
use raphtory_api::core::Direction;
10+
use raphtory_api::core::entities::VID;
11+
use raphtory_storage::graph::graph::GraphStorage;
12+
use raphtory_storage::graph::nodes::node_storage_ops::NodeStorageOps;
13+
use raphtory_storage::layer_ops::InternalLayerOps;
14+
use std::sync::Arc;
15+
use std::ops::Deref;
16+
use crate::db::api::view::internal::filtered_node::FilteredNodeStorageOps;
17+
use crate::db::api::view::internal::{FilterOps, FilterState, GraphView};
18+
19+
#[derive(Clone)]
20+
pub struct NotANodeFilter;
21+
22+
impl NodeOp for NotANodeFilter {
23+
type Output = bool;
24+
25+
fn apply(&self, _storage: &GraphStorage, _node: VID) -> Self::Output {
26+
panic!("Not a node filter")
27+
}
28+
}
29+
30+
#[derive(Debug, Clone)]
31+
pub struct Degree<G> {
32+
pub(crate) dir: Direction,
33+
pub(crate) view: G,
34+
}
35+
36+
impl<G: GraphView> NodeOp for Degree<G> {
37+
type Output = usize;
38+
39+
fn apply(&self, storage: &GraphStorage, node: VID) -> usize {
40+
let node = storage.core_node(node);
41+
if matches!(self.view.filter_state(), FilterState::Neither) {
42+
node.degree(self.view.layer_ids(), self.dir)
43+
} else {
44+
node.filtered_neighbours_iter(&self.view, self.view.layer_ids(), self.dir)
45+
.count()
46+
}
47+
}
48+
}
49+
50+
impl<G: GraphView + 'static> IntoDynNodeOp for Degree<G> {}
51+
52+
#[derive(Debug, Copy, Clone)]
53+
pub struct Map<Op: NodeOp, V> {
54+
op: Op,
55+
map: fn(Op::Output) -> V,
56+
}
57+
58+
impl<Op: NodeOp, V: Clone + Send + Sync> NodeOp for Map<Op, V> {
59+
type Output = V;
60+
61+
fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output {
62+
(self.map)(self.op.apply(storage, node))
63+
}
64+
}
65+
66+
impl<Op: NodeOp + 'static, V: Clone + Send + Sync + 'static> IntoDynNodeOp for Map<Op, V> {}
67+
68+
impl<'a, V: Clone + Send + Sync> NodeOp for Arc<dyn NodeOp<Output = V> + 'a> {
69+
type Output = V;
70+
fn apply(&self, storage: &GraphStorage, node: VID) -> V {
71+
self.deref().apply(storage, node)
72+
}
73+
}
74+
75+
impl<V: Clone + Send + Sync + 'static> IntoDynNodeOp for Arc<dyn NodeOp<Output = V>> {
76+
fn into_dynamic(self) -> Arc<dyn NodeOp<Output = Self::Output>> {
77+
self.clone()
78+
}
79+
}
Lines changed: 7 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1-
use crate::db::{
2-
api::{
3-
state::ops::filter::{Mask, MaskOp},
4-
view::internal::{
5-
time_semantics::filtered_node::FilteredNodeStorageOps, FilterOps, FilterState,
6-
GraphView,
7-
},
8-
},
9-
graph::{
10-
create_node_type_filter,
11-
views::filter::model::{and_filter::AndOp, not_filter::NotOp, or_filter::OrOp},
12-
},
13-
};
141
use raphtory_api::core::{
152
entities::{GID, VID},
16-
storage::arc_str::ArcStr,
17-
Direction,
3+
storage::arc_str::ArcStr
4+
,
185
};
196
use raphtory_storage::{
207
core_ops::CoreGraphOps,
21-
graph::{graph::GraphStorage, nodes::node_storage_ops::NodeStorageOps},
8+
graph::graph::GraphStorage,
229
};
23-
use std::{ops::Deref, sync::Arc};
10+
use std::sync::Arc;
11+
use crate::db::api::state::ops::filter::{AndOp, NotOp, OrOp};
12+
use crate::db::api::state::ops::Map;
2413

2514
pub trait NodeFilterOp: NodeOp<Output = bool> + Clone {
2615
fn is_filtered(&self) -> bool;
@@ -32,17 +21,6 @@ pub trait NodeFilterOp: NodeOp<Output = bool> + Clone {
3221
fn not(self) -> NotOp<Self>;
3322
}
3423

35-
#[derive(Clone)]
36-
pub struct NotANodeFilter;
37-
38-
impl NodeOp for NotANodeFilter {
39-
type Output = bool;
40-
41-
fn apply(&self, _storage: &GraphStorage, _node: VID) -> Self::Output {
42-
panic!("Not a node filter")
43-
}
44-
}
45-
4624
impl<Op: NodeOp<Output = bool> + Clone> NodeFilterOp for Op {
4725
fn is_filtered(&self) -> bool {
4826
// If there is a const true value, it is not filtered
@@ -115,47 +93,6 @@ where
11593

11694
impl<Left, Right> IntoDynNodeOp for Eq<Left, Right> where Eq<Left, Right>: NodeOp + 'static {}
11795

118-
impl<L, R> NodeOp for AndOp<L, R>
119-
where
120-
L: NodeOp<Output = bool>,
121-
R: NodeOp<Output = bool>,
122-
{
123-
type Output = bool;
124-
125-
fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output {
126-
self.left.apply(storage, node) && self.right.apply(storage, node)
127-
}
128-
}
129-
130-
impl<L, R> IntoDynNodeOp for AndOp<L, R> where Self: NodeOp + 'static {}
131-
132-
impl<L, R> NodeOp for OrOp<L, R>
133-
where
134-
L: NodeOp<Output = bool>,
135-
R: NodeOp<Output = bool>,
136-
{
137-
type Output = bool;
138-
139-
fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output {
140-
self.left.apply(storage, node) || self.right.apply(storage, node)
141-
}
142-
}
143-
144-
impl<L, R> IntoDynNodeOp for OrOp<L, R> where Self: NodeOp + 'static {}
145-
146-
impl<T> NodeOp for NotOp<T>
147-
where
148-
T: NodeOp<Output = bool>,
149-
{
150-
type Output = bool;
151-
152-
fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output {
153-
!self.0.apply(storage, node)
154-
}
155-
}
156-
157-
impl<T> IntoDynNodeOp for NotOp<T> where Self: NodeOp + 'static {}
158-
15996
#[derive(Clone, Copy, Debug)]
16097
pub struct Const<V>(pub V);
16198

@@ -204,6 +141,7 @@ impl IntoDynNodeOp for Id {}
204141

205142
#[derive(Debug, Copy, Clone)]
206143
pub struct Type;
144+
207145
impl NodeOp for Type {
208146
type Output = Option<ArcStr>;
209147

@@ -225,77 +163,3 @@ impl NodeOp for TypeId {
225163
}
226164

227165
impl IntoDynNodeOp for TypeId {}
228-
229-
#[derive(Debug, Clone)]
230-
pub struct Degree<G> {
231-
pub(crate) dir: Direction,
232-
pub(crate) view: G,
233-
}
234-
235-
impl<G: GraphView> NodeOp for Degree<G> {
236-
type Output = usize;
237-
238-
fn apply(&self, storage: &GraphStorage, node: VID) -> usize {
239-
let node = storage.core_node(node);
240-
if matches!(self.view.filter_state(), FilterState::Neither) {
241-
node.degree(self.view.layer_ids(), self.dir)
242-
} else {
243-
node.filtered_neighbours_iter(&self.view, self.view.layer_ids(), self.dir)
244-
.count()
245-
}
246-
}
247-
}
248-
249-
impl<G: GraphView + 'static> IntoDynNodeOp for Degree<G> {}
250-
251-
impl<'a, V: Clone + Send + Sync> NodeOp for Arc<dyn NodeOp<Output = V> + 'a> {
252-
type Output = V;
253-
fn apply(&self, storage: &GraphStorage, node: VID) -> V {
254-
self.deref().apply(storage, node)
255-
}
256-
}
257-
258-
impl<V: Clone + Send + Sync + 'static> IntoDynNodeOp for Arc<dyn NodeOp<Output = V>> {
259-
fn into_dynamic(self) -> Arc<dyn NodeOp<Output = Self::Output>> {
260-
self.clone()
261-
}
262-
}
263-
264-
#[derive(Debug, Copy, Clone)]
265-
pub struct Map<Op: NodeOp, V> {
266-
op: Op,
267-
map: fn(Op::Output) -> V,
268-
}
269-
270-
impl<Op: NodeOp, V: Clone + Send + Sync> NodeOp for Map<Op, V> {
271-
type Output = V;
272-
273-
fn apply(&self, storage: &GraphStorage, node: VID) -> Self::Output {
274-
(self.map)(self.op.apply(storage, node))
275-
}
276-
}
277-
278-
impl<Op: NodeOp + 'static, V: Clone + Send + Sync + 'static> IntoDynNodeOp for Map<Op, V> {}
279-
280-
pub type NodeTypeFilterOp = Mask<TypeId>;
281-
282-
impl NodeTypeFilterOp {
283-
pub fn new_from_values<I: IntoIterator<Item = V>, V: AsRef<str>>(
284-
node_types: I,
285-
view: impl GraphView,
286-
) -> Self {
287-
let mask = create_node_type_filter(view.node_meta().node_type_meta(), node_types);
288-
TypeId.mask(mask)
289-
}
290-
}
291-
292-
#[cfg(test)]
293-
mod test {
294-
use crate::db::api::state::ops::{Const, NodeFilterOp};
295-
296-
#[test]
297-
fn test_const() {
298-
let c = Const(true);
299-
assert!(!c.is_filtered());
300-
}
301-
}

raphtory/src/db/api/view/graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use raphtory_storage::{
5050
use rayon::prelude::*;
5151
use rustc_hash::FxHashSet;
5252
use std::sync::{atomic::Ordering, Arc};
53-
use crate::db::api::state::ops::NodeTypeFilterOp;
53+
use crate::db::api::state::ops::filter::NodeTypeFilterOp;
5454
use crate::db::graph::views::filter::node_filtered_graph::NodeFilteredGraph;
5555

5656
/// This trait GraphViewOps defines operations for accessing
File renamed without changes.

0 commit comments

Comments
 (0)