use rustc_hash::{FxHashMap, FxHashSet};
use crate::osc::CompactDiffOverlay;
pub(super) struct NodeLocationIndex {
pub(super) locations: FxHashMap<i64, (i32, i32)>,
pub(super) needed_set: FxHashSet<i64>,
}
impl NodeLocationIndex {
#[cfg_attr(feature = "hotpath", hotpath::measure)]
pub(super) fn build_from_diff(diff: &CompactDiffOverlay) -> Self {
let mut all_needed: FxHashSet<i64> = FxHashSet::default();
for &way_id in diff.way_ids() {
if let Some(way) = diff.get_way(way_id) {
for node_id in way.refs() {
all_needed.insert(node_id);
}
}
}
let mut locations: FxHashMap<i64, (i32, i32)> =
FxHashMap::with_capacity_and_hasher(all_needed.len(), Default::default());
let mut still_needed: FxHashSet<i64> = FxHashSet::default();
for &node_id in &all_needed {
if let Some(node) = diff.get_node(node_id) {
locations.insert(node_id, (node.decimicro_lat(), node.decimicro_lon()));
} else {
still_needed.insert(node_id);
}
}
Self {
locations,
needed_set: still_needed,
}
}
}