From c82cb5111a970edcc3af74a7b28fd3a5f50a4fdb Mon Sep 17 00:00:00 2001 From: Fabian Murariu Date: Mon, 16 Dec 2024 18:17:14 +0000 Subject: [PATCH] remove some useless things --- raphtory/src/core/entities/graph/timer.rs | 17 ++-- .../src/core/entities/properties/tcell.rs | 29 +----- .../src/core/entities/properties/tprop.rs | 23 ----- raphtory/src/core/mod.rs | 6 -- raphtory/src/core/storage/lazy_vec.rs | 43 --------- raphtory/src/core/storage/mod.rs | 16 +--- raphtory/src/core/storage/node_entry.rs | 8 +- raphtory/src/core/storage/timeindex.rs | 31 ++----- raphtory/src/db/api/properties/internal.rs | 1 - .../storage/graph/storage_ops/additions.rs | 6 +- .../graph/storage_ops/time_semantics.rs | 5 - .../db/api/storage/graph/tprop_storage_ops.rs | 4 - raphtory/src/db/api/view/graph.rs | 8 +- .../src/db/api/view/node_property_filter.rs | 93 ------------------- raphtory/src/db/graph/node.rs | 4 - raphtory/src/serialise/serialise.rs | 7 +- 16 files changed, 34 insertions(+), 267 deletions(-) diff --git a/raphtory/src/core/entities/graph/timer.rs b/raphtory/src/core/entities/graph/timer.rs index df5892094..27dde4a84 100644 --- a/raphtory/src/core/entities/graph/timer.rs +++ b/raphtory/src/core/entities/graph/timer.rs @@ -19,7 +19,10 @@ pub(crate) trait TimeCounterTrait { } } } - fn get(&self) -> i64; + #[inline(always)] + fn get(&self) -> i64 { + self.counter().load(Ordering::Relaxed) + } } #[derive(Serialize, Deserialize, Debug)] @@ -40,14 +43,10 @@ impl TimeCounterTrait for MinCounter { new_value < current_value } + #[inline(always)] fn counter(&self) -> &AtomicI64 { &self.counter } - - #[inline] - fn get(&self) -> i64 { - self.counter.load(Ordering::Relaxed) - } } #[derive(Serialize, Deserialize, Debug)] @@ -67,14 +66,10 @@ impl TimeCounterTrait for MaxCounter { fn cmp(a: i64, b: i64) -> bool { a > b } + #[inline(always)] fn counter(&self) -> &AtomicI64 { &self.counter } - - #[inline] - fn get(&self) -> i64 { - self.counter.load(Ordering::Relaxed) - } } #[cfg(test)] diff --git a/raphtory/src/core/entities/properties/tcell.rs b/raphtory/src/core/entities/properties/tcell.rs index aa94fa3c4..189c399c8 100644 --- a/raphtory/src/core/entities/properties/tcell.rs +++ b/raphtory/src/core/entities/properties/tcell.rs @@ -80,12 +80,7 @@ impl TCell { } pub fn iter_t(&self) -> BoxedLIter<(i64, &A)> { - match self { - TCell::Empty => Box::new(std::iter::empty()), - TCell::TCell1(t, value) => Box::new(std::iter::once((t.t(), value))), - TCell::TCellCap(svm) => Box::new(svm.iter().map(|(ti, v)| (ti.t(), v))), - TCell::TCellN(btm) => Box::new(btm.iter().map(|(ti, v)| (ti.t(), v))), - } + Box::new(self.iter().map(|(t, a)| (t.t(), a))) } pub fn iter_window( @@ -107,24 +102,10 @@ impl TCell { } pub fn iter_window_t(&self, r: Range) -> Box + Send + '_> { - match self { - TCell::Empty => Box::new(std::iter::empty()), - TCell::TCell1(t, value) => { - if r.contains(&t.t()) { - Box::new(std::iter::once((t.t(), value))) - } else { - Box::new(std::iter::empty()) - } - } - TCell::TCellCap(svm) => Box::new( - svm.range(TimeIndexEntry::range(r)) - .map(|(ti, v)| (ti.t(), v)), - ), - TCell::TCellN(btm) => Box::new( - btm.range(TimeIndexEntry::range(r)) - .map(|(ti, v)| (ti.t(), v)), - ), - } + Box::new( + self.iter_window(TimeIndexEntry::range(r)) + .map(|(t, a)| (t.t(), a)), + ) } pub fn last_before(&self, t: TimeIndexEntry) -> Option<(TimeIndexEntry, &A)> { diff --git a/raphtory/src/core/entities/properties/tprop.rs b/raphtory/src/core/entities/properties/tprop.rs index 52a0b475d..02a841ebf 100644 --- a/raphtory/src/core/entities/properties/tprop.rs +++ b/raphtory/src/core/entities/properties/tprop.rs @@ -420,29 +420,6 @@ impl<'a> TPropOps<'a> for &'a TProp { TProp::Map(cell) => cell.at(ti).map(|v| Prop::Map(v.clone())), } } - - // fn len(self) -> usize { - // match self { - // TProp::Empty => 0, - // TProp::Str(v) => v.len(), - // TProp::U8(v) => v.len(), - // TProp::U16(v) => v.len(), - // TProp::I32(v) => v.len(), - // TProp::I64(v) => v.len(), - // TProp::U32(v) => v.len(), - // TProp::U64(v) => v.len(), - // TProp::F32(v) => v.len(), - // TProp::F64(v) => v.len(), - // TProp::Bool(v) => v.len(), - // TProp::DTime(v) => v.len(), - // TProp::NDTime(v) => v.len(), - // TProp::Graph(v) => v.len(), - // TProp::PersistentGraph(v) => v.len(), - // TProp::Document(v) => v.len(), - // TProp::List(v) => v.len(), - // TProp::Map(v) => v.len(), - // } - // } } #[cfg(test)] diff --git a/raphtory/src/core/mod.rs b/raphtory/src/core/mod.rs index d20c0e70a..90463e5e5 100644 --- a/raphtory/src/core/mod.rs +++ b/raphtory/src/core/mod.rs @@ -721,12 +721,6 @@ impl From> for Prop { } } -impl> FromIterator

for Prop { - fn from_iter>(iter: I) -> Self { - Prop::List(Arc::new(iter.into_iter().map(|v| v.into()).collect())) - } -} - impl From<&Prop> for Prop { fn from(value: &Prop) -> Self { value.clone() diff --git a/raphtory/src/core/storage/lazy_vec.rs b/raphtory/src/core/storage/lazy_vec.rs index 33d54bae7..cb39cd82a 100644 --- a/raphtory/src/core/storage/lazy_vec.rs +++ b/raphtory/src/core/storage/lazy_vec.rs @@ -67,15 +67,6 @@ impl MaskedCol { self.mask.len() } - pub fn iter_mut(&mut self) -> impl Iterator> { - let ts_len = self.ts.len(); - self.ts - .iter_mut() - .zip(&self.mask[0..ts_len]) - .map(|(t, &is_some)| is_some.then(|| t)) - .chain(self.mask[ts_len..].iter().map(|_| None)) - } - pub fn iter(&self) -> impl Iterator> { let ts_len = self.ts.len(); self.ts @@ -84,19 +75,6 @@ impl MaskedCol { .map(|(t, &is_some)| is_some.then(|| t)) .chain(self.mask[ts_len..].iter().map(|_| None)) } - - pub fn into_iter(self) -> impl Iterator> { - let empty_tail = self.mask.len() - self.ts.len(); - self.ts - .into_iter() - .zip(self.mask.into_iter()) - .map(|(t, is_some)| is_some.then(|| t)) - .chain(std::iter::from_fn(|| None).take(empty_tail)) - } - - pub fn filled_len(&self) -> usize { - self.mask.iter().filter(|v| **v).count() - } } #[derive(Default, Debug, PartialEq, Serialize, Deserialize)] @@ -416,19 +394,6 @@ mod lazy_vec_tests { assert_eq!(vec.len(), 3); } - // #[test] - // fn lazy_vec_is_opt_vec_insert() { - // proptest!(|( - // v in Vec::>::arbitrary(), - // )| { - // let mut lazy_vec = LazyVec::::Empty; - // for (i, value) in v.iter().enumerate() { - // lazy_vec.insert(i, *value); - // } - // check_lazy_vec(&lazy_vec, v); - // }); - // } - #[test] fn lazy_vec_is_opt_vec_push() { proptest!(|( @@ -442,14 +407,6 @@ mod lazy_vec_tests { }); } - // #[test] - // fn none_1_lazy_vec() { - // let mut vec = LazyVec::::Empty; - // vec.insert(0, None); - - // assert_eq!(vec.len(), 1); - // } - #[test] fn normal_operation() { let mut vec = LazyVec::::Empty; diff --git a/raphtory/src/core/storage/mod.rs b/raphtory/src/core/storage/mod.rs index 52713514a..f51cbf575 100644 --- a/raphtory/src/core/storage/mod.rs +++ b/raphtory/src/core/storage/mod.rs @@ -441,7 +441,7 @@ where self.locks.par_iter().flat_map(|v| v.par_iter()) } - #[allow(unused)] + #[cfg(test)] pub(crate) fn into_iter(self) -> impl Iterator { self.locks.into_iter().flat_map(|data| { (0..data.as_ref().len()).map(move |offset| ArcEntry { @@ -450,18 +450,6 @@ where }) }) } - - #[allow(unused)] - pub(crate) fn into_par_iter(self) -> impl ParallelIterator { - self.locks.into_par_iter().flat_map(|data| { - (0..data.as_ref().len()) - .into_par_iter() - .map(move |offset| ArcEntry { - guard: data.clone(), - i: offset, - }) - }) - } } impl NodeStorage { @@ -862,7 +850,7 @@ impl<'a, NS: DerefMut + 'a> EntryMut<'a, &'a mut NS> { &self.guard[self.i] } - pub fn get_mut(&mut self) -> &mut NodeStore { + pub fn node_store_mut(&mut self) -> &mut NodeStore { &mut self.guard[self.i] } diff --git a/raphtory/src/core/storage/node_entry.rs b/raphtory/src/core/storage/node_entry.rs index bfabdf100..708c79133 100644 --- a/raphtory/src/core/storage/node_entry.rs +++ b/raphtory/src/core/storage/node_entry.rs @@ -2,7 +2,7 @@ use std::{borrow::Cow, ops::Range}; use raphtory_api::core::{ entities::{edges::edge_ref::EdgeRef, GidRef, VID}, - storage::timeindex::{TimeIndexEntry, TimeIndexOps}, + storage::timeindex::TimeIndexEntry, Direction, }; @@ -71,9 +71,9 @@ impl<'a> NodeEntry<'a> { w: Range, ) -> impl Iterator)> + Send + Sync { let tcell = &self.node.timestamps().props_ts; - tcell.range(w).iter_values().filter_map(move |(t, row)| { - let row = MemRow::new(self.t_props_log, row); - Some((t, Row::Mem(row))) + tcell.iter_window(w).filter_map(move |(t, row)| { + let row = MemRow::new(self.t_props_log, *row); + Some((*t, Row::Mem(row))) }) } } diff --git a/raphtory/src/core/storage/timeindex.rs b/raphtory/src/core/storage/timeindex.rs index cf549c17b..b9ba0568f 100644 --- a/raphtory/src/core/storage/timeindex.rs +++ b/raphtory/src/core/storage/timeindex.rs @@ -1,5 +1,5 @@ use super::locked_view::LockedView; -use crate::core::entities::{properties::tcell::TCell, LayerIds}; +use crate::core::entities::LayerIds; use itertools::Itertools; use rayon::prelude::*; use serde::{Deserialize, Serialize}; @@ -134,10 +134,6 @@ impl TimeIndexLike for TimeIndex { Box::new(self.range_iter(w)) } - fn first_range(&self, w: Range) -> Option { - self.range_iter(w).next() - } - fn last_range(&self, w: Range) -> Option { self.range_iter(w).next_back() } @@ -150,18 +146,6 @@ pub enum TimeIndexWindow<'a, T: AsTime, TI> { All(&'a TI), } -impl<'a, A: Copy + Send + Sync> TimeIndexWindow<'a, TimeIndexEntry, TCell> { - pub fn iter_values(self) -> Box + Send + Sync + 'a> { - match self { - TimeIndexWindow::Empty => Box::new(iter::empty()), - TimeIndexWindow::TimeIndexRange { timeindex, range } => { - Box::new(timeindex.iter_window(range.clone()).map(|(t, v)| (*t, *v))) - } - TimeIndexWindow::All(timeindex) => Box::new(timeindex.iter().map(|(t, v)| (*t, *v))), - } - } -} - impl<'a, T: AsTime, TI: TimeIndexLike> TimeIndexWindow<'a, T, TI> { pub fn len(&self) -> usize { match self { @@ -199,8 +183,9 @@ impl<'a, T: AsTime, TI: TimeIndexLike> TimeIndexIntoOps if ts.len() == 0 { TimeIndexWindow::Empty } else { - if let Some(min_val) = ts.first() { - if let Some(max_val) = ts.last() { + ts.first() + .zip(ts.last()) + .map(|(min_val, max_val)| { if min_val >= w.start && max_val < w.end { TimeIndexWindow::All(ts) } else { @@ -209,12 +194,8 @@ impl<'a, T: AsTime, TI: TimeIndexLike> TimeIndexIntoOps range: w, } } - } else { - TimeIndexWindow::Empty - } - } else { - TimeIndexWindow::Empty - } + }) + .unwrap_or(TimeIndexWindow::Empty) } } } diff --git a/raphtory/src/db/api/properties/internal.rs b/raphtory/src/db/api/properties/internal.rs index f9edbcf63..f516b72c7 100644 --- a/raphtory/src/db/api/properties/internal.rs +++ b/raphtory/src/db/api/properties/internal.rs @@ -42,7 +42,6 @@ pub trait TemporalPropertyViewOps { pub trait TemporalPropertiesRowView { fn rows(&self) -> BoxedLIter<(TimeIndexEntry, Vec<(usize, Prop)>)>; - fn edge_ts(&self) -> BoxedLIter; } #[enum_dispatch] diff --git a/raphtory/src/db/api/storage/graph/storage_ops/additions.rs b/raphtory/src/db/api/storage/graph/storage_ops/additions.rs index 60664aa07..4accccc17 100644 --- a/raphtory/src/db/api/storage/graph/storage_ops/additions.rs +++ b/raphtory/src/db/api/storage/graph/storage_ops/additions.rs @@ -83,8 +83,8 @@ impl InternalAdditionOps for TemporalGraph { } let vid = self.resolve_node(id)?; let mut entry = self.storage.get_node_mut(vid.inner()); - let mut a = entry.to_mut(); - let node_store = a.get_mut(); + let mut entry_ref = entry.to_mut(); + let node_store = entry_ref.node_store_mut(); if node_store.node_type == 0 { let node_type_id = self.node_meta.get_or_create_node_type_id(node_type); node_store.update_node_type(node_type_id.inner()); @@ -152,7 +152,7 @@ impl InternalAdditionOps for TemporalGraph { (*prop_id, prop) }))?; - a.get_mut().update_t_prop_time(t, prop_i); + a.node_store_mut().update_t_prop_time(t, prop_i); Ok(()) } diff --git a/raphtory/src/db/api/storage/graph/storage_ops/time_semantics.rs b/raphtory/src/db/api/storage/graph/storage_ops/time_semantics.rs index 8476bff1e..753862885 100644 --- a/raphtory/src/db/api/storage/graph/storage_ops/time_semantics.rs +++ b/raphtory/src/db/api/storage/graph/storage_ops/time_semantics.rs @@ -513,11 +513,6 @@ impl TimeSemantics for GraphStorage { res } - // fn has_temporal_edge_prop(&self, e: EdgeRef, prop_id: usize, layer_ids: &LayerIds) -> bool { - // let entry = self.core_edge(e.pid()); - // (&entry).has_temporal_prop(&layer_ids.constrain_from_edge(e), prop_id) - // } - fn temporal_edge_prop_hist<'a>( &'a self, e: EdgeRef, diff --git a/raphtory/src/db/api/storage/graph/tprop_storage_ops.rs b/raphtory/src/db/api/storage/graph/tprop_storage_ops.rs index 72d0605d8..607dd7ed5 100644 --- a/raphtory/src/db/api/storage/graph/tprop_storage_ops.rs +++ b/raphtory/src/db/api/storage/graph/tprop_storage_ops.rs @@ -96,8 +96,4 @@ impl<'a> TPropOps<'a> for TPropRef<'a> { fn at(self, ti: &TimeIndexEntry) -> Option { for_all!(self, tprop => tprop.at(ti)) } - - // fn len(self) -> usize { - // for_all!(self, tprop => tprop.len()) - // } } diff --git a/raphtory/src/db/api/view/graph.rs b/raphtory/src/db/api/view/graph.rs index e7636bb1c..f7107b505 100644 --- a/raphtory/src/db/api/view/graph.rs +++ b/raphtory/src/db/api/view/graph.rs @@ -235,26 +235,26 @@ impl<'graph, G: BoxableGraphView + Sized + Clone + 'graph> GraphViewOps<'graph> .node_type_meta() .get_or_create_id(&node_type) .inner(); - new_node.get_mut().node_type = new_type_id; + new_node.node_store_mut().node_type = new_type_id; } g.logical_to_physical.set(gid.as_ref(), new_id)?; if let Some(earliest) = node.earliest_time() { // explicitly add node earliest_time to handle PersistentGraph new_node - .get_mut() + .node_store_mut() .update_t_prop_time(TimeIndexEntry::start(earliest), None) } for (t, rows) in node.rows() { let prop_offset = new_node.t_props_log_mut().push(rows)?; - new_node.get_mut().update_t_prop_time(t, prop_offset); + new_node.node_store_mut().update_t_prop_time(t, prop_offset); } for c_prop_id in node.const_prop_ids() { if let Some(prop_value) = node.get_const_prop(c_prop_id) { new_node - .get_mut() + .node_store_mut() .add_constant_prop(c_prop_id, prop_value)?; } } diff --git a/raphtory/src/db/api/view/node_property_filter.rs b/raphtory/src/db/api/view/node_property_filter.rs index bd0d44584..52aad1d46 100644 --- a/raphtory/src/db/api/view/node_property_filter.rs +++ b/raphtory/src/db/api/view/node_property_filter.rs @@ -352,97 +352,4 @@ mod test { // assert_graph_equal(&filtered, &expected_g); }) } - - #[test] - fn test_filter_is_none_sample() { - let nodes = vec![ - (0u64, None, None), - (1, None, None), - (2, None, None), - (3, None, None), - (4, None, None), - (5, None, None), - (6, Some("".to_string()), None), - (7, None, None), - (8, None, None), - (9, None, None), - (10, None, None), - (11, None, None), - (12, None, None), - (13, None, None), - (14, None, None), - (15, None, None), - (16, None, None), - (17, None, None), - (18, None, None), - (19, None, None), - (20, None, None), - (21, None, None), - (22, None, None), - (23, None, Some(-1006640885922i64)), - (24, None, Some(3140823659770432416)), - (25, None, Some(-8241928021672356322)), - (26, None, None), - (27, None, Some(1531674380875899820)), - (28, None, None), - (29, None, None), - (30, None, None), - (31, None, Some(-46139717112632079)), - (32, None, None), - (33, Some("a".to_string()), Some(1268855120093795622)), - (34, None, None), - (35, Some("".to_string()), None), - (36, None, Some(-7161369594877871170)), - (37, None, Some(802040896379373150)), - (38, None, Some(-8575189323174740844)), - (39, Some("b".to_string()), None), - (40, None, None), - (41, None, None), - (42, None, Some(-9213792616588373967)), - (43, Some("c".to_string()), Some(-8033735226120800391)), - (44, Some("d".to_string()), Some(-4373305175473905212)), - (45, None, Some(4466699769621037019)), - (46, None, None), - (47, Some("e".to_string()), Some(-7288882491415087470)), - (48, Some("f".to_string()), Some(-3571741428046533850)), - ]; - - let edges = vec![(6u64, 2u64, 0i64, "".to_string(), 0i64)]; - - let g = build_graph_from_edge_list(&edges); - add_node_props(&g, &nodes); - - let node6 = g.node(6).unwrap(); - let prop = node6.properties().get("int_prop"); - assert_eq!(prop, None); - - let filtered = g.filter_nodes(PropertyFilter::is_none("int_prop")).unwrap(); - - let expected_g = node_filtered_graph(&edges, &nodes, |_, int_v| int_v.is_none()); - - let mut nodes = filtered.nodes().id().collect_vec(); - let mut expected_nodes = expected_g.nodes().id().collect_vec(); - - nodes.sort(); - expected_nodes.sort(); - assert_eq!(nodes, expected_nodes); - - let edges = filtered.edges(); - let expected_edges = expected_g.edges(); - - println!( - "{:?}, {:?}", - edges.id().collect_vec(), - expected_edges.id().collect_vec() - ); - - assert_edges_equal(&expected_edges, &expected_edges); - let filtered_p = g - .persistent_graph() - .filter_nodes(PropertyFilter::is_none("int_prop")) - .unwrap(); - assert_edges_equal(&filtered_p.edges(), &expected_g.persistent_graph().edges()); - // FIXME: history filtering not working properly - // assert_graph_equal(&filtered, &expected_g); - } } diff --git a/raphtory/src/db/graph/node.rs b/raphtory/src/db/graph/node.rs index ef74b06aa..c9cf2efc4 100644 --- a/raphtory/src/db/graph/node.rs +++ b/raphtory/src/db/graph/node.rs @@ -277,10 +277,6 @@ impl TemporalPropertiesRowView for NodeView fn rows(&self) -> BoxedLIter<(TimeIndexEntry, Vec<(usize, Prop)>)> { self.graph.node_history_rows(self.node, None) } - - fn edge_ts(&self) -> BoxedLIter { - self.graph.node_edge_history(self.node, None) - } } impl ConstPropertiesOps for NodeView { diff --git a/raphtory/src/serialise/serialise.rs b/raphtory/src/serialise/serialise.rs index b13611072..1254af55e 100644 --- a/raphtory/src/serialise/serialise.rs +++ b/raphtory/src/serialise/serialise.rs @@ -396,7 +396,7 @@ impl StableDecode for TemporalGraph { }; if let Some(mut node_store) = shard.set(vid, gid) { storage.logical_to_physical.set(gid, vid)?; - node_store.get_mut().node_type = node.type_id as usize; + node_store.node_store_mut().node_type = node.type_id as usize; } } let edges = storage.storage.edges.read_lock(); @@ -446,10 +446,11 @@ impl StableDecode for TemporalGraph { } if props.is_empty() { - node.get_mut().update_t_prop_time(update.time(), None); + node.node_store_mut() + .update_t_prop_time(update.time(), None); } else { let prop_offset = node.t_props_log_mut().push(props)?; - node.get_mut() + node.node_store_mut() .update_t_prop_time(update.time(), prop_offset); }