diff --git a/raphtory/src/core/entities/edges/edge_store.rs b/raphtory/src/core/entities/edges/edge_store.rs index ea47415f0..de6f95690 100644 --- a/raphtory/src/core/entities/edges/edge_store.rs +++ b/raphtory/src/core/entities/edges/edge_store.rs @@ -38,7 +38,17 @@ pub struct EdgeStore { #[derive(Serialize, Deserialize, Debug, Default, PartialEq)] pub struct EdgeData { pub(crate) layer: EdgeLayer, - pub(crate) deletions: TimeIndex, + deletions: TimeIndex, +} + +impl EdgeData { + pub fn deletions(&self) -> &TimeIndex { + &self.deletions + } + + pub fn deletions_mut(&mut self) -> &mut TimeIndex { + &mut self.deletions + } } pub trait EdgeDataLike<'a> { diff --git a/raphtory/src/core/entities/graph/edges.rs b/raphtory/src/core/entities/graph/edges.rs index db75aff1e..dfe732834 100644 --- a/raphtory/src/core/entities/graph/edges.rs +++ b/raphtory/src/core/entities/graph/edges.rs @@ -72,11 +72,9 @@ impl Layer { } pub(crate) fn additions(&self, eid: EID) -> Option>> { - self.additions.entry_opt(eid) + self.additions.entry_opt(eid).filter(|add| !add.is_empty()) } -} -impl Layer { pub fn lock(&self) -> LockedLayer { LockedLayer { edge_data: self.edge_data.read_lock(), @@ -85,16 +83,14 @@ impl Layer { } pub fn is_active(&self, eid: EID) -> bool { - self.additions.has_entry(eid) + self.additions(eid).is_some() } pub fn get_prop(&self, eid: EID, prop_id: usize) -> Option { - let data = self.edge_data.entry(eid); - if data.is_empty() { - return None; - } - let locked_t_prop = - data.map(|d| d.layer.temporal_property(prop_id).unwrap_or(&TProp::Empty)); + let data = self.edge_data.entry_opt(eid)?; + let locked_t_prop = Entry::map(data, |d| { + d.layer.temporal_property(prop_id).unwrap_or(&TProp::Empty) + }); Some(TPropRef::Locked(locked_t_prop)) } } @@ -107,10 +103,7 @@ pub struct LockedLayer { impl LockedLayer { pub fn is_active(&self, eid: EID) -> bool { - !self - .additions(eid) - .map(|add| add.is_empty()) - .unwrap_or(true) + self.additions(eid).is_some() } pub fn get_prop(&self, eid: EID, prop_id: usize) -> Option<&TProp> { @@ -119,7 +112,7 @@ impl LockedLayer { } pub fn additions(&self, eid: EID) -> Option<&TimeIndex> { - self.additions.get_opt(eid) + self.additions.get_opt(eid).filter(|add| !add.is_empty()) } pub fn edge_data(&self, eid: EID) -> Option<&EdgeData> { diff --git a/raphtory/src/core/entities/graph/tgraph.rs b/raphtory/src/core/entities/graph/tgraph.rs index 48a4a77ad..3703a1561 100644 --- a/raphtory/src/core/entities/graph/tgraph.rs +++ b/raphtory/src/core/entities/graph/tgraph.rs @@ -396,7 +396,7 @@ impl TemporalGraph { layer, |_| {}, Some(|edge_data: &mut EdgeData| { - edge_data.deletions.insert(t); + edge_data.deletions_mut().insert(t); Ok(()) }), )?; diff --git a/raphtory/src/core/storage/mod.rs b/raphtory/src/core/storage/mod.rs index b08f8524f..24e953c94 100644 --- a/raphtory/src/core/storage/mod.rs +++ b/raphtory/src/core/storage/mod.rs @@ -373,22 +373,18 @@ impl<'a, T> Entry<'a, T> { &self.guard[self.offset] } - pub fn is_empty(&self) -> bool { - self.guard.get(self.offset).is_none() - } - pub fn map_guard &U>( - self, + entry: Self, f: F, ) -> lock_api::MappedRwLockReadGuard<'a, parking_lot::RawRwLock, U> { - RwLockReadGuard::map(self.guard, |guard| { - let what = &guard[self.offset]; + RwLockReadGuard::map(entry.guard, |guard| { + let what = &guard[entry.offset]; f(what) }) } - pub fn map &U>(self, f: F) -> LockedView<'a, U> { - let mapped_guard = self.map_guard(f); + pub fn map &U>(entry: Self, f: F) -> LockedView<'a, U> { + let mapped_guard = Self::map_guard(entry, f); LockedView::LockMapped(mapped_guard) } } diff --git a/raphtory/src/core/storage/timeindex.rs b/raphtory/src/core/storage/timeindex.rs index 0799307f2..05c574ef8 100644 --- a/raphtory/src/core/storage/timeindex.rs +++ b/raphtory/src/core/storage/timeindex.rs @@ -560,6 +560,7 @@ impl<'a, T: AsTime> TimeIndexIntoOps for LockedView<'a, TimeIndex> { } } +#[derive(Debug)] pub struct LockedTimeIndexWindow<'a, T: AsTime> { timeindex: LockedView<'a, TimeIndex>, range: Range, diff --git a/raphtory/src/db/api/storage/edges/edge_storage_ops.rs b/raphtory/src/db/api/storage/edges/edge_storage_ops.rs index 0802a89b1..c7eed09e4 100644 --- a/raphtory/src/db/api/storage/edges/edge_storage_ops.rs +++ b/raphtory/src/db/api/storage/edges/edge_storage_ops.rs @@ -10,6 +10,7 @@ use crate::{ timeindex::{ LockedTimeIndexWindow, TimeIndex, TimeIndexIntoOps, TimeIndexOps, TimeIndexWindow, }, + Entry, }, }, db::api::{storage::tprop_storage_ops::TPropRef, view::IntoDynBoxed}, @@ -26,6 +27,7 @@ use raphtory_api::core::{entities::EID, storage::timeindex::TimeIndexEntry}; use rayon::prelude::*; use std::ops::Range; +#[derive(Debug)] pub enum TimeIndexRef<'a> { Ref(&'a TimeIndex), Locked(LockedView<'a, TimeIndex>), @@ -306,8 +308,14 @@ impl<'a> MemEdge<'a> { pub fn has_layer_inner(self, layer_id: usize) -> bool { match self.layers { - MemLayers::Unlocked(layers) => layers[layer_id].is_active(self.eid()), - MemLayers::Locked(layers) => layers[layer_id].is_active(self.eid()), + MemLayers::Unlocked(layers) => { + layers[layer_id].is_active(self.eid()) + || layers[layer_id].edge_data(self.eid()).is_some() + } + MemLayers::Locked(layers) => { + layers[layer_id].is_active(self.eid()) + || layers[layer_id].edge_data(self.eid()).is_some() + } } } @@ -328,7 +336,7 @@ impl<'a> MemEdge<'a> { match self.layers { MemLayers::Unlocked(layers) => layers[layer_id] .additions(self.eid()) - .map(|entry| TimeIndexRef::Locked(entry.map(|t| t))) + .map(|entry| TimeIndexRef::Locked(Entry::map(entry, |t| t))) .unwrap_or(TimeIndexRef::Ref(&TimeIndex::Empty)), MemLayers::Locked(layers) => layers[layer_id] .additions(self.eid()) @@ -341,12 +349,12 @@ impl<'a> MemEdge<'a> { match self.layers { MemLayers::Unlocked(layers) => layers[layer_id] .edge_data(self.eid()) - .map(|ed| ed.map(|ed| &ed.deletions)) + .map(|ed| Entry::map(ed, |ed| ed.deletions())) .map(|dels| TimeIndexRef::Locked(dels)) .unwrap_or(TimeIndexRef::Ref(&TimeIndex::Empty)), MemLayers::Locked(layers) => layers[layer_id] .edge_data(self.eid()) - .map(|ed| TimeIndexRef::Ref(&ed.deletions)) + .map(|ed| TimeIndexRef::Ref(ed.deletions())) .unwrap_or(TimeIndexRef::Ref(&TimeIndex::Empty)), } } diff --git a/raphtory/src/db/api/storage/storage_ops.rs b/raphtory/src/db/api/storage/storage_ops.rs index 50ccdaf35..0b2479d77 100644 --- a/raphtory/src/db/api/storage/storage_ops.rs +++ b/raphtory/src/db/api/storage/storage_ops.rs @@ -226,8 +226,6 @@ impl GraphStorage { ) -> impl ParallelIterator + 'graph { view.node_list().into_par_iter().filter(move |&vid| { let node = self.node(vid); - let n = node.name(); - let i = node.node_type_id(); let r = type_filter .as_ref() .map_or(true, |type_filter| type_filter[node.node_type_id()]);