diff --git a/raphtory/src/algorithms/components/in_components.rs b/raphtory/src/algorithms/components/in_components.rs index bc4225599..d26e2c493 100644 --- a/raphtory/src/algorithms/components/in_components.rs +++ b/raphtory/src/algorithms/components/in_components.rs @@ -134,7 +134,7 @@ pub fn in_component<'graph, G: GraphViewOps<'graph>>( NodeState::new( node.graph.clone(), node.graph.clone(), - distances, + distances.into(), Some(Index::new(nodes)), ) } diff --git a/raphtory/src/algorithms/components/out_components.rs b/raphtory/src/algorithms/components/out_components.rs index e761b893e..519d46a7c 100644 --- a/raphtory/src/algorithms/components/out_components.rs +++ b/raphtory/src/algorithms/components/out_components.rs @@ -137,7 +137,7 @@ pub fn out_component<'graph, G: GraphViewOps<'graph>>( NodeState::new( node.graph.clone(), node.graph.clone(), - distances, + distances.into(), Some(Index::new(nodes)), ) } diff --git a/raphtory/src/db/api/state/lazy_node_state.rs b/raphtory/src/db/api/state/lazy_node_state.rs index b6e83563f..71d5b5741 100644 --- a/raphtory/src/db/api/state/lazy_node_state.rs +++ b/raphtory/src/db/api/state/lazy_node_state.rs @@ -16,7 +16,10 @@ use crate::{ prelude::*, }; use rayon::prelude::*; -use std::fmt::{Debug, Formatter}; +use std::{ + fmt::{Debug, Formatter}, + sync::Arc, +}; #[derive(Clone)] pub struct LazyNodeState<'graph, Op, G, GH = G> { @@ -100,7 +103,7 @@ impl<'graph, Op: NodeOp + 'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'gra NodeState::new( self.nodes.base_graph.clone(), self.nodes.graph.clone(), - values, + values.into(), Some(Index::new(keys)), ) } else { @@ -108,7 +111,7 @@ impl<'graph, Op: NodeOp + 'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'gra NodeState::new( self.nodes.base_graph.clone(), self.nodes.graph.clone(), - values, + values.into(), None, ) } diff --git a/raphtory/src/db/api/state/node_state.rs b/raphtory/src/db/api/state/node_state.rs index c94dfb2f1..e04eef867 100644 --- a/raphtory/src/db/api/state/node_state.rs +++ b/raphtory/src/db/api/state/node_state.rs @@ -84,10 +84,11 @@ impl + From + Send + Sync> Index { } } +#[derive(Clone)] pub struct NodeState<'graph, V, G, GH = G> { base_graph: G, graph: GH, - values: Vec, + values: Arc<[V]>, keys: Option>, _marker: PhantomData<&'graph ()>, } @@ -122,7 +123,7 @@ impl<'graph, V, G: GraphViewOps<'graph>> NodeState<'graph, V, G> { .map(|vid| values[vid.index()].clone()) .collect(), }; - Self::new(graph.clone(), graph, values, index) + Self::new(graph.clone(), graph, values.into(), index) } /// Construct a node state from an eval result, mapping values @@ -147,7 +148,7 @@ impl<'graph, V, G: GraphViewOps<'graph>> NodeState<'graph, V, G> { } impl<'graph, V, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>> NodeState<'graph, V, G, GH> { - pub fn new(base_graph: G, graph: GH, values: Vec, keys: Option>) -> Self { + pub fn new(base_graph: G, graph: GH, values: Arc<[V]>, keys: Option>) -> Self { Self { base_graph, graph, @@ -157,7 +158,7 @@ impl<'graph, V, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>> NodeState<'gr } } - pub fn into_inner(self) -> (Vec, Option>) { + pub fn into_inner(self) -> (Arc<[V]>, Option>) { (self.values, self.keys) } } @@ -219,11 +220,13 @@ impl< } fn into_values(self) -> impl Iterator + 'graph { - self.values.into_iter() + (0..self.values.len()).map(move |i| self.values[i].clone()) } fn into_par_values(self) -> impl ParallelIterator + 'graph { - self.values.into_par_iter() + (0..self.values.len()) + .into_par_iter() + .map(move |i| self.values[i].clone()) } fn iter<'a>( @@ -350,7 +353,7 @@ mod test { let float_state = NodeState { base_graph: g.clone(), graph: g.clone(), - values: vec![0.0f64], + values: [0.0f64].into(), keys: None, _marker: Default::default(), }; @@ -358,7 +361,7 @@ mod test { let int_state = NodeState { base_graph: g.clone(), graph: g.clone(), - values: vec![1i64], + values: [1i64].into(), keys: None, _marker: Default::default(), }; diff --git a/raphtory/src/db/api/state/node_state_ops.rs b/raphtory/src/db/api/state/node_state_ops.rs index ea6efc418..f84e5972c 100644 --- a/raphtory/src/db/api/state/node_state_ops.rs +++ b/raphtory/src/db/api/state/node_state_ops.rs @@ -107,7 +107,7 @@ pub trait NodeStateOps<'graph>: NodeState::new( self.base_graph().clone(), self.graph().clone(), - values, + values.into(), Some(Index::new(keys)), ) } @@ -131,7 +131,7 @@ pub trait NodeStateOps<'graph>: NodeState::new( self.base_graph().clone(), self.graph().clone(), - values, + values.into(), Some(Index::new(keys)), ) } @@ -168,7 +168,7 @@ pub trait NodeStateOps<'graph>: NodeState::new( self.base_graph().clone(), self.graph().clone(), - values, + values.into(), Some(Index::new(keys)), ) }