nodedb 0.0.0-beta.1

Local-first, real-time, edge-to-cloud hybrid database for multi-modal workloads
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//! Shared graph algorithm utilities.

use crate::engine::graph::csr::CsrIndex;

/// Collect undirected neighbors of a node (out + in, deduplicated).
pub fn undirected_neighbors(csr: &CsrIndex, node: u32) -> Vec<u32> {
    let mut neighbors: Vec<u32> = csr.iter_out_edges(node).map(|(_, dst)| dst).collect();
    for (_, src) in csr.iter_in_edges(node) {
        if !neighbors.contains(&src) {
            neighbors.push(src);
        }
    }
    neighbors
}