grafeo_core/graph/mod.rs
1//! Graph model implementations.
2//!
3//! Pick your graph model:
4//!
5//! | Model | When to use | Example use case |
6//! | ----- | ----------- | ---------------- |
7//! | [`lpg`] | Most apps (default) | Social networks, fraud detection |
8//! | [`compact`] | Read-heavy / embedded (feature-gated: `compact-store`) | WASM, edge workers, static snapshots |
9//! | [`rdf`] | Knowledge graphs | Ontologies, linked data (feature-gated) |
10//!
11//! These are separate implementations with no abstraction overhead - you get
12//! the full performance of whichever model you choose.
13
14pub mod lpg;
15pub mod traits;
16
17#[cfg(feature = "compact-store")]
18pub mod compact;
19
20#[cfg(feature = "rdf")]
21pub mod rdf;
22
23pub use traits::{GraphStore, GraphStoreMut, NullGraphStore};
24
25/// Controls which edges to follow during traversal.
26///
27/// Most graph operations need to specify direction. Use [`Outgoing`](Self::Outgoing)
28/// when you care about relationships *from* a node, [`Incoming`](Self::Incoming) for
29/// relationships *to* a node, and [`Both`](Self::Both) when direction doesn't matter.
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
31pub enum Direction {
32 /// Follow outgoing edges (A)-\[r\]->(B) from A's perspective.
33 Outgoing,
34 /// Follow incoming edges (A)<-\[r\]-(B) from A's perspective.
35 Incoming,
36 /// Follow edges in either direction - treat the graph as undirected.
37 Both,
38}
39
40impl Direction {
41 /// Flips the direction - outgoing becomes incoming and vice versa.
42 ///
43 /// Useful when traversing backward along a path.
44 #[must_use]
45 pub const fn reverse(self) -> Self {
46 match self {
47 Direction::Outgoing => Direction::Incoming,
48 Direction::Incoming => Direction::Outgoing,
49 Direction::Both => Direction::Both,
50 }
51 }
52}