pub struct CodeGraph { /* private fields */ }Expand description
Core graph with Arc-wrapped internals for O(1) CoW snapshots.
CodeGraph uses Arc for all internal components, enabling:
- O(1) snapshot creation via Arc cloning
- Copy-on-write semantics via
Arc::make_mut - Memory-efficient sharing between snapshots
§Design
The Arc wrapping enables the MVCC pattern:
- Readers see a consistent snapshot at the time they acquired access
- Writers use
Arc::make_mutto get exclusive copies only when mutating - Multiple snapshots can coexist without copying data
§Performance
- Snapshot creation: O(5) Arc clones ≈ <1μs
- Read access: Direct Arc dereference, no locking
- Write access:
Arc::make_mutclones only if refcount > 1
Implementations§
Source§impl CodeGraph
impl CodeGraph
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty CodeGraph.
§Example
use sqry_core::graph::unified::concurrent::CodeGraph;
let graph = CodeGraph::new();
assert_eq!(graph.epoch(), 0);Sourcepub fn from_components(
nodes: NodeArena,
edges: BidirectionalEdgeStore,
strings: StringInterner,
files: FileRegistry,
indices: AuxiliaryIndices,
) -> Self
pub fn from_components( nodes: NodeArena, edges: BidirectionalEdgeStore, strings: StringInterner, files: FileRegistry, indices: AuxiliaryIndices, ) -> Self
Creates a CodeGraph from existing components.
This is useful when building a graph from external data or reconstructing from serialized state.
Sourcepub fn snapshot(&self) -> GraphSnapshot
pub fn snapshot(&self) -> GraphSnapshot
Creates a cheap snapshot of the graph.
This operation is O(5) Arc clones, which completes in <1μs. The snapshot is isolated from future mutations to the original graph.
§Example
use sqry_core::graph::unified::concurrent::CodeGraph;
let graph = CodeGraph::new();
let snapshot = graph.snapshot();
// snapshot is independent of future mutations to graphSourcepub fn edges(&self) -> &BidirectionalEdgeStore
pub fn edges(&self) -> &BidirectionalEdgeStore
Returns a reference to the bidirectional edge store.
Sourcepub fn strings(&self) -> &StringInterner
pub fn strings(&self) -> &StringInterner
Returns a reference to the string interner.
Sourcepub fn files(&self) -> &FileRegistry
pub fn files(&self) -> &FileRegistry
Returns a reference to the file registry.
Sourcepub fn indices(&self) -> &AuxiliaryIndices
pub fn indices(&self) -> &AuxiliaryIndices
Returns a reference to the auxiliary indices.
Sourcepub fn nodes_mut(&mut self) -> &mut NodeArena
pub fn nodes_mut(&mut self) -> &mut NodeArena
Returns a mutable reference to the node arena.
Uses Arc::make_mut for copy-on-write semantics: if other
references exist (e.g., snapshots), the data is cloned.
Sourcepub fn edges_mut(&mut self) -> &mut BidirectionalEdgeStore
pub fn edges_mut(&mut self) -> &mut BidirectionalEdgeStore
Returns a mutable reference to the bidirectional edge store.
Uses Arc::make_mut for copy-on-write semantics.
Sourcepub fn strings_mut(&mut self) -> &mut StringInterner
pub fn strings_mut(&mut self) -> &mut StringInterner
Returns a mutable reference to the string interner.
Uses Arc::make_mut for copy-on-write semantics.
Sourcepub fn files_mut(&mut self) -> &mut FileRegistry
pub fn files_mut(&mut self) -> &mut FileRegistry
Returns a mutable reference to the file registry.
Uses Arc::make_mut for copy-on-write semantics.
Sourcepub fn indices_mut(&mut self) -> &mut AuxiliaryIndices
pub fn indices_mut(&mut self) -> &mut AuxiliaryIndices
Returns a mutable reference to the auxiliary indices.
Uses Arc::make_mut for copy-on-write semantics.
Sourcepub fn nodes_and_strings_mut(&mut self) -> (&mut NodeArena, &mut StringInterner)
pub fn nodes_and_strings_mut(&mut self) -> (&mut NodeArena, &mut StringInterner)
Returns mutable references to both the node arena and the string interner.
This avoids the borrow-conflict that arises when calling nodes_mut() and
strings_mut() separately on &mut self.
Sourcepub fn rebuild_indices(&mut self)
pub fn rebuild_indices(&mut self)
Rebuilds auxiliary indices from the current node arena.
This avoids the borrow conflict that arises when calling nodes() and
indices_mut() separately on &mut self. Uses disjoint field borrowing
to access nodes (shared) and indices (mutable) simultaneously.
Internally calls AuxiliaryIndices::build_from_arena which clears
existing indices and rebuilds in a single pass without per-element
duplicate checking.
Sourcepub fn bump_epoch(&mut self) -> u64
pub fn bump_epoch(&mut self) -> u64
Increments the epoch counter and returns the new value.
Called automatically by ConcurrentCodeGraph::write().
Sourcepub fn set_epoch(&mut self, epoch: u64)
pub fn set_epoch(&mut self, epoch: u64)
Sets the epoch to a specific value.
This is primarily for testing or reconstruction from serialized state.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the number of nodes in the graph.
This is a convenience method that delegates to nodes().len().
§Example
use sqry_core::graph::unified::concurrent::CodeGraph;
let graph = CodeGraph::new();
assert_eq!(graph.node_count(), 0);Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the number of edges in the graph (forward direction).
This counts edges in the forward store, including both CSR and delta edges.
§Example
use sqry_core::graph::unified::concurrent::CodeGraph;
let graph = CodeGraph::new();
assert_eq!(graph.edge_count(), 0);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the graph contains no nodes.
This is a convenience method that delegates to nodes().is_empty().
§Example
use sqry_core::graph::unified::concurrent::CodeGraph;
let graph = CodeGraph::new();
assert!(graph.is_empty());Sourcepub fn indexed_files(&self) -> impl Iterator<Item = (FileId, &Path)>
pub fn indexed_files(&self) -> impl Iterator<Item = (FileId, &Path)>
Returns an iterator over all indexed file paths.
This is useful for enumerating all files that have been processed and added to the graph.
§Example
use sqry_core::graph::unified::concurrent::CodeGraph;
let graph = CodeGraph::new();
for (file_id, path) in graph.indexed_files() {
println!("File {}: {}", file_id.index(), path.display());
}Sourcepub fn confidence(&self) -> &HashMap<String, ConfidenceMetadata>
pub fn confidence(&self) -> &HashMap<String, ConfidenceMetadata>
Returns the per-language confidence metadata.
This contains analysis confidence information collected during graph build, primarily used by language plugins (e.g., Rust) to track analysis quality.
Sourcepub fn merge_confidence(&mut self, language: &str, metadata: ConfidenceMetadata)
pub fn merge_confidence(&mut self, language: &str, metadata: ConfidenceMetadata)
Merges confidence metadata for a language.
If confidence already exists for the language, this merges the new metadata (taking the lower confidence level and combining limitations). Otherwise, it inserts the new confidence.
Sourcepub fn set_confidence(
&mut self,
confidence: HashMap<String, ConfidenceMetadata>,
)
pub fn set_confidence( &mut self, confidence: HashMap<String, ConfidenceMetadata>, )
Sets the confidence metadata map directly.
This is primarily used when loading a graph from serialized state.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CodeGraph
impl !RefUnwindSafe for CodeGraph
impl Send for CodeGraph
impl Sync for CodeGraph
impl Unpin for CodeGraph
impl UnsafeUnpin for CodeGraph
impl !UnwindSafe for CodeGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more