pub fn find_next_existing_node(
    start: Option<NodeId>,
    node_ids: &[NodeId],
    node_indices: &HashMap<NodeId, NodeIndex>
) -> (Option<NodeId>, Option<NodeIndex>)
Expand description

Find the next existing node ID and its index in the node_indices HashMap after the given start ID.

This function searches the node_ids slice for the next existing node ID after the specified start ID. If the next existing node ID is found, it returns a tuple (Some(id), Some(index)), where id is the found node ID, and index is its index in the node_indices HashMap. If no existing node ID is found, it returns (None, None).

Arguments

  • start - An optional starting node ID to search from.
  • node_ids - A reference to the slice containing the node IDs.
  • node_indices - A reference to the HashMap containing the node indices.

Returns

A tuple (Option<i64>, Option<i64>) containing the next existing node ID and its index if found, or (None, None) otherwise.

Example

use std::collections::HashMap;
use petgraph::stable_graph::NodeIndex;
use openrailwaymap_exporter::importer::overpass_importer::find_next_existing_node;

let node_ids = vec![1, 3, 5];
let mut node_indices = HashMap::new();
node_indices.insert(1, NodeIndex::new(0));
node_indices.insert(3, NodeIndex::new(1));
node_indices.insert(5, NodeIndex::new(2));

assert_eq!(find_next_existing_node(Some(1), &node_ids, &node_indices), (Some(3), Some(NodeIndex::new(1))));
assert_eq!(find_next_existing_node(Some(3), &node_ids, &node_indices), (Some(5), Some(NodeIndex::new(2))));
assert_eq!(find_next_existing_node(Some(5), &node_ids, &node_indices), (None, None));
assert_eq!(find_next_existing_node(None, &node_ids, &node_indices), (Some(1), Some(NodeIndex::new(0))));