Skip to main content

WikiGraph

Struct WikiGraph 

Source
pub struct WikiGraph { /* private fields */ }
Expand description

In-memory directed graph of wiki pages and their [[wikilink]] connections.

Implementations§

Source§

impl WikiGraph

Source

pub fn new() -> Self

Source

pub fn upsert_node( &mut self, slug: &str, title: &str, is_placeholder: bool, ) -> NodeIndex

Add or update a node. Returns its NodeIndex.

Source

pub fn remove_node(&mut self, slug: &str)

Remove a node and all its edges.

Source

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.

Get all slugs that link TO a given slug (backlinks / incoming). Results are sorted by slug for deterministic output.

Get all slugs that a given slug links TO (forward links / outgoing). Results are sorted by slug for deterministic output.

Source

pub fn degree(&self, slug: &str) -> usize

Get the degree (total edges in + out) of a node.

Source

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.

Source

pub fn get_full_graph(&self) -> (Vec<GraphNode>, Vec<GraphEdge>)

Get full graph data for serialization. Nodes sorted by slug, edges sorted by (source, target) for deterministic output.

Source

pub fn stats(&self) -> (usize, usize)

Get node and edge counts.

Trait Implementations§

Source§

impl Default for WikiGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.