This patch simplifies FindMostPopularDest without changing the
functionality.
Given a list of jump threading destinations, the function finds the
most popular destination. To ensure determinism when there are
multiple destinations with the highest popularity, the function picks
the first one in the successor list with the highest popularity.
Without this patch:
- The function populates DestPopularity -- a histogram mapping destinations to their respective occurrence counts.
- Then we iterate over DestPopularity, looking for the highest popularity while building a vector of destinations with the highest popularity.
- Finally, we iterate the successor list, looking for the destination with the highest popularity.
With this patch:
- We implement DestPopularity with MapVector instead of DenseMap. We populate the map with popularity 0 for all successors in the order they appear in the successor list.
- We build the histogram in the same way as before.
- We simply use std::max_element on DestPopularity to find the most popular destination. The use of MapVector ensures determinism.
Initializing DestPopularity like this should be unnecessary, I think; as long as the ordering of PredToDestList is deterministic, the ordering of the resulting MapVector should also be deterministic.
Can we just assert !DestPopularity.empty(), instead of messing with nullptr? If PredToDestList is non-empty, DestPopularity should also be non-empty.over inserting nullptr; inserting nullptr simplifies the control flow, but it's not intuitive.