Skip to main content

nodes_by_degree

Function nodes_by_degree 

Source
pub fn nodes_by_degree(
    graph: &SqliteGraph,
    descending: bool,
) -> Result<Vec<(i64, usize)>, SqliteGraphError>
Expand description

Computes node degrees (total number of incoming + outgoing edges).

Returns all nodes sorted by their degree, useful for finding hubs (high-degree nodes) or isolates (zero-degree nodes) in the graph.

§Arguments

  • graph - The graph to analyze
  • descending - If true, sort highest degree first; if false, sort lowest first

§Returns

Vector of (node_id, degree) tuples sorted by degree. Ties are broken by node ID.

§Complexity

Time: O(|V| + |E|) - visits each node and counts edges Space: O(|V|) for degree storage

§Example

use sqlitegraph::{SqliteGraph, algo::nodes_by_degree};
let graph = SqliteGraph::open_in_memory()?;
// ... add nodes and edges ...
let degrees = nodes_by_degree(&graph, true)?;