Skip to main content

get_neighbors_cached

Function get_neighbors_cached 

Source
pub fn get_neighbors_cached(
    graph_file: &mut GraphFile,
    node_id: NativeNodeId,
    direction: Direction,
    cache: &mut TraversalCache,
    stats: &mut TraversalCacheStats,
) -> NativeResult<Vec<NativeNodeId>>
Expand description

Get neighbors for a node with per-traversal caching.

This helper function checks the cache before falling through to AdjacencyHelpers, reducing redundant I/O during traversals.

§Parameters

  • graph_file: Mutable borrow of the graph file for I/O operations
  • node_id: The node whose neighbors we want to fetch
  • direction: Whether to get Outgoing or Incoming neighbors
  • cache: Mutable borrow of the per-traversal cache
  • stats: Mutable borrow of statistics tracking (optional)

§Returns

An owned Vec<NativeNodeId> containing the neighbor node IDs.

Note: Returns an owned Vec (not a reference) to avoid borrow checker lifetime issues. The clone is cheap for typical neighbor list sizes.

§Example

let mut cache = TraversalCache::new();
let mut stats = TraversalCacheStats::default();

let neighbors = get_neighbors_cached(
    graph_file,
    node_id,
    Direction::Outgoing,
    &mut cache,
    &mut stats,
)?;