Skip to content

Commit

Permalink
add more references for LayerIds
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmurariu committed Oct 25, 2024
1 parent 28fc2cb commit cf83ee0
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 137 deletions.
6 changes: 2 additions & 4 deletions raphtory/src/core/entities/nodes/node_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,10 @@ impl<'a> Entry<'a, NodeStore> {

pub fn into_edges_iter(
self,
layers: LayerIds,
layers: &LayerIds,
dir: Direction,
) -> impl Iterator<Item = EdgeRef> + 'a {
GenLockedIter::from((self, layers), |(node, layers)| {
Box::new(node.edge_tuples(layers, dir))
})
GenLockedIter::from(self, |node| Box::new(node.edge_tuples(layers, dir)))
}
}

Expand Down
12 changes: 6 additions & 6 deletions raphtory/src/db/api/storage/graph/edges/edge_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'a, 'b: 'a> EdgeStorageOps<'a> for &'a EdgeStorageEntry<'b> {
self.as_ref().out_ref()
}

fn active(self, layer_ids: LayerIds, w: Range<i64>) -> bool {
fn active(self, layer_ids: &LayerIds, w: Range<i64>) -> bool {
self.as_ref().active(layer_ids, w)
}

Expand All @@ -61,7 +61,7 @@ impl<'a, 'b: 'a> EdgeStorageOps<'a> for &'a EdgeStorageEntry<'b> {
self.as_ref().dst()
}

fn layer_ids_iter(self, layer_ids: LayerIds) -> impl Iterator<Item = usize> + 'a {
fn layer_ids_iter(self, layer_ids: &LayerIds) -> impl Iterator<Item = usize> + 'a {
self.as_ref().layer_ids_iter(layer_ids)
}

Expand All @@ -71,7 +71,7 @@ impl<'a, 'b: 'a> EdgeStorageOps<'a> for &'a EdgeStorageEntry<'b> {

fn additions_iter(
self,
layer_ids: LayerIds,
layer_ids: &LayerIds,
) -> impl Iterator<Item = (usize, TimeIndexRef<'a>)> + 'a {
self.as_ref().additions_iter(layer_ids)
}
Expand All @@ -85,7 +85,7 @@ impl<'a, 'b: 'a> EdgeStorageOps<'a> for &'a EdgeStorageEntry<'b> {

fn deletions_iter(
self,
layer_ids: LayerIds,
layer_ids: &LayerIds,
) -> impl Iterator<Item = (usize, TimeIndexRef<'a>)> + 'a {
self.as_ref().deletions_iter(layer_ids)
}
Expand All @@ -99,7 +99,7 @@ impl<'a, 'b: 'a> EdgeStorageOps<'a> for &'a EdgeStorageEntry<'b> {

fn updates_iter(
self,
layer_ids: LayerIds,
layer_ids: &LayerIds,
) -> impl Iterator<Item = (usize, TimeIndexRef<'a>, TimeIndexRef<'a>)> + 'a {
self.as_ref().updates_iter(layer_ids)
}
Expand Down Expand Up @@ -129,7 +129,7 @@ impl<'a, 'b: 'a> EdgeStorageOps<'a> for &'a EdgeStorageEntry<'b> {

fn temporal_prop_iter(
self,
layer_ids: LayerIds,
layer_ids: &LayerIds,
prop_id: usize,
) -> impl Iterator<Item = (usize, impl TPropOps<'a>)> + 'a {
self.as_ref().temporal_prop_iter(layer_ids, prop_id)
Expand Down
10 changes: 5 additions & 5 deletions raphtory/src/db/api/storage/graph/edges/edge_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<'a> EdgeStorageOps<'a> for EdgeStorageRef<'a> {
for_all!(self, edge => EdgeStorageOps::out_ref(edge))
}

fn active(self, layer_ids: LayerIds, w: Range<i64>) -> bool {
fn active(self, layer_ids: &LayerIds, w: Range<i64>) -> bool {
for_all!(self, edge => EdgeStorageOps::active(edge, layer_ids, w))
}

Expand All @@ -74,7 +74,7 @@ impl<'a> EdgeStorageOps<'a> for EdgeStorageRef<'a> {
for_all!(self, edge => edge.dst())
}

fn layer_ids_iter(self, layer_ids: LayerIds) -> impl Iterator<Item = usize> + 'a {
fn layer_ids_iter(self, layer_ids: &LayerIds) -> impl Iterator<Item = usize> + 'a {
for_all_iter!(self, edge => EdgeStorageOps::layer_ids_iter(edge, layer_ids))
}

Expand All @@ -84,7 +84,7 @@ impl<'a> EdgeStorageOps<'a> for EdgeStorageRef<'a> {

fn additions_iter(
self,
layer_ids: LayerIds,
layer_ids: &LayerIds,
) -> impl Iterator<Item = (usize, TimeIndexRef<'a>)> + 'a {
for_all_iter!(self, edge => EdgeStorageOps::additions_iter(edge, layer_ids))
}
Expand All @@ -98,7 +98,7 @@ impl<'a> EdgeStorageOps<'a> for EdgeStorageRef<'a> {

fn deletions_iter(
self,
layer_ids: LayerIds,
layer_ids: &LayerIds,
) -> impl Iterator<Item = (usize, TimeIndexRef<'a>)> + 'a {
for_all_iter!(self, edge => EdgeStorageOps::deletions_iter(edge, layer_ids))
}
Expand All @@ -112,7 +112,7 @@ impl<'a> EdgeStorageOps<'a> for EdgeStorageRef<'a> {

fn updates_iter(
self,
layer_ids: LayerIds,
layer_ids: &LayerIds,
) -> impl Iterator<Item = (usize, TimeIndexRef<'a>, TimeIndexRef<'a>)> + 'a {
for_all_iter!(self, edge => EdgeStorageOps::updates_iter(edge, layer_ids))
}
Expand Down
25 changes: 14 additions & 11 deletions raphtory/src/db/api/storage/graph/edges/edge_storage_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,19 @@ impl<'a> TimeIndexIntoOps for TimeIndexRef<'a> {
pub trait EdgeStorageOps<'a>: Copy + Sized + Send + Sync + 'a {
fn out_ref(self) -> EdgeRef;

fn active(self, layer_ids: LayerIds, w: Range<i64>) -> bool;
fn active(self, layer_ids: &LayerIds, w: Range<i64>) -> bool;

fn has_layer(self, layer_ids: &LayerIds) -> bool;
fn src(self) -> VID;
fn dst(self) -> VID;

fn layer_ids_iter(self, layer_ids: LayerIds) -> impl Iterator<Item = usize> + 'a;
fn layer_ids_iter(self, layer_ids: &LayerIds) -> impl Iterator<Item = usize> + 'a;

fn layer_ids_par_iter(self, layer_ids: LayerIds) -> impl ParallelIterator<Item = usize> + 'a;

fn additions_iter(
self,
layer_ids: LayerIds,
layer_ids: &LayerIds,
) -> impl Iterator<Item = (usize, TimeIndexRef<'a>)> + 'a {
self.layer_ids_iter(layer_ids)
.map(move |id| (id, self.additions(id)))
Expand All @@ -174,7 +174,7 @@ pub trait EdgeStorageOps<'a>: Copy + Sized + Send + Sync + 'a {
}
fn deletions_iter(
self,
layer_ids: LayerIds,
layer_ids: &LayerIds,
) -> impl Iterator<Item = (usize, TimeIndexRef<'a>)> + 'a {
self.layer_ids_iter(layer_ids)
.map(move |id| (id, self.deletions(id)))
Expand All @@ -190,7 +190,7 @@ pub trait EdgeStorageOps<'a>: Copy + Sized + Send + Sync + 'a {

fn updates_iter(
self,
layer_ids: LayerIds,
layer_ids: &LayerIds,
) -> impl Iterator<Item = (usize, TimeIndexRef<'a>, TimeIndexRef<'a>)> + 'a {
self.layer_ids_iter(layer_ids)
.map(move |id| (id, self.additions(id), self.deletions(id)))
Expand All @@ -216,7 +216,7 @@ pub trait EdgeStorageOps<'a>: Copy + Sized + Send + Sync + 'a {

fn temporal_prop_iter(
self,
layer_ids: LayerIds,
layer_ids: &LayerIds,
prop_id: usize,
) -> impl Iterator<Item = (usize, impl TPropOps<'a>)> + 'a {
self.layer_ids_iter(layer_ids)
Expand Down Expand Up @@ -294,16 +294,19 @@ impl<'a> MemEdge<'a> {
}

impl<'a> EdgeStorageOps<'a> for MemEdge<'a> {
fn active(self, layer_ids: LayerIds, w: Range<i64>) -> bool {
fn active(self, layer_ids: &LayerIds, w: Range<i64>) -> bool {
match layer_ids {
LayerIds::None => false,
LayerIds::All => self
.additions_iter(layer_ids)
.any(|(_, t_index)| t_index.active_t(w.clone())),
LayerIds::One(l_id) => self.get_additions(l_id).filter(|a| a.active_t(w)).is_some(),
LayerIds::One(l_id) => self
.get_additions(*l_id)
.filter(|a| a.active_t(w))
.is_some(),
LayerIds::Multiple(layers) => layers
.iter()
.any(|l_id| self.active(LayerIds::One(l_id), w.clone())),
.any(|l_id| self.active(&LayerIds::One(l_id), w.clone())),
}
}

Expand All @@ -328,14 +331,14 @@ impl<'a> EdgeStorageOps<'a> for MemEdge<'a> {
EdgeRef::new_outgoing(self.eid(), self.src(), self.dst())
}

fn layer_ids_iter(self, layer_ids: LayerIds) -> impl Iterator<Item = usize> + 'a {
fn layer_ids_iter(self, layer_ids: &LayerIds) -> impl Iterator<Item = usize> + 'a {
match layer_ids {
LayerIds::None => LayerVariants::None(std::iter::empty()),
LayerIds::All => LayerVariants::All(
(0..self.internal_num_layers()).filter(move |&l| self.has_layer_inner(l)),
),
LayerIds::One(id) => {
LayerVariants::One(self.has_layer_inner(id).then_some(id).into_iter())
LayerVariants::One(self.has_layer_inner(*id).then_some(*id).into_iter())
}
LayerIds::Multiple(ids) => {
LayerVariants::Multiple(ids.iter().filter(move |&id| self.has_layer_inner(id)))
Expand Down
18 changes: 12 additions & 6 deletions raphtory/src/db/api/storage/graph/edges/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@ pub enum EdgesStorageRef<'a> {

impl<'a> EdgesStorageRef<'a> {
#[cfg(feature = "storage")]
pub fn iter(self, layers: LayerIds) -> impl Iterator<Item = EdgeStorageEntry<'a>> {
pub fn iter(
self,
layers: &LayerIds,
) -> impl Iterator<Item = EdgeStorageEntry<'a>> + use<'a, '_> {
match self {
EdgesStorageRef::Mem(storage) => StorageVariants::Mem(
storage
.iter()
.filter(move |e| e.has_layer(layers.clone()))
.filter(move |e| e.has_layer(layers))
.map(EdgeStorageEntry::Mem),
),
EdgesStorageRef::Unlocked(edges) => StorageVariants::Unlocked(
edges
.iter()
.filter(move |e| e.has_layer(layers.clone()))
.filter(move |e| e.has_layer(layers))
.map(EdgeStorageEntry::Unlocked),
),
EdgesStorageRef::Disk(storage) => {
Expand Down Expand Up @@ -80,18 +83,21 @@ impl<'a> EdgesStorageRef<'a> {
}

#[cfg(feature = "storage")]
pub fn par_iter(self, layers: LayerIds) -> impl ParallelIterator<Item = EdgeStorageEntry<'a>> {
pub fn par_iter(
self,
layers: &LayerIds,
) -> impl ParallelIterator<Item = EdgeStorageEntry<'a>> + use<'a, '_> {
match self {
EdgesStorageRef::Mem(storage) => StorageVariants::Mem(
storage
.par_iter()
.filter(move |e| e.has_layer(layers.clone()))
.filter(move |e| e.has_layer(layers))
.map(EdgeStorageEntry::Mem),
),
EdgesStorageRef::Unlocked(edges) => StorageVariants::Unlocked(
edges
.par_iter()
.filter(move |e| e.has_layer(layers.clone()))
.filter(move |e| e.has_layer(layers))
.map(EdgeStorageEntry::Unlocked),
),
EdgesStorageRef::Disk(storage) => {
Expand Down
4 changes: 2 additions & 2 deletions raphtory/src/db/api/storage/graph/nodes/node_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ impl<'a, 'b: 'a> From<&'a NodeStorageEntry<'b>> for NodeStorageRef<'a> {
impl<'b> NodeStorageEntry<'b> {
pub fn into_edges_iter(
self,
layers: LayerIds,
layers: &LayerIds,
dir: Direction,
) -> impl Iterator<Item = EdgeRef> + 'b {
match self {
NodeStorageEntry::Mem(entry) => {
StorageVariants::Mem(GenLockedIter::from((entry, layers), |(entry, layers)| {
StorageVariants::Mem(GenLockedIter::from(entry, |entry| {
Box::new(entry.edges_iter(layers, dir))
}))
}
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/db/api/storage/graph/storage_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ impl GraphStorage {
) -> impl Iterator<Item = EdgeRef> + 'a {
let source = self.node_entry(node);
let layers = view.layer_ids();
let iter = source.into_edges_iter(layers.clone(), dir);
let iter = source.into_edges_iter(layers, dir);
match view.filter_state() {
FilterState::Neither => FilterVariants::Neither(iter),
FilterState::Both => FilterVariants::Both(iter.filter(|&e| {
Expand Down
Loading

0 comments on commit cf83ee0

Please sign in to comment.