pub struct WikiGraph { /* private fields */ }Expand description
In-memory directed graph of wiki pages and their [[wikilink]] connections.
Implementations§
Source§impl WikiGraph
impl WikiGraph
pub fn new() -> Self
Sourcepub fn upsert_node(
&mut self,
slug: &str,
title: &str,
is_placeholder: bool,
) -> NodeIndex
pub fn upsert_node( &mut self, slug: &str, title: &str, is_placeholder: bool, ) -> NodeIndex
Add or update a node. Returns its NodeIndex.
Sourcepub fn remove_node(&mut self, slug: &str)
pub fn remove_node(&mut self, slug: &str)
Remove a node and all its edges.
Sourcepub fn set_outgoing_edges(&mut self, source_slug: &str, target_slugs: &[String])
pub fn set_outgoing_edges(&mut self, source_slug: &str, target_slugs: &[String])
Set outgoing edges FROM a source node.
Removes all existing outgoing edges first, then adds new ones. Creates placeholder nodes for targets that don’t exist. Duplicate targets are deduplicated — at most one edge per (source, target) pair.
Sourcepub fn get_backlinks(&self, slug: &str) -> Vec<String>
pub fn get_backlinks(&self, slug: &str) -> Vec<String>
Get all slugs that link TO a given slug (backlinks / incoming). Results are sorted by slug for deterministic output.
Sourcepub fn get_forward_links(&self, slug: &str) -> Vec<String>
pub fn get_forward_links(&self, slug: &str) -> Vec<String>
Get all slugs that a given slug links TO (forward links / outgoing). Results are sorted by slug for deterministic output.
Sourcepub fn cleanup_orphaned_placeholders(&mut self) -> Vec<String>
pub fn cleanup_orphaned_placeholders(&mut self) -> Vec<String>
Remove placeholder nodes that have zero edges. Returns the slugs of removed nodes.
Uses batched removal with a single index rebuild at the end, avoiding the O(n * k) cost of rebuilding after each removal.