30 lines
1.1 KiB
Diff
30 lines
1.1 KiB
Diff
# UNDF: UNDF-2026-000001007
|
|
--- a/src/simutrans/simhalt.cc
|
|
+++ b/src/simutrans/simhalt.cc
|
|
@@ -1374,13 +1374,22 @@
|
|
|
|
void haltestelle_t::rebuild_linked_connections()
|
|
{
|
|
- vector_tpl<halthandle_t> all; // all halts connected to this halt
|
|
- for( uint8 i=0; i<goods_manager_t::get_max_catg_index(); i++ ){
|
|
+ // Collect unique connected halts using a hash set for O(1) membership test.
|
|
+ // Previously used append_unique (linear scan) inside a double loop over
|
|
+ // categories x connections, giving O(C * H^2) where H = connected halts.
|
|
+ // With the hash set this becomes O(C * H).
|
|
+ inthashtable_tpl<uint16, bool> seen;
|
|
+ vector_tpl<halthandle_t> all;
|
|
+ for( uint8 i=0; i<goods_manager_t::get_max_catg_index(); i++ ) {
|
|
vector_tpl<connection_t>& connections = all_links[i].connections;
|
|
|
|
for(connection_t &c : connections) {
|
|
- all.append_unique( c.halt );
|
|
+ if( c.halt.is_bound() ) {
|
|
+ uint16 halt_id = c.halt.get_id();
|
|
+ if( !seen.get(halt_id) ) {
|
|
+ seen.put(halt_id, true);
|
|
+ all.append(c.halt);
|
|
+ }
|
|
+ }
|
|
}
|
|
}
|
|
for(halthandle_t h : all) {
|