Wait — I'm still building the hash map for ways, so the direct writing doesn't help yet. The issue is that `sorted_geo_cells` is built from the union of `cell_to_ways`, `cell_to_addrs`, `cell_to_interps` keys. I need `cell_to_ways` to exist as a hash map for this union step.

But I can skip the hash map for the WRITE step — use `write_entries_from_sorted` for ways instead of the hash-map version. Let me update the write phase:


1904:                return write_entries(output_dir + "/street_entries.bin", sorted_geo_cells, data.cell_to_ways);
2998:            std::vector<CellItemPair> sorted_way_pairs, sorted_interp_pairs;
3000:                sorted_way_pairs = concat_and_sort(way_pairs);
3010:            build_cell_map(sorted_way_pairs, data.cell_to_ways);


The `sorted_way_pairs` is a local variable inside the S2 phase block, but I need it in the write phase. Let me make it a member of ParsedData or pass it through. Simpler: make it a local in the outer scope.


  2983→            // Build hash map from sorted pairs (for interps + cell_to_addrs union)
  2984→            auto build_cell_map = [](const std::vector<CellItemPair>& sorted,
  2985→                                      std::unordered_map<uint64_t, std::vector<uint32_t>>& out) {
  2986→                out.reserve(sorted.size() / 2);
  2987→                for (size_t i = 0; i < sorted.size(); ) {

            // Build hash map from sorted pairs (for interps + cell_to_addrs union)
            auto build_cell_map = [](const std::vector<CellItemPair>& sorted,
                                      std::unordered_map<uint64_t, std::vector<uint32_t>>& out) {
                out.reserve(sorted.size() / 2);
                for (size_t i = 0; i < sorted.size(); ) {


  2995→            };
  2996→
  2997→            // Sort ways and interps in parallel. Keep way pairs sorted for direct writing.
  2998→            std::vector<CellItemPair> sorted_way_pairs, sorted_interp_pairs;
  2999→            auto f_ways = std::async(std::launch::async, [&] {
  3000→                sorted_way_pairs = concat_and_sort(way_pairs);
  3001→            });
  3002→            auto f_interps = std::async(std::launch::async, [&] {
  3003→                sorted_interp_pairs = concat_and_sort(interp_pairs);
  3004→                build_cell_map(sorted_interp_pairs, data.cell_to_interps);
  3005→            });
  3006→            f_ways.get();
  3007→            f_interps.get();
  3008→
  3009→            // Build cell_to_ways from sorted pairs (still needed for sorted_geo_cells union + dedup)
  3010→            build_cell_map(sorted_way_pairs, data.cell_to_ways);
  3011→            log_phase("  S2: sort + group into cell maps", _s2t);
  3012→
  3013→            // Free deferred work items
  3014→            data.deferred_ways.clear();
  3015→            data.deferred_ways.shrink_to_fit();
  3016→            data.deferred_interps.clear();
  3017→            data.deferred_interps.shrink_to_fit();
  3018→
  3019→            std::cerr << "S2 cell computation complete." << std::endl;
  3020→        }
  3021→
  3022→        // Resolve interpolation endpoints
  3023→        std::cerr << "Resolving interpolation endpoints..." << std::endl;
  3024→        resolve_interpolation_endpoints(data);

            };

            // Sort ways and interps in parallel. Keep way pairs sorted for direct writing.
            std::vector<CellItemPair> sorted_way_pairs, sorted_interp_pairs;
            auto f_ways = std::async(std::launch::async, [&] {
                sorted_way_pairs = concat_and_sort(way_pairs);
            });
            auto f_interps = std::async(std::launch::async, [&] {
                sorted_interp_pairs = concat_and_sort(interp_pairs);
                build_cell_map(sorted_interp_pairs, data.cell_to_interps);
            });
            f_ways.get();
            f_interps.get();

            // Build cell_to_ways from sorted pairs (still needed for sorted_geo_cells union + dedup)
            build_cell_map(sorted_way_pairs, data.cell_to_ways);
            log_phase("  S2: sort + group into cell maps", _s2t);

            // Free deferred work items
            data.deferred_ways.clear();
            data.deferred_ways.shrink_to_fit();
            data.deferred_interps.clear();
            data.deferred_interps.shrink_to_fit();

            std::cerr << "S2 cell computation complete." << std::endl;
        }

        // Resolve interpolation endpoints
        std::cerr << "Resolving interpolation endpoints..." << std::endl;
        resolve_interpolation_endpoints(data);


The `sorted_way_pairs` is inside a block that ends at line 3020. I need to move it to an outer scope. Let me declare it before the block:


Edit

            // Sort ways and interps in parallel. Keep way pairs sorted for direct writing.
            std::vector<CellItemPair> sorted_way_pairs, sorted_interp_pairs;

            // Sort ways and interps in parallel. Keep way pairs sorted for direct writing.
            // sorted_way_pairs persists for use in write_entries_from_sorted later.
            data.sorted_way_cell_pairs.clear(); // will be populated below
            std::vector<CellItemPair> sorted_interp_pairs;