From cf176ad279f591777eca394d7143f6841b41178d Mon Sep 17 00:00:00 2001 From: Lucas Jeub Date: Wed, 27 Nov 2024 11:46:42 +0100 Subject: [PATCH] no reason to make a Hashset when building a subgraph anymore --- raphtory/src/db/api/view/graph.rs | 5 ----- raphtory/src/db/graph/views/node_subgraph.rs | 11 +++++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/raphtory/src/db/api/view/graph.rs b/raphtory/src/db/api/view/graph.rs index 3b28576ee..1aa76e7be 100644 --- a/raphtory/src/db/api/view/graph.rs +++ b/raphtory/src/db/api/view/graph.rs @@ -337,11 +337,6 @@ impl<'graph, G: BoxableGraphView + Sized + Clone + 'graph> GraphViewOps<'graph> } fn subgraph, V: AsNodeRef>(&self, nodes: I) -> NodeSubgraph { - let _layer_ids = self.layer_ids(); - let nodes: FxHashSet = nodes - .into_iter() - .flat_map(|v| (&self).node(v).map(|v| v.node)) - .collect(); NodeSubgraph::new(self.clone(), nodes) } diff --git a/raphtory/src/db/graph/views/node_subgraph.rs b/raphtory/src/db/graph/views/node_subgraph.rs index b362845cf..a50a2e932 100644 --- a/raphtory/src/db/graph/views/node_subgraph.rs +++ b/raphtory/src/db/graph/views/node_subgraph.rs @@ -1,5 +1,5 @@ use crate::{ - core::entities::{LayerIds, VID}, + core::entities::{nodes::node_ref::AsNodeRef, LayerIds, VID}, db::api::{ properties::internal::InheritPropertiesOps, state::Index, @@ -50,11 +50,14 @@ impl<'graph, G: GraphViewOps<'graph>> InheritMaterialize for NodeSubgraph {} impl<'graph, G: GraphViewOps<'graph>> InheritLayerOps for NodeSubgraph {} impl<'graph, G: GraphViewOps<'graph>> NodeSubgraph { - pub fn new(graph: G, nodes: impl IntoIterator) -> Self { + pub fn new(graph: G, nodes: impl IntoIterator) -> Self { + let nodes = nodes + .into_iter() + .flat_map(|v| graph.internalise_node(v.as_node_ref())); let mut nodes: Vec<_> = if graph.nodes_filtered() { - nodes.into_iter().filter(|n| graph.has_node(*n)).collect() + nodes.filter(|n| graph.has_node(*n)).collect() } else { - nodes.into_iter().collect() + nodes.collect() }; nodes.sort(); let nodes = Index::new(nodes, graph.unfiltered_num_nodes());