Skip to content

Commit

Permalink
changes as per review
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmurariu committed Nov 28, 2024
1 parent 3047492 commit 093e2c4
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 50 deletions.
39 changes: 0 additions & 39 deletions raphtory/src/core/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize> = 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<usize> = 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()),
}
}
}
}
2 changes: 1 addition & 1 deletion raphtory/src/db/api/view/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down
43 changes: 41 additions & 2 deletions raphtory/src/db/api/view/layer.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -158,3 +158,42 @@ impl<T: SingleLayer, const N: usize> 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<usize> = 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<usize> = 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()),
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ impl<'graph, G: GraphViewOps<'graph>> InheritListOps for CachedView<G> {}
impl<'graph, G: GraphViewOps<'graph>> EdgeFilterOps for CachedView<G> {
#[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]
Expand All @@ -131,10 +131,10 @@ impl<'graph, G: GraphViewOps<'graph>> EdgeFilterOps for CachedView<G> {

impl<'graph, G: GraphViewOps<'graph>> NodeFilterOps for CachedView<G> {
fn nodes_filtered(&self) -> bool {
true
self.graph.nodes_filtered()
}
fn node_list_trusted(&self) -> bool {
false
self.graph.node_list_trusted()
}

#[inline]
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -258,7 +278,7 @@ mod test {
});
}

proptest!(|(edge_list in any::<Vec<(u8, u8, i16, u8)>>().prop_filter("greater than 3",|v| v.len() > 3 ))| {
proptest!(|(edge_list in any::<Vec<(u8, u8, i16, u8)>>().prop_filter("greater than 3",|v| v.len() > 0 ))| {
check(&edge_list);
})
}
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/db/graph/views/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/python/graph/views/graph_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down

0 comments on commit 093e2c4

Please sign in to comment.