Skip to content

Commit

Permalink
no reason to make a Hashset when building a subgraph anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
ljeub-pometry committed Nov 27, 2024
1 parent 2dc3db9 commit cf176ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
5 changes: 0 additions & 5 deletions raphtory/src/db/api/view/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,6 @@ impl<'graph, G: BoxableGraphView + Sized + Clone + 'graph> GraphViewOps<'graph>
}

fn subgraph<I: IntoIterator<Item = V>, V: AsNodeRef>(&self, nodes: I) -> NodeSubgraph<G> {
let _layer_ids = self.layer_ids();
let nodes: FxHashSet<VID> = nodes
.into_iter()
.flat_map(|v| (&self).node(v).map(|v| v.node))
.collect();
NodeSubgraph::new(self.clone(), nodes)
}

Expand Down
11 changes: 7 additions & 4 deletions raphtory/src/db/graph/views/node_subgraph.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -50,11 +50,14 @@ impl<'graph, G: GraphViewOps<'graph>> InheritMaterialize for NodeSubgraph<G> {}
impl<'graph, G: GraphViewOps<'graph>> InheritLayerOps for NodeSubgraph<G> {}

impl<'graph, G: GraphViewOps<'graph>> NodeSubgraph<G> {
pub fn new(graph: G, nodes: impl IntoIterator<Item = VID>) -> Self {
pub fn new(graph: G, nodes: impl IntoIterator<Item = impl AsNodeRef>) -> 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());
Expand Down

0 comments on commit cf176ad

Please sign in to comment.