Skip to content

Commit

Permalink
change the compatible view handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ljeub-pometry committed Jan 23, 2025
1 parent 9998f5c commit 337edcb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ readme = "README.md"
homepage = "https://github.com/Raphtory/raphtory/"
keywords = ["graph", "temporal-graph", "temporal"]
authors = ["Pometry"]
rust-version = "1.84.0"
rust-version = "1.82.0"
edition = "2021"

[profile.dev]
Expand Down
23 changes: 17 additions & 6 deletions raphtory/src/db/api/storage/graph/storage_ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,25 @@ impl std::fmt::Display for GraphStorage {
}

impl GraphStorage {
/// Unique id for the storage that can be used to check if two views point at the same underlying
/// graph (and hence have compatible VIDs)
pub fn graph_id(&self) -> usize {
/// Check if two storage instances point at the same underlying storage
pub fn ptr_eq(&self, other: &Self) -> bool {
match self {
GraphStorage::Mem(g) => Arc::as_ptr(&g.graph).addr(),
GraphStorage::Unlocked(g) => Arc::as_ptr(g).addr(),
GraphStorage::Mem(LockedGraph {
graph: this_graph, ..
})
| GraphStorage::Unlocked(this_graph) => match other {
GraphStorage::Mem(LockedGraph {
graph: other_graph, ..
})
| GraphStorage::Unlocked(other_graph) => Arc::ptr_eq(this_graph, other_graph),
#[cfg(feature = "storage")]
_ => false,
},
#[cfg(feature = "storage")]
GraphStorage::Disk(g) => Arc::as_ptr(g).addr(),
GraphStorage::Disk(this_graph) => match other {
GraphStorage::Disk(other_graph) => Arc::ptr_eq(this_graph, other_graph),
_ => false,
},
}
}

Expand Down
5 changes: 5 additions & 0 deletions raphtory/src/db/api/view/internal/core_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ use std::{iter, ops::Range};
#[cfg(feature = "storage")]
use pometry_storage::timestamps::LayerAdditions;

/// Check if two Graph views point at the same underlying storage
pub fn is_view_compatible(g1: &impl CoreGraphOps, g2: &impl CoreGraphOps) -> bool {
g1.core_graph().ptr_eq(&g2.core_graph())
}

/// Core functions that should (almost-)always be implemented by pointing at the underlying graph.
#[enum_dispatch]
pub trait CoreGraphOps: Send + Sync {
Expand Down
7 changes: 5 additions & 2 deletions raphtory/src/db/graph/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use crate::{
};

use crate::db::{
api::state::{Index, NodeOp},
api::{
state::{Index, NodeOp},
view::internal::is_view_compatible,
},
graph::{create_node_type_filter, views::node_subgraph::NodeSubgraph},
};
use either::Either;
Expand Down Expand Up @@ -69,7 +72,7 @@ impl<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph> + Debug> Debug

impl<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>> PartialEq for Nodes<'graph, G, GH> {
fn eq(&self, other: &Self) -> bool {
if self.base_graph.core_graph().graph_id() == other.base_graph.core_graph().graph_id() {
if is_view_compatible(&self.base_graph, &other.base_graph) {
// same storage, can use internal ids
self.iter_refs().eq(other.iter_refs())
} else {
Expand Down

0 comments on commit 337edcb

Please sign in to comment.