Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions db4-storage/src/generic_t_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ impl<'a, Ref: WithTProps<'a>> TPropOps<'a> for GenericTProps<'a, Ref> {
.max_by_key(|(t, _)| *t)
}

fn last(&self) -> Option<(EventTime, Prop)> {
self.tprops(self.prop_id)
.filter_map(|t_props| t_props.last())
.max_by_key(|(t, _)| *t)
}

fn iter_inner(
self,
w: Option<Range<EventTime>>,
Expand Down
2 changes: 2 additions & 0 deletions raphtory-api/src/core/entities/properties/tprop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub trait TPropOps<'a>: Clone + Send + Sync + Sized + 'a {
self.clone().iter_inner_rev(Some(EventTime::MIN..t)).next()
}

fn last(&self) -> Option<(EventTime, Prop)>;

fn iter_inner(
self,
range: Option<Range<EventTime>>,
Expand Down
19 changes: 17 additions & 2 deletions raphtory-core/src/entities/properties/tcell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,23 @@ impl<A: Sync + Send> TCell<A> {
match self {
TCell::Empty => None,
TCell::TCell1(t2, v) => (*t2 < t).then_some((*t2, v)),
TCell::TCellCap(map) => map.range(EventTime::MIN..t).last().map(|(ti, v)| (*ti, v)),
TCell::TCellN(map) => map.range(EventTime::MIN..t).last().map(|(ti, v)| (*ti, v)),
TCell::TCellCap(map) => map
.range(EventTime::MIN..t)
.next_back()
.map(|(ti, v)| (*ti, v)),
TCell::TCellN(map) => map
.range(EventTime::MIN..t)
.next_back()
.map(|(ti, v)| (*ti, v)),
}
}

pub fn last_value(&self) -> Option<(EventTime, &A)> {
match self {
TCell::Empty => None,
TCell::TCell1(t, v) => Some((*t, v)),
TCell::TCellCap(map) => map.last_key_value().map(|(t, v)| (*t, v)),
TCell::TCellN(map) => map.last_key_value().map(|(t, v)| (*t, v)),
}
}

Expand Down
33 changes: 32 additions & 1 deletion raphtory-core/src/entities/properties/tprop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use raphtory_api::core::{
prop::{Prop, PropArray, PropType},
tprop::TPropOps,
},
storage::arc_str::ArcStr,
storage::{arc_str::ArcStr, timeindex::TimeIndexOps},
};
use rustc_hash::FxHashMap;
use serde::Serialize;
Expand Down Expand Up @@ -119,6 +119,15 @@ impl<'a> TPropCell<'a> {
}

impl<'a> TPropOps<'a> for TPropCell<'a> {
fn last(&self) -> Option<(EventTime, Prop)> {
let i = self.t_cell?.last()?;
None
}

fn last_before(&self, t: EventTime) -> Option<(EventTime, Prop)> {
todo!()
}

fn iter_inner(
self,
range: Option<Range<EventTime>>,
Expand Down Expand Up @@ -386,6 +395,28 @@ impl TProp {
}

impl<'a> TPropOps<'a> for &'a TProp {
fn last(&self) -> Option<(EventTime, Prop)> {
match self {
TProp::Empty => None,
TProp::Str(cell) => cell.last_value().map(|(t, v)| (t, Prop::Str(v.clone()))),
TProp::U8(cell) => cell.last_value().map(|(t, v)| (t, Prop::U8(v.clone()))),
TProp::U16(cell) => cell.last_value().map(|(t, v)| (t, Prop::U16(v.clone()))),
TProp::I32(cell) => cell.last_value().map(|(t, v)| (t, Prop::I32(v.clone()))),
TProp::I64(cell) => cell.last_value().map(|(t, v)| (t, Prop::I64(v.clone()))),
TProp::U32(cell) => cell.last_value().map(|(t, v)| (t, Prop::U32(v.clone()))),
TProp::U64(cell) => cell.last_value().map(|(t, v)| (t, Prop::U64(v.clone()))),
TProp::F32(cell) => cell.last_value().map(|(t, v)| (t, Prop::F32(v.clone()))),
TProp::F64(cell) => cell.last_value().map(|(t, v)| (t, Prop::F64(v.clone()))),
TProp::Bool(cell) => cell.last_value().map(|(t, v)| (t, Prop::Bool(v.clone()))),
TProp::DTime(cell) => cell.last_value().map(|(t, v)| (t, Prop::DTime(v.clone()))),
TProp::List(cell) => cell.last_value().map(|(t, v)| (t, Prop::List(v.clone()))),
TProp::NDTime(cell) => cell.last_value().map(|(t, v)| (t, Prop::NDTime(v.clone()))),
TProp::Map(cell) => cell.last_value().map(|(t, v)| (t, Prop::Map(v.clone()))),
TProp::Decimal(cell) => cell
.last_value()
.map(|(t, v)| (t, Prop::Decimal(v.clone()))),
}
}
fn last_before(&self, t: EventTime) -> Option<(EventTime, Prop)> {
match self {
TProp::Empty => None,
Expand Down
4 changes: 4 additions & 0 deletions raphtory-storage/src/graph/variants/storage_variants2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl<'a, Mem: TPropOps<'a> + 'a> TPropOps<'a> for SelfType!(Mem, Disk) {
for_all!(self, props => props.last_before(t))
}

fn last(&self) -> Option<(EventTime, Prop)> {
for_all!(self, props => props.last())
}

fn iter_inner(
self,
range: Option<Range<EventTime>>,
Expand Down
4 changes: 4 additions & 0 deletions raphtory-storage/src/graph/variants/storage_variants3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ impl<'a, Mem: TPropOps<'a> + 'a, Unlocked: TPropOps<'a> + 'a> TPropOps<'a>
for_all!(self, props => props.last_before(t))
}

fn last(&self) -> Option<(EventTime, Prop)> {
for_all!(self, props => props.last())
}

fn iter_inner(
self,
range: Option<Range<EventTime>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,16 @@ impl NodeTimeSemanticsOps for BaseTimeSemantics {
) -> Option<(EventTime, Prop)> {
for_all!(self, semantics => semantics.node_tprop_last_at_window(node, view, prop_id, t, w))
}

#[inline]
fn node_tprop_last<'graph, G: GraphView + 'graph>(
&self,
node: NodeStorageRef<'graph>,
view: G,
prop_id: usize,
) -> Option<(EventTime, Prop)> {
for_all!(self, semantics => semantics.node_tprop_last(node, view, prop_id))
}
}

impl EdgeTimeSemanticsOps for BaseTimeSemantics {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ impl NodeTimeSemanticsOps for EventSemantics {
.kmerge_by(|(a, _), (b, _)| a >= b)
}

fn node_tprop_last<'graph, G: GraphView + 'graph>(
&self,
node: NodeStorageRef<'graph>,
view: G,
prop_id: usize,
) -> Option<(EventTime, Prop)> {
node.tprop_iter_layers(view.layer_ids(), prop_id)
.filter_map(|prop| prop.last())
.max_by_key(|(t, _)| *t)
}

fn node_tprop_last_at<'graph, G: GraphView + 'graph>(
&self,
node: NodeStorageRef<'graph>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ pub struct FilteredEdgeTProp<G, P> {
impl<'graph, G: GraphViewOps<'graph>, P: TPropOps<'graph>> TPropOps<'graph>
for FilteredEdgeTProp<G, P>
{
fn last(&self) -> Option<(EventTime, Prop)> {
if self.view.internal_exploded_edge_filtered() {
self.clone().iter_rev().next()
} else {
self.props.last()
}
}
fn iter_inner(
self,
range: Option<Range<EventTime>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,17 @@ impl NodeTimeSemanticsOps for PersistentSemantics {
window_iter_rev.chain(first)
}

fn node_tprop_last<'graph, G: GraphView + 'graph>(
&self,
node: NodeStorageRef<'graph>,
view: G,
prop_id: usize,
) -> Option<(EventTime, Prop)> {
node.tprop_iter_layers(view.layer_ids(), prop_id)
.filter_map(|prop| prop.last())
.max_by_key(|(t, _)| *t)
}

fn node_tprop_last_at<'graph, G: GraphViewOps<'graph>>(
&self,
node: NodeStorageRef<'graph>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ impl NodeTimeSemanticsOps for TimeSemantics {
) -> impl Iterator<Item = (EventTime, ELID)> + Send + Sync + 'graph {
for_all_iter!(self, semantics => semantics.node_edge_history_rev_window(node, view, layer_ids, w))
}

fn node_tprop_last<'graph, G: GraphView + 'graph>(
&self,
node: NodeStorageRef<'graph>,
view: G,
prop_id: usize,
) -> Option<(EventTime, Prop)> {
for_all!(self, semantics => semantics.node_tprop_last(node, view, prop_id))
}
}

impl EdgeTimeSemanticsOps for TimeSemantics {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ pub trait NodeTimeSemanticsOps {
w: Range<EventTime>,
) -> impl Iterator<Item = (EventTime, Prop)> + Send + Sync + 'graph;

fn node_tprop_last<'graph, G: GraphView + 'graph>(
&self,
node: NodeStorageRef<'graph>,
view: G,
prop_id: usize,
) -> Option<(EventTime, Prop)>;

fn node_tprop_last_at<'graph, G: GraphView + 'graph>(
&self,
node: NodeStorageRef<'graph>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ impl NodeTimeSemanticsOps for WindowTimeSemantics {
.node_tprop_iter_window_rev(node, view, prop_id, w)
}

fn node_tprop_last<'graph, G: GraphView + 'graph>(
&self,
node: NodeStorageRef<'graph>,
view: G,
prop_id: usize,
) -> Option<(EventTime, Prop)> {
self.semantics
.node_tprop_last_at(node, view, prop_id, self.window.end.previous())
}

#[inline]
fn node_tprop_last_at<'graph, G: GraphView + 'graph>(
&self,
Expand Down
8 changes: 3 additions & 5 deletions raphtory/src/db/graph/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,9 @@ impl<'graph, G: GraphViewOps<'graph>> InternalTemporalPropertyViewOps for NodeVi
fn temporal_value(&self, id: usize) -> Option<Prop> {
let semantics = self.graph.node_time_semantics();
let node = self.graph.core_node(self.node);
let res = semantics
.node_tprop_iter_rev(node.as_ref(), &self.graph, id)
.next()
.map(|(_, v)| v);
res
semantics
.node_tprop_last(node.as_ref(), &self.graph, id)
.map(|(_, v)| v)
}

fn temporal_iter(&self, id: usize) -> BoxedLIter<'_, (EventTime, Prop)> {
Expand Down
Loading