|
| 1 | +use crate::{ |
| 2 | + db::{ |
| 3 | + api::{ |
| 4 | + properties::internal::InheritPropertiesOps, |
| 5 | + view::internal::{ |
| 6 | + Immutable, InheritEdgeHistoryFilter, InheritEdgeLayerFilterOps, |
| 7 | + InheritExplodedEdgeFilterOps, InheritLayerOps, InheritListOps, InheritMaterialize, |
| 8 | + InheritNodeFilterOps, InheritNodeHistoryFilter, InheritStorageOps, |
| 9 | + InheritTimeSemantics, InternalEdgeFilterOps, Static, |
| 10 | + }, |
| 11 | + }, |
| 12 | + graph::views::filter::model::{edge_filter::Endpoint, node_filter::CompositeNodeFilter}, |
| 13 | + }, |
| 14 | + prelude::GraphViewOps, |
| 15 | +}; |
| 16 | +use raphtory_api::{core::entities::LayerIds, inherit::Base}; |
| 17 | +use raphtory_storage::{ |
| 18 | + core_ops::InheritCoreGraphOps, |
| 19 | + graph::edges::{edge_ref::EdgeStorageRef, edge_storage_ops::EdgeStorageOps}, |
| 20 | +}; |
| 21 | + |
| 22 | +#[derive(Debug, Clone)] |
| 23 | +pub struct EdgeNodeFilteredGraph<G> { |
| 24 | + graph: G, |
| 25 | + endpoint: Endpoint, |
| 26 | + filter: CompositeNodeFilter, |
| 27 | +} |
| 28 | + |
| 29 | +impl<G> EdgeNodeFilteredGraph<G> { |
| 30 | + #[inline] |
| 31 | + pub fn new(graph: G, endpoint: Endpoint, node_cf: CompositeNodeFilter) -> Self { |
| 32 | + Self { |
| 33 | + graph, |
| 34 | + endpoint, |
| 35 | + filter: node_cf, |
| 36 | + } |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +impl<G> Base for EdgeNodeFilteredGraph<G> { |
| 41 | + type Base = G; |
| 42 | + #[inline] |
| 43 | + fn base(&self) -> &Self::Base { |
| 44 | + &self.graph |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +impl<G> Static for EdgeNodeFilteredGraph<G> {} |
| 49 | +impl<G> Immutable for EdgeNodeFilteredGraph<G> {} |
| 50 | + |
| 51 | +impl<'graph, G: GraphViewOps<'graph>> InheritCoreGraphOps for EdgeNodeFilteredGraph<G> {} |
| 52 | +impl<'graph, G: GraphViewOps<'graph>> InheritStorageOps for EdgeNodeFilteredGraph<G> {} |
| 53 | +impl<'graph, G: GraphViewOps<'graph>> InheritLayerOps for EdgeNodeFilteredGraph<G> {} |
| 54 | +impl<'graph, G: GraphViewOps<'graph>> InheritListOps for EdgeNodeFilteredGraph<G> {} |
| 55 | +impl<'graph, G: GraphViewOps<'graph>> InheritMaterialize for EdgeNodeFilteredGraph<G> {} |
| 56 | +impl<'graph, G: GraphViewOps<'graph>> InheritNodeFilterOps for EdgeNodeFilteredGraph<G> {} |
| 57 | +impl<'graph, G: GraphViewOps<'graph>> InheritPropertiesOps for EdgeNodeFilteredGraph<G> {} |
| 58 | +impl<'graph, G: GraphViewOps<'graph>> InheritTimeSemantics for EdgeNodeFilteredGraph<G> {} |
| 59 | +impl<'graph, G: GraphViewOps<'graph>> InheritNodeHistoryFilter for EdgeNodeFilteredGraph<G> {} |
| 60 | +impl<'graph, G: GraphViewOps<'graph>> InheritEdgeHistoryFilter for EdgeNodeFilteredGraph<G> {} |
| 61 | +impl<'graph, G: GraphViewOps<'graph>> InheritEdgeLayerFilterOps for EdgeNodeFilteredGraph<G> {} |
| 62 | +impl<'graph, G: GraphViewOps<'graph>> InheritExplodedEdgeFilterOps for EdgeNodeFilteredGraph<G> {} |
| 63 | + |
| 64 | +impl<'graph, G: GraphViewOps<'graph>> InternalEdgeFilterOps for EdgeNodeFilteredGraph<G> { |
| 65 | + #[inline] |
| 66 | + fn internal_edge_filtered(&self) -> bool { |
| 67 | + true |
| 68 | + } |
| 69 | + |
| 70 | + #[inline] |
| 71 | + fn internal_edge_list_trusted(&self) -> bool { |
| 72 | + false |
| 73 | + } |
| 74 | + |
| 75 | + #[inline] |
| 76 | + fn internal_filter_edge(&self, edge: EdgeStorageRef, layer_ids: &LayerIds) -> bool { |
| 77 | + if !self.graph.internal_filter_edge(edge, layer_ids) { |
| 78 | + return false; |
| 79 | + } |
| 80 | + |
| 81 | + // Fetch the endpoint node and delegate to the node composite filter. |
| 82 | + let ok = match self.endpoint { |
| 83 | + Endpoint::Src => self |
| 84 | + .filter |
| 85 | + .matches_node(&self.graph, self.graph.core_node(edge.src()).as_ref()), |
| 86 | + Endpoint::Dst => self |
| 87 | + .filter |
| 88 | + .matches_node(&self.graph, self.graph.core_node(edge.dst()).as_ref()), |
| 89 | + }; |
| 90 | + ok |
| 91 | + } |
| 92 | +} |
0 commit comments