Skip to content

fix: stopCode lookup added#93

Open
pranavs6 wants to merge 1 commit into
mainfrom
fix/stopCode_id_lookup
Open

fix: stopCode lookup added#93
pranavs6 wants to merge 1 commit into
mainfrom
fix/stopCode_id_lookup

Conversation

@pranavs6

Copy link
Copy Markdown
Member

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an additional lookup key for stops so callers can retrieve stops by stop.code as well as by the stop id suffix parsed from stop.id.

Changes:

  • Store each stop in stops_by_gtfs under stop_code (from stop.id) and, when different/non-empty, also under stop.code.
  • Clone stop_res to support inserting the same stop under multiple keys.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +792 to +794
stop_data.stops.insert(stop_code.to_string(), stop_res.clone());
if stop.code != stop_code && !stop.code.is_empty() {
stop_data.stops.insert(stop.code.clone(), stop_res);

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stop_res is cloned unconditionally to insert under stop_code, even when the alternate stop.code key is not inserted. This adds extra allocations per stop (potentially significant for large feeds). Consider inserting stop_res by move for the common case and only cloning when the alternate key is actually needed (e.g., branch on the condition and choose which insert gets the moved value).

Suggested change
stop_data.stops.insert(stop_code.to_string(), stop_res.clone());
if stop.code != stop_code && !stop.code.is_empty() {
stop_data.stops.insert(stop.code.clone(), stop_res);
if stop.code != stop_code && !stop.code.is_empty() {
stop_data
.stops
.insert(stop_code.to_string(), stop_res.clone());
stop_data.stops.insert(stop.code.clone(), stop_res);
} else {
stop_data.stops.insert(stop_code.to_string(), stop_res);

Copilot uses AI. Check for mistakes.
stop_data.stops.insert(stop_code.to_string(), stop_res);
stop_data.stops.insert(stop_code.to_string(), stop_res.clone());
if stop.code != stop_code && !stop.code.is_empty() {
stop_data.stops.insert(stop.code.clone(), stop_res);

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new stop.code alias insertion uses HashMap::insert, which will silently overwrite an existing stop if another record already used the same stop.code key. Since GTFS stop_code is not guaranteed unique, this can lead to incorrect stop lookups depending on input ordering. Consider guarding against collisions (e.g., only insert if the key is vacant, or detect differing ids and log/skip/fail).

Suggested change
stop_data.stops.insert(stop.code.clone(), stop_res);
match stop_data.stops.entry(stop.code.clone()) {
std::collections::hash_map::Entry::Vacant(entry) => {
entry.insert(stop_res);
}
std::collections::hash_map::Entry::Occupied(entry) => {
if entry.get().id != stop_res.id {
// Preserve the first alias mapping and skip conflicting stop.code collisions.
}
}
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants