| 836 | } |
| 837 | |
| 838 | int HouseDetector::LoadStreets(vector<FeatureID> const & ids) |
| 839 | { |
| 840 | // LOG(LDEBUG, ("IDs = ", ids)); |
| 841 | |
| 842 | ASSERT(base::IsSortedAndUnique(ids), ()); |
| 843 | |
| 844 | // Check if the cache is obsolete and need to be cleared. |
| 845 | if (!m_id2st.empty()) |
| 846 | { |
| 847 | using Value = pair<FeatureID, Street *>; |
| 848 | function<Value::first_type const &(Value const &)> f = bind(&Value::first, _1); |
| 849 | |
| 850 | // Do clear cache if we have elements that are present in the one set, |
| 851 | // but not in the other one (set's order is irrelevant). |
| 852 | size_t const count = |
| 853 | set_intersection(make_transform_iterator(m_id2st.begin(), f), make_transform_iterator(m_id2st.end(), f), |
| 854 | ids.begin(), ids.end(), CounterIterator()) |
| 855 | .GetCount(); |
| 856 | |
| 857 | if (count < min(ids.size(), m_id2st.size())) |
| 858 | { |
| 859 | LOG(LDEBUG, ("Clear HouseDetector cache: " |
| 860 | "Common =", |
| 861 | count, "Cache =", m_id2st.size(), "Input =", ids.size())); |
| 862 | ClearCaches(); |
| 863 | } |
| 864 | else if (m_id2st.size() > ids.size() * 1.2) |
| 865 | { |
| 866 | LOG(LDEBUG, ("Clear unused")); |
| 867 | ClearUnusedStreets(ids); |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | // Load streets. |
| 872 | int count = 0; |
| 873 | for (size_t i = 0; i < ids.size(); ++i) |
| 874 | { |
| 875 | if (m_id2st.find(ids[i]) != m_id2st.end()) |
| 876 | continue; |
| 877 | |
| 878 | auto f = m_loader.Load(ids[i]); |
| 879 | if (!f) |
| 880 | { |
| 881 | LOG(LWARNING, ("Can't read feature from:", ids[i].m_mwmId)); |
| 882 | continue; |
| 883 | } |
| 884 | |
| 885 | if (f->GetGeomType() == feature::GeomType::Line) |
| 886 | { |
| 887 | // Use default name as a primary compare key for merging. |
| 888 | string_view const name = f->GetName(localisation::kDefaultNameIndex); |
| 889 | if (name.empty()) |
| 890 | continue; |
| 891 | |
| 892 | ++count; |
| 893 | |
| 894 | Street * st = new Street(); |
| 895 | st->SetName(name); |