Skip to content

Commit

Permalink
fix the additions and edge explosions
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmurariu committed Jun 27, 2024
1 parent d47a2bc commit e3b30b5
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 33 deletions.
12 changes: 11 additions & 1 deletion raphtory/src/core/entities/edges/edge_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ pub struct EdgeStore {
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
pub struct EdgeData {
pub(crate) layer: EdgeLayer,
pub(crate) deletions: TimeIndex<TimeIndexEntry>,
deletions: TimeIndex<TimeIndexEntry>,
}

impl EdgeData {
pub fn deletions(&self) -> &TimeIndex<TimeIndexEntry> {
&self.deletions
}

pub fn deletions_mut(&mut self) -> &mut TimeIndex<TimeIndexEntry> {
&mut self.deletions
}
}

pub trait EdgeDataLike<'a> {
Expand Down
23 changes: 8 additions & 15 deletions raphtory/src/core/entities/graph/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ impl Layer {
}

pub(crate) fn additions(&self, eid: EID) -> Option<Entry<'_, TimeIndex<TimeIndexEntry>>> {
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(),
Expand All @@ -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<TPropRef> {
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))
}
}
Expand All @@ -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> {
Expand All @@ -119,7 +112,7 @@ impl LockedLayer {
}

pub fn additions(&self, eid: EID) -> Option<&TimeIndex<TimeIndexEntry>> {
self.additions.get_opt(eid)
self.additions.get_opt(eid).filter(|add| !add.is_empty())
}

pub fn edge_data(&self, eid: EID) -> Option<&EdgeData> {
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/core/entities/graph/tgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl TemporalGraph {
layer,
|_| {},
Some(|edge_data: &mut EdgeData| {
edge_data.deletions.insert(t);
edge_data.deletions_mut().insert(t);
Ok(())
}),
)?;
Expand Down
14 changes: 5 additions & 9 deletions raphtory/src/core/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, F: Fn(&T) -> &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, F: Fn(&T) -> &U>(self, f: F) -> LockedView<'a, U> {
let mapped_guard = self.map_guard(f);
pub fn map<U, F: Fn(&T) -> &U>(entry: Self, f: F) -> LockedView<'a, U> {
let mapped_guard = Self::map_guard(entry, f);
LockedView::LockMapped(mapped_guard)
}
}
Expand Down
1 change: 1 addition & 0 deletions raphtory/src/core/storage/timeindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ impl<'a, T: AsTime> TimeIndexIntoOps for LockedView<'a, TimeIndex<T>> {
}
}

#[derive(Debug)]
pub struct LockedTimeIndexWindow<'a, T: AsTime> {
timeindex: LockedView<'a, TimeIndex<T>>,
range: Range<T>,
Expand Down
18 changes: 13 additions & 5 deletions raphtory/src/db/api/storage/edges/edge_storage_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
timeindex::{
LockedTimeIndexWindow, TimeIndex, TimeIndexIntoOps, TimeIndexOps, TimeIndexWindow,
},
Entry,
},
},
db::api::{storage::tprop_storage_ops::TPropRef, view::IntoDynBoxed},
Expand All @@ -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<TimeIndexEntry>),
Locked(LockedView<'a, TimeIndex<TimeIndexEntry>>),
Expand Down Expand Up @@ -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()
}
}
}

Expand All @@ -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())
Expand All @@ -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)),
}
}
Expand Down
2 changes: 0 additions & 2 deletions raphtory/src/db/api/storage/storage_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ impl GraphStorage {
) -> impl ParallelIterator<Item = VID> + '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()]);
Expand Down

0 comments on commit e3b30b5

Please sign in to comment.