Skip to content

Commit

Permalink
fixex for Send and Sync iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmurariu committed Dec 13, 2024
1 parent 01d1dd6 commit a3e5126
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 25 deletions.
9 changes: 4 additions & 5 deletions raphtory-api/src/core/storage/timeindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ pub trait AsTime: fmt::Debug + Copy + Ord + Eq + Send + Sync + 'static {
}

pub trait TimeIndexLike: TimeIndexOps {
fn range_iter(
&self,
w: Range<Self::IndexType>,
) -> Box<dyn Iterator<Item = Self::IndexType> + Send + '_>;
fn range_iter(&self, w: Range<Self::IndexType>) -> BoxedLIter<Self::IndexType>;

fn first_range(&self, w: Range<Self::IndexType>) -> Option<Self::IndexType>;
fn first_range(&self, w: Range<Self::IndexType>) -> Option<Self::IndexType> {
self.range_iter(w).next()
}

fn last_range(&self, w: Range<Self::IndexType>) -> Option<Self::IndexType>;
}
Expand Down
11 changes: 2 additions & 9 deletions raphtory/src/core/entities/properties/tcell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,10 @@ impl<A: Sync + Send> TCell<A> {
}

impl<A: Send + Sync> TimeIndexLike for TCell<A> {
fn range_iter(
&self,
w: Range<Self::IndexType>,
) -> Box<dyn Iterator<Item = Self::IndexType> + Send + '_> {
fn range_iter(&self, w: Range<Self::IndexType>) -> BoxedLIter<Self::IndexType> {
Box::new(self.iter_window(w).map(|(ti, _)| *ti))
}

fn first_range(&self, w: Range<Self::IndexType>) -> Option<Self::IndexType> {
self.iter_window(w).next().map(|(ti, _)| *ti)
}

fn last_range(&self, w: Range<Self::IndexType>) -> Option<Self::IndexType> {
self.iter_window(w).next_back().map(|(ti, _)| *ti)
}
Expand Down Expand Up @@ -236,7 +229,7 @@ impl<A: Send + Sync> TimeIndexOps for TCell<A> {
}
}

fn iter(&self) -> Box<dyn Iterator<Item = Self::IndexType> + Send + '_> {
fn iter(&self) -> BoxedLIter<Self::IndexType> {
match self {
TCell::Empty => Box::new(std::iter::empty()),
TCell::TCell1(t, _) => Box::new(std::iter::once(*t)),
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/core/storage/node_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<'a> NodeEntry<'a> {
pub fn into_rows_window(
self,
w: Range<TimeIndexEntry>,
) -> impl Iterator<Item = (TimeIndexEntry, Row<'a>)> {
) -> impl Iterator<Item = (TimeIndexEntry, Row<'a>)> + 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);
Expand Down
7 changes: 2 additions & 5 deletions raphtory/src/core/storage/timeindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ impl<T: AsTime> TimeIndex<T> {
}

impl<T: AsTime> TimeIndexLike for TimeIndex<T> {
fn range_iter(
&self,
w: Range<Self::IndexType>,
) -> Box<dyn Iterator<Item = Self::IndexType> + Send + '_> {
fn range_iter(&self, w: Range<Self::IndexType>) -> BoxedLIter<Self::IndexType> {
Box::new(self.range_iter(w))
}

Expand All @@ -154,7 +151,7 @@ pub enum TimeIndexWindow<'a, T: AsTime, TI> {
}

impl<'a, A: Copy + Send + Sync> TimeIndexWindow<'a, TimeIndexEntry, TCell<A>> {
pub fn iter_values(self) -> Box<dyn Iterator<Item = (TimeIndexEntry, A)> + Send + 'a> {
pub fn iter_values(self) -> Box<dyn Iterator<Item = (TimeIndexEntry, A)> + Send + Sync + 'a> {
match self {
TimeIndexWindow::Empty => Box::new(iter::empty()),
TimeIndexWindow::TimeIndexRange { timeindex, range } => {
Expand Down
7 changes: 2 additions & 5 deletions raphtory/src/db/api/view/internal/core_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl TimeIndexOps for NodeTimestamps {
.or_else(|| last.or(other))
}

fn iter(&self) -> Box<dyn Iterator<Item = Self::IndexType> + Send + '_> {
fn iter(&self) -> BoxedLIter<Self::IndexType> {
Box::new(
self.edge_ts
.iter()
Expand All @@ -383,10 +383,7 @@ impl TimeIndexOps for NodeTimestamps {
}

impl TimeIndexLike for NodeTimestamps {
fn range_iter(
&self,
w: Range<Self::IndexType>,
) -> Box<dyn Iterator<Item = Self::IndexType> + Send + '_> {
fn range_iter(&self, w: Range<Self::IndexType>) -> BoxedLIter<Self::IndexType> {
Box::new(
self.edge_ts
.range_iter(w.clone())
Expand Down

0 comments on commit a3e5126

Please sign in to comment.