From 093e2c4320739ebd947e4f9d44ee091b4f443da8 Mon Sep 17 00:00:00 2001 From: Fabian Murariu Date: Thu, 28 Nov 2024 14:25:48 +0000 Subject: [PATCH] changes as per review --- raphtory/src/core/entities/mod.rs | 39 ----------------- raphtory/src/db/api/view/graph.rs | 2 +- raphtory/src/db/api/view/layer.rs | 43 ++++++++++++++++++- .../views/{masked_graph.rs => cached_view.rs} | 32 +++++++++++--- raphtory/src/db/graph/views/mod.rs | 2 +- raphtory/src/python/graph/views/graph_view.rs | 2 +- 6 files changed, 70 insertions(+), 50 deletions(-) rename raphtory/src/db/graph/views/{masked_graph.rs => cached_view.rs} (91%) diff --git a/raphtory/src/core/entities/mod.rs b/raphtory/src/core/entities/mod.rs index a7df12e81..0147447ea 100644 --- a/raphtory/src/core/entities/mod.rs +++ b/raphtory/src/core/entities/mod.rs @@ -4,42 +4,3 @@ pub mod nodes; pub mod properties; pub use raphtory_api::core::entities::*; - -pub fn diff<'a>( - left: &LayerIds, - graph: impl crate::prelude::GraphViewOps<'a>, - other: &LayerIds, -) -> LayerIds { - match (left, other) { - (LayerIds::None, _) => LayerIds::None, - (this, LayerIds::None) => this.clone(), - (_, LayerIds::All) => LayerIds::None, - (LayerIds::One(id), other) => { - if other.contains(id) { - LayerIds::None - } else { - LayerIds::One(*id) - } - } - (LayerIds::Multiple(ids), other) => { - let ids: Vec = ids.iter().filter(|id| !other.contains(id)).collect(); - match ids.len() { - 0 => LayerIds::None, - 1 => LayerIds::One(ids[0]), - _ => LayerIds::Multiple(ids.into()), - } - } - (LayerIds::All, other) => { - let all_layer_ids: Vec = graph - .unique_layers() - .map(|name| graph.get_layer_id(name.as_ref()).unwrap()) - .filter(|id| !other.contains(id)) - .collect(); - match all_layer_ids.len() { - 0 => LayerIds::None, - 1 => LayerIds::One(all_layer_ids[0]), - _ => LayerIds::Multiple(all_layer_ids.into()), - } - } - } -} diff --git a/raphtory/src/db/api/view/graph.rs b/raphtory/src/db/api/view/graph.rs index f5a5f4b80..29bc7cbfc 100644 --- a/raphtory/src/db/api/view/graph.rs +++ b/raphtory/src/db/api/view/graph.rs @@ -22,7 +22,7 @@ use crate::{ node::NodeView, nodes::Nodes, views::{ - masked_graph::CachedView, node_subgraph::NodeSubgraph, + cached_view::CachedView, node_subgraph::NodeSubgraph, node_type_filtered_subgraph::TypeFilteredSubgraph, }, }, diff --git a/raphtory/src/db/api/view/layer.rs b/raphtory/src/db/api/view/layer.rs index b2763f45f..b784e8289 100644 --- a/raphtory/src/db/api/view/layer.rs +++ b/raphtory/src/db/api/view/layer.rs @@ -1,11 +1,11 @@ use crate::{ - core::{entities::diff, utils::errors::GraphError}, + core::utils::errors::GraphError, db::{ api::view::internal::{InternalLayerOps, OneHopFilter}, graph::views::layer_graph::LayeredGraph, }, }; -use raphtory_api::core::storage::arc_str::ArcStr; +use raphtory_api::core::{entities::LayerIds, storage::arc_str::ArcStr}; use std::sync::Arc; /// Trait defining layer operations @@ -158,3 +158,42 @@ impl From<[T; N]> for Layer { } } } + +pub fn diff<'a>( + left: &LayerIds, + graph: impl crate::prelude::GraphViewOps<'a>, + other: &LayerIds, +) -> LayerIds { + match (left, other) { + (LayerIds::None, _) => LayerIds::None, + (this, LayerIds::None) => this.clone(), + (_, LayerIds::All) => LayerIds::None, + (LayerIds::One(id), other) => { + if other.contains(id) { + LayerIds::None + } else { + LayerIds::One(*id) + } + } + (LayerIds::Multiple(ids), other) => { + let ids: Vec = ids.iter().filter(|id| !other.contains(id)).collect(); + match ids.len() { + 0 => LayerIds::None, + 1 => LayerIds::One(ids[0]), + _ => LayerIds::Multiple(ids.into()), + } + } + (LayerIds::All, other) => { + let all_layer_ids: Vec = graph + .unique_layers() + .map(|name| graph.get_layer_id(name.as_ref()).unwrap()) + .filter(|id| !other.contains(id)) + .collect(); + match all_layer_ids.len() { + 0 => LayerIds::None, + 1 => LayerIds::One(all_layer_ids[0]), + _ => LayerIds::Multiple(all_layer_ids.into()), + } + } + } +} diff --git a/raphtory/src/db/graph/views/masked_graph.rs b/raphtory/src/db/graph/views/cached_view.rs similarity index 91% rename from raphtory/src/db/graph/views/masked_graph.rs rename to raphtory/src/db/graph/views/cached_view.rs index 0fc3e8c94..d4d46fa58 100644 --- a/raphtory/src/db/graph/views/masked_graph.rs +++ b/raphtory/src/db/graph/views/cached_view.rs @@ -101,17 +101,17 @@ impl<'graph, G: GraphViewOps<'graph>> InheritListOps for CachedView {} impl<'graph, G: GraphViewOps<'graph>> EdgeFilterOps for CachedView { #[inline] fn edges_filtered(&self) -> bool { - true + self.graph.edges_filtered() } #[inline] fn edge_list_trusted(&self) -> bool { - false + self.graph.edge_list_trusted() } #[inline] fn edge_filter_includes_node_filter(&self) -> bool { - self.graph.edge_filter_includes_node_filter() + true } #[inline] @@ -131,10 +131,10 @@ impl<'graph, G: GraphViewOps<'graph>> EdgeFilterOps for CachedView { impl<'graph, G: GraphViewOps<'graph>> NodeFilterOps for CachedView { fn nodes_filtered(&self) -> bool { - true + self.graph.nodes_filtered() } fn node_list_trusted(&self) -> bool { - false + self.graph.node_list_trusted() } #[inline] @@ -169,6 +169,26 @@ mod test { use itertools::Itertools; use proptest::prelude::*; + #[test] + fn empty_graph() { + let graph = Graph::new(); + test_storage!(&graph, |graph| { + let sg = graph.cache_view(); + assert_graph_equal(&sg, &graph); + }); + } + + #[test] + fn empty_window() { + let graph = Graph::new(); + graph.add_edge(1, 1, 1, NO_PROPS, None).unwrap(); + test_storage!(&graph, |graph| { + let window = graph.window(2, 3); + let sg = window.cache_view(); + assert_graph_equal(&window, &sg); + }); + } + #[test] fn test_materialize_no_edges() { let graph = Graph::new(); @@ -258,7 +278,7 @@ mod test { }); } - proptest!(|(edge_list in any::>().prop_filter("greater than 3",|v| v.len() > 3 ))| { + proptest!(|(edge_list in any::>().prop_filter("greater than 3",|v| v.len() > 0 ))| { check(&edge_list); }) } diff --git a/raphtory/src/db/graph/views/mod.rs b/raphtory/src/db/graph/views/mod.rs index cea08f8d8..4dba9bed1 100644 --- a/raphtory/src/db/graph/views/mod.rs +++ b/raphtory/src/db/graph/views/mod.rs @@ -1,6 +1,6 @@ +pub mod cached_view; pub mod deletion_graph; pub mod layer_graph; -pub mod masked_graph; pub mod node_subgraph; pub mod node_type_filtered_subgraph; pub mod property_filter; diff --git a/raphtory/src/python/graph/views/graph_view.rs b/raphtory/src/python/graph/views/graph_view.rs index c6ad7102b..9ba3e2a7d 100644 --- a/raphtory/src/python/graph/views/graph_view.rs +++ b/raphtory/src/python/graph/views/graph_view.rs @@ -17,8 +17,8 @@ use crate::{ node::NodeView, nodes::Nodes, views::{ + cached_view::CachedView, layer_graph::LayeredGraph, - masked_graph::CachedView, node_subgraph::NodeSubgraph, node_type_filtered_subgraph::TypeFilteredSubgraph, property_filter::{