1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al. 3 * This file is part of Overpass_API. 5 * Overpass_API is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 10 * Overpass_API is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 15 * You should have received a copy of the GNU Affero General Public License 16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>. 19#include "abstract_processing.h" 20#include "collect_members.h" 25//----------------------------------------------------------------------------- 27template< typename Container > 29 const Container& ways, const std::vector< int >& pos, std::vector< Node::Id_Type >& ids) 31118 q for (const auto& i : ways) 33115 q for (const auto& j : i.second) 35915 q auto it3 = pos.begin(); 36965 q while (it3 != pos.end() && *it3 < 0) 3853 q if (*it3 + (int)j.nds.size() >= 0) 3953 q ids.push_back(j.nds[*it3 + j.nds.size()]); 42915 q while (it3 != pos.end() && *it3 == 0) 441785 q while(it3 != pos.end()) 46873 q if (*it3 < (int)j.nds.size()+1) 47873 q ids.push_back(j.nds[*it3-1]); 55template< typename Container > 56void way_nd_ids_plain(const Container& ways, std::vector< Node::Id_Type >& ids) 582731892 q for (const auto& i : ways) 603885454 q for (const auto& j : i.second) 6221534753 q for (auto k : j.nds) 63192870653 q ids.push_back(k); 69template< typename Container > 70void way_nd_ids_once(const Container& ways, std::vector< Node::Id_Type >& ids) 723120 q for (const auto& i : ways) 74212713 q for (const auto& j : i.second) 761150813 q auto size = ids.size(); 771150813 q for (auto k : j.nds) 791150813 q std::sort(ids.begin()+size, ids.end()); 801150813 q ids.erase(std::unique(ids.begin()+size, ids.end()), ids.end()); 86template< typename Container > 87void way_nd_firstlast(const Container& ways, std::vector< Node::Id_Type >& ids) 892615 q for (const auto& i : ways) 911967 q for (const auto& j : i.second) 9312456 q if (j.nds.empty()) 9512456 q ids.push_back(j.nds.front()); 9612456 q ids.push_back(j.nds.back()); 102std::vector< Node::Id_Type > way_nd_ids( 103 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways, 104 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways, 105 const std::vector< int >* pos) 1072561583 q std::vector< Node::Id_Type > ids; 109118 q way_nd_ids_pos(ways, *pos, ids); 1112560478 q way_nd_ids_plain(ways, ids); 1132561583 q if (!attic_ways.empty()) 1160 way_nd_ids_pos(attic_ways, *pos, ids); 118168816 q way_nd_ids_plain(attic_ways, ids); 1212561583 q std::sort(ids.begin(), ids.end()); 1222561583 q ids.erase(std::unique(ids.begin(), ids.end()), ids.end()); 128std::vector< Node::Id_Type > way_cnt_nd_ids( 129 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways, 130 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways, 131 unsigned int lower_limit, unsigned int upper_limit) 1332520 q std::vector< Node::Id_Type > ids; 1342520 q way_nd_ids_once(ways, ids); 13665 q way_nd_ids_once(attic_ways, ids); 1382520 q std::sort(ids.begin(), ids.end()); 1402520 q decltype(ids.size()) lower = 0; 1412520 q decltype(ids.size()) upper = 0; 1422520 q decltype(ids.size()) target = 0; 1435157420 q while (lower < ids.size()) 14510933013 q while (upper < ids.size() && ids[lower] == ids[upper]) 1475154913 q if (lower_limit <= upper - lower && upper - lower <= upper_limit) 1484736711 q ids[target++] = ids[lower]; 157std::vector< Node::Id_Type > way_link_nd_ids( 158 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways, 159 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways, 160 unsigned int lower_limit, unsigned int upper_limit) 1622015 q std::vector< Node::Id_Type > ids; 1632015 q way_nd_ids_plain(ways, ids); 16565 q way_nd_ids_plain(attic_ways, ids); 1672015 q std::sort(ids.begin(), ids.end()); 1692015 q std::vector< Node::Id_Type > fl_ids; 1702015 q way_nd_firstlast(ways, fl_ids); 17265 q way_nd_firstlast(attic_ways, fl_ids); 1742015 q std::sort(fl_ids.begin(), fl_ids.end()); 1762015 q decltype(ids.size()) lower = 0; 1772015 q decltype(ids.size()) upper = 0; 1782015 q decltype(fl_ids.size()) fl_lower = 0; 1792015 q decltype(fl_ids.size()) fl_upper = 0; 1802015 q decltype(ids.size()) target = 0; 1811244915 q while (lower < ids.size()) 183269846 q while (upper < ids.size() && ids[lower] == ids[upper]) 185124296 q while (fl_lower < fl_ids.size() && fl_ids[fl_lower] < ids[lower]) 187124296 q fl_upper = fl_lower; 188149196 q while (fl_upper < fl_ids.size() && fl_ids[fl_upper] == ids[lower]) 190124296 q if (lower_limit <= 2*(upper - lower) + fl_lower - fl_upper 191124296 q && 2*(upper - lower) + fl_lower - fl_upper <= upper_limit) 19274026 q ids[target++] = ids[lower]; 194124296 q fl_lower = fl_upper; 202Ranges< Uint32_Index > calc_node_children_ranges(const std::vector< uint32 >& way_rel_idxs) 20459831501 q Ranges< Uint32_Index > result; 20659831501 q for (std::vector< uint32 >::const_iterator it = way_rel_idxs.begin(); 2071513368501 q it != way_rel_idxs.end(); ++it) 219128244330 q lat = upper_ilat(*it & 0x2aaaaaa8); 220128244330 q lon = upper_ilon(*it & 0x55555554); 2254675143 q lat = upper_ilat(*it & 0x2aaaaa80); 2264675143 q lon = upper_ilon(*it & 0x55555540); 2294810 q else if (*it & 0x00000004) 23141 q lat = upper_ilat(*it & 0x2aaaa800); 23241 q lon = upper_ilon(*it & 0x55555400); 235449 q else if (*it & 0x00000008) 237123 q lat = upper_ilat(*it & 0x2aaa8000); 238123 q lon = upper_ilon(*it & 0x55554000); 241326 q else if (*it & 0x00000010) 243205 q lat = upper_ilat(*it & 0x2aa80000); 244205 q lon = upper_ilon(*it & 0x55540000); 247123 q else if (*it & 0x00000020) 249123 q lat = upper_ilat(*it & 0x2a800000); 250123 q lon = upper_ilon(*it & 0x55400000); 2530 else if (*it & 0x00000040) 2550 lat = upper_ilat(*it & 0x28000000); 2560 lon = upper_ilon(*it & 0x54000000); 2590 else // *it == 0x80000080 266132967331 q result.push_back(ll_upper(lat<<16, lon<<16), ll_upper((lat+offset-1)<<16, (lon+offset-1)<<16)+1); 267132967331 q result.push_back(ll_upper(lat<<16, (lon+offset)<<16), ll_upper((lat+offset-1)<<16, (lon+2*offset-1)<<16)+1); 268132967331 q result.push_back(ll_upper((lat+offset)<<16, lon<<16), ll_upper((lat+2*offset-1)<<16, (lon+offset-1)<<16)+1); 270132967331 q ll_upper((lat+offset)<<16, (lon+offset)<<16), ll_upper((lat+2*offset-1)<<16, (lon+2*offset-1)<<16)+1); 271132967331 q for (uint32 i = lat; i <= lat_u; ++i) 2730 for (uint32 j = lon; j <= lon_u; ++j) 2740 result.push_back(ll_upper(i<<16, j<<16), ll_upper(i<<16, j<<16)+1); 2781320570359 q result.push_back(*it, (*it) + 1); 286Ranges< Uint32_Index > relation_node_member_indices( 287 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& current_rels, 288 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels) 29027974473 q std::vector< uint32 > parents; 29271038473 q for (auto it = current_rels.begin(); it != current_rels.end(); ++it) 29443064181 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0)) 296 // Treat relations with really large indices: get the node indexes from the segement indexes 29781124147 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) 29978653123 q for (std::vector< Uint31_Index >::const_iterator it3 = it2->node_idxs.begin(); 3001139244123 q it3 != it2->node_idxs.end(); ++it3) 3011060591116 q parents.push_back(it3->val()); 30540593158 q parents.push_back(it->first.val()); 30752764473 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it) 3092479041 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0)) 311 // Treat relations with really large indices: get the node indexes from the segement indexes 312101030 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) 31425312 q for (std::vector< Uint31_Index >::const_iterator it3 = it2->node_idxs.begin(); 315352912 q it3 != it2->node_idxs.end(); ++it3) 31632768 q parents.push_back(it3->val()); 3202403328 q parents.push_back(it->first.val()); 32327974473 q return calc_node_children_ranges(parents); 327Ranges< Uint31_Index > relation_way_member_indices 328 (const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& current_rels, 329 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels) 33128110477 q std::vector< Uint31_Index > parents; 33228110477 q std::vector< Uint31_Index > children_idxs; 33476495477 q for (auto it = current_rels.begin(); it != current_rels.end(); ++it) 33648385183 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0)) 338 // Treat relations with really large indices: get the ways indexes explicitly 33986648150 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) 34184090126 q for (std::vector< Uint31_Index >::const_iterator it3 = it2->way_idxs.begin(); 34215081575126 q it3 != it2->way_idxs.end(); ++it3) 34314997485121 q children_idxs.push_back(*it3); 34745827159 q parents.push_back(it->first); 34957571477 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it) 3512946173 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0)) 353 // Treat relations with really large indices: get the ways indexes explicitly 3542758961 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) 3562593044 q for (std::vector< Uint31_Index >::const_iterator it3 = it2->way_idxs.begin(); 357456514044 q it3 != it2->way_idxs.end(); ++it3) 358453921044 q children_idxs.push_back(*it3); 3622780258 q parents.push_back(it->first); 36528110477 q std::sort(children_idxs.begin(), children_idxs.end()); 36628110477 q children_idxs.erase(std::unique(children_idxs.begin(), children_idxs.end()), children_idxs.end()); 36828110477 q return collect_way_req(parents, children_idxs); 372Ranges< Uint31_Index > uint31_to_ranges(const std::vector< Uint31_Index >& arg) 3743524 q Ranges< Uint31_Index > result; 3767657 q result.push_back(i, inc(i)); 381Ranges< Uint31_Index > collect_way_req( 382 const std::vector< Uint31_Index >& parents, const std::vector< Uint31_Index >& children_idxs) 38428110477 q Ranges< Uint31_Index > req = calc_children_(parents); 38628110477 q for (std::vector< Uint31_Index >::const_iterator it = children_idxs.begin(); 3871779373477 q it != children_idxs.end(); ++it) 3881751263135 q req.push_back(*it, inc(*it)); 395template< typename Index, typename Skeleton > 396std::vector< Index > get_indexes( 397 Request_Context& context, const std::vector< typename Skeleton::Id_Type >& ids) 39911 q std::vector< Index > result; 40111 q Random_File< typename Skeleton::Id_Type, Index > current( 40211 q context.random_index(current_skeleton_file_properties< Skeleton >())); 40321 q for (auto it = ids.begin(); it != ids.end(); ++it) 40411 q result.push_back(current.get(it->val())); 40611 q if (context.get_desired_timestamp() != NOW) 40811 q Random_File< typename Skeleton::Id_Type, Index > attic_random( 40911 q context.random_index(attic_skeleton_file_properties< Skeleton >())); 41011 q std::vector< typename Skeleton::Id_Type > idx_list_ids; 41121 q for (auto it = ids.begin(); it != ids.end(); ++it) 41311 q if (attic_random.get(it->val()).val() == 0) 41511 q else if (attic_random.get(it->val()) == 0xff) 4160 idx_list_ids.push_back(it->val()); 41811 q result.push_back(attic_random.get(it->val())); 42111 q Block_Backend< typename Skeleton::Id_Type, Index > idx_list_db 42211 q (context.data_index(attic_idx_list_properties< Skeleton >())); 42311 q for (auto it = idx_list_db.discrete_begin(idx_list_ids.begin(), idx_list_ids.end()); 42411 q !(it == idx_list_db.discrete_end()); ++it) 4250 result.push_back(it.object()); 42811 q std::sort(result.begin(), result.end()); 42911 q result.erase(std::unique(result.begin(), result.end()), result.end()); 435Ranges< Uint31_Index > collect_relation_req( 436 Request_Context& context, const std::vector< Relation::Id_Type >& map_ids) 4383424 q std::vector< Uint31_Index > req; 4403424 q Random_File< Relation_Skeleton::Id_Type, Uint31_Index > random( 4413424 q context.random_index(osm_base_settings().RELATIONS)); 4423424 q for (std::vector< Relation::Id_Type >::const_iterator 443581724 q it(map_ids.begin()); it != map_ids.end(); ++it) 44457837 q req.push_back(random.get(it->val())); 4463424 q std::sort(req.begin(), req.end()); 4473424 q req.erase(unique(req.begin(), req.end()), req.end()); 4493424 q return uint31_to_ranges(req); 453Ranges< Uint31_Index > collect_attic_relation_req( 454 Request_Context& context, const std::vector< Relation::Id_Type >& map_ids) 45611 q std::vector< Uint31_Index > req = get_indexes< Uint31_Index, Relation_Skeleton >(context, map_ids); 45711 q return uint31_to_ranges(req); 461Ranges< Uint31_Index > relation_relation_member_indices 462 (Request_Context& context, 463 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& current_rels, 464 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels) 4663424 q std::vector< Relation::Id_Type > map_ids; 468308924 q for (auto it = current_rels.begin(); it != current_rels.end(); ++it) 469 // Treat relations with really large indices: get the node indexes from nodes.std::map. 470305517 q filter_for_member_ids(it->second, map_ids, Relation_Entry::RELATION); 4723424 q std::sort(map_ids.begin(), map_ids.end()); 4733424 q map_ids.erase(std::unique(map_ids.begin(), map_ids.end()), map_ids.end()); 4743424 q context.get_health_guard().check(); 4753424 q Ranges< Uint31_Index > current = collect_relation_req(context, map_ids); 4763424 q context.get_health_guard().check(); 47921924 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it) 480 // Treat relations with really large indices: get the node indexes from nodes.std::map. 4811855 q filter_for_member_ids(it->second, map_ids, Relation_Entry::RELATION); 4833424 q std::sort(map_ids.begin(), map_ids.end()); 4843424 q map_ids.erase(std::unique(map_ids.begin(), map_ids.end()), map_ids.end()); 48711 q context.get_health_guard().check(); 48811 q Ranges< Uint31_Index > attic = collect_attic_relation_req(context, map_ids); 48911 q return current.union_(attic); 495Ranges< Uint32_Index > way_nd_indices( 496 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways, 497 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways) 49925655114 q std::vector< uint32 > parents; 50161877114 q for (auto it = ways.begin(); it != ways.end(); ++it) 5033622267 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x1) == 0)) // Adapt 0x3 505 // Treat ways with really large indices: get the node indexes from the segment indexes 506148136 q for (std::vector< Way_Skeleton >::const_iterator it2 = it->second.begin(); 507452336 q it2 != it->second.end(); ++it2) 509304234 q for (std::vector< Quad_Coord >::const_iterator it3 = it2->geometry.begin(); 51031232634 q it3 != it2->geometry.end(); ++it3) 51130928434 q parents.push_back(it3->ll_upper); 5153474166 q parents.push_back(it->first.val()); 51730422114 q for (auto it = attic_ways.begin(); it != attic_ways.end(); ++it) 519476724 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x1) == 0)) // Adapt 0x3 521 // Treat ways with really large indices: get the node indexes from the segment indexes 52212915 q for (std::vector< Attic< Way_Skeleton > >::const_iterator it2 = it->second.begin(); 52332015 q it2 != it->second.end(); ++it2) 52519112 q for (std::vector< Quad_Coord >::const_iterator it3 = it2->geometry.begin(); 5261659312 q it3 != it2->geometry.end(); ++it3) 5271640212 q parents.push_back(it3->ll_upper); 531463824 q parents.push_back(it->first.val()); 53325655114 q std::sort(parents.begin(), parents.end()); 53425655114 q parents.erase(unique(parents.begin(), parents.end()), parents.end()); 53625655114 q return calc_node_children_ranges(parents); 540Ranges< Uint32_Index > way_covered_indices( 541 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways, 542 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways) 54426850 q std::vector< uint32 > parents; 54693750 q for (auto it = ways.begin(); it != ways.end(); ++it) 54766926 q parents.push_back(it->first.val()); 54832350 q for (auto it = attic_ways.begin(); it != attic_ways.end(); ++it) 549555 q parents.push_back(it->first.val()); 55126850 q std::sort(parents.begin(), parents.end()); 55226850 q parents.erase(unique(parents.begin(), parents.end()), parents.end()); 55426850 q return calc_node_children_ranges(parents); 558std::vector< Relation::Id_Type > relation_relation_member_ids( 559 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& rels, 560 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels, 561 const uint32* role_id) 5634428 q std::vector< Relation::Id_Type > ids; 56622 q for (auto it = rels.begin(); it != rels.end(); ++it) 5670 filter_for_member_ids(it->second, ids, Relation_Entry::RELATION, *role_id); 571311926 q for (auto it = rels.begin(); it != rels.end(); ++it) 572307717 q filter_for_member_ids(it->second, ids, Relation_Entry::RELATION); 57722 q for (auto it = rels.begin(); it != rels.end(); ++it) 5780 filter_for_member_ids(it->second, ids, Relation_Entry::RELATION, *role_id); 579962 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it) 580941 q filter_for_member_ids(it->second, ids, Relation_Entry::RELATION, *role_id); 584311926 q for (auto it = rels.begin(); it != rels.end(); ++it) 585307717 q filter_for_member_ids(it->second, ids, Relation_Entry::RELATION); 58613326 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it) 587914 q filter_for_member_ids(it->second, ids, Relation_Entry::RELATION); 5904428 q std::sort(ids.begin(), ids.end()); 596template< typename Id_Type > 598 std::vector< Id_Type >& working_ids, const std::vector< Id_Type >& extra_ids, bool invert_ids) 60081600496 q std::vector< Id_Type > copy_ids = working_ids; 60277 q working_ids.erase(std::set_intersection 60377 q (extra_ids.begin(), extra_ids.end(), copy_ids.begin(), copy_ids.end(), 60477 q working_ids.begin()), working_ids.end()); 60681593493 q working_ids.erase(std::set_difference 60781593493 q (copy_ids.begin(), copy_ids.end(), extra_ids.begin(), extra_ids.end(), 60881593493 q working_ids.begin()), working_ids.end()); 612Timeless< Uint31_Index, Relation_Skeleton > relation_relation_members 613 (Request_Context& context, 614 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& parents, 615 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_parents, 616 const Ranges< Uint31_Index >& children_ranges, 617 const std::vector< Relation::Id_Type >& children_ids, bool invert_ids, const uint32* role_id) 6193727 q std::vector< Relation::Id_Type > intersect_ids = relation_relation_member_ids(parents, attic_parents, role_id); 6203727 q context.get_health_guard().check(); 6213727 q sieve_first_arg(intersect_ids, children_ids, invert_ids); 6233727 q return collect_items_range< Uint31_Index, Relation_Skeleton >(context, 6243727 q children_ranges.is_global() 6253727 q ? relation_relation_member_indices(context, parents, attic_parents) : children_ranges, 6263727 q Id_Predicate< Relation_Skeleton >(intersect_ids)); 630Timeless< Uint31_Index, Way_Skeleton > relation_way_members 631 (Request_Context& context, 632 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& relations, 633 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_relations, 634 const Ranges< Uint31_Index >& way_ranges, 635 const std::vector< Way::Id_Type >& way_ids, bool invert_ids, const uint32* role_id) 63727958477 q std::vector< Way::Id_Type > intersect_ids = relation_way_member_ids(relations, attic_relations, role_id); 63827958477 q context.get_health_guard().check(); 63927958477 q sieve_first_arg(intersect_ids, way_ids, invert_ids); 64127958477 q return collect_items_range< Uint31_Index, Way_Skeleton >(context, way_ranges.intersect( 64227958477 q relation_way_member_indices(relations, attic_relations)), 64327958477 q Id_Predicate< Way_Skeleton >(intersect_ids)); 647std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > > relation_way_members 648 (Request_Context& context, 649 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& relations, 650 const Ranges< Uint31_Index >& way_ranges) 652147123 q std::vector< Way::Id_Type > intersect_ids = relation_way_member_ids({}, relations); 653147123 q context.get_health_guard().check(); 655147123 q auto timeless = collect_items_range< Uint31_Index, Way_Skeleton >(context, way_ranges.intersect( 656147123 q relation_way_member_indices({}, relations)), 657147123 q Id_Predicate< Way_Skeleton >(intersect_ids)); 659147123 q std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > > result; 660147123 q keep_matching_skeletons(result, timeless.current, timeless.attic, context.get_desired_timestamp()); 665Timeless< Uint32_Index, Node_Skeleton > paired_items_range( 666 Request_Context& context, 667 const std::vector< Node::Id_Type >& target_ids, const Ranges< Uint32_Index >& ranges) 66953605487 q auto result = collect_items_range< Uint32_Index, Node_Skeleton >( 67053605487 q context, ranges, Id_Predicate< Node_Skeleton >(target_ids)); 67153605487 q keep_matching_skeletons(result.current, result.attic, context.get_desired_timestamp()); 677Timeless< Uint32_Index, Node_Skeleton > relation_node_members 678 (Request_Context& context, 679 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& relations, 680 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_relations, 681 const Ranges< Uint32_Index >& node_ranges, 682 const std::vector< Node::Id_Type >& node_ids, bool invert_ids, const uint32* role_id) 68427950473 q std::vector< Node::Id_Type > intersect_ids = relation_node_member_ids(relations, attic_relations, role_id); 68527950473 q context.get_health_guard().check(); 68627950473 q sieve_first_arg(intersect_ids, node_ids, invert_ids); 68827950473 q return paired_items_range( 68927950473 q context, intersect_ids, node_ranges.intersect( 69027950473 q relation_node_member_indices(relations, attic_relations))); 694std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > > relation_node_members 695 (Request_Context& context, 696 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& relations, 697 const Ranges< Uint32_Index >& node_ranges) 699147123 q std::vector< Node::Id_Type > intersect_ids = relation_node_member_ids(relations, {}); 700147123 q context.get_health_guard().check(); 702 // Retrieve all nodes referred by the ways. 703147123 q auto timeless = collect_items_range< Uint32_Index, Node_Skeleton >( 704147123 q context, node_ranges, Id_Predicate< Node_Skeleton >(intersect_ids)); 706147123 q std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > > result; 707147123 q keep_matching_skeletons(result, timeless.current, timeless.attic, context.get_desired_timestamp()); 712Timeless< Uint32_Index, Node_Skeleton > way_members( 713 Request_Context& context, 714 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways, 715 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways, 716 const std::vector< int >* pos, 717 const Ranges< Uint32_Index >& node_ranges, 718 const std::vector< Node::Id_Type >& node_ids, bool invert_ids) 7202561083 q std::vector< Node::Id_Type > intersect_ids = way_nd_ids(ways, attic_ways, pos); 7212561083 q context.get_health_guard().check(); 7222561083 q sieve_first_arg(intersect_ids, node_ids, invert_ids); 7242561083 q return paired_items_range(context, intersect_ids, 7252561083 q !node_ranges.is_global() ? node_ranges : way_nd_indices(ways, attic_ways)); 729Timeless< Uint32_Index, Node_Skeleton > way_cnt_members( 730 Request_Context& context, 731 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways, 732 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways, 733 unsigned int lower_limit, unsigned int upper_limit, 734 const Ranges< Uint32_Index >& node_ranges, 735 const std::vector< Node::Id_Type >& node_ids, bool invert_ids) 7372520 q std::vector< Node::Id_Type > intersect_ids = way_cnt_nd_ids(ways, attic_ways, lower_limit, upper_limit); 7382520 q context.get_health_guard().check(); 7392520 q sieve_first_arg(intersect_ids, node_ids, invert_ids); 7412520 q return paired_items_range(context, intersect_ids, 7422520 q !node_ranges.is_global() ? node_ranges : way_nd_indices(ways, attic_ways)); 746Timeless< Uint32_Index, Node_Skeleton > way_link_members( 747 Request_Context& context, 748 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways, 749 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways, 750 unsigned int lower_limit, unsigned int upper_limit, 751 const Ranges< Uint32_Index >& node_ranges, 752 const std::vector< Node::Id_Type >& node_ids, bool invert_ids) 7542015 q std::vector< Node::Id_Type > intersect_ids = way_link_nd_ids(ways, attic_ways, lower_limit, upper_limit); 7552015 q context.get_health_guard().check(); 7562015 q sieve_first_arg(intersect_ids, node_ids, invert_ids); 7582015 q return paired_items_range(context, intersect_ids, 7592015 q !node_ranges.is_global() ? node_ranges : way_nd_indices(ways, attic_ways)); 762//----------------------------------------------------------------------------- 764const std::map< uint32, std::string >& relation_member_roles(Transaction& transaction) 76628542664 q static std::map< uint32, std::string > roles; 770664664 q Block_Backend< Uint32_Index, String_Object > roles_db 771664664 q (transaction.data_index(osm_base_settings().RELATION_ROLES)); 772664664 q for (Block_Backend< Uint32_Index, String_Object >::Flat_Iterator 773898392664 q it(roles_db.flat_begin()); !(it == roles_db.flat_end()); ++it) 774897728664 q roles[it.index().val()] = it.object().val(); 781uint32 determine_role_id(Transaction& transaction, const std::string& role) 7833424 q const std::map< uint32, std::string >& roles = relation_member_roles(transaction); 784524624 q for (std::map< uint32, std::string >::const_iterator it = roles.begin(); it != roles.end(); ++it) 786524624 q if (it->second == role) 7890 return std::numeric_limits< uint32 >::max(); 793//----------------------------------------------------------------------------- 796bool add_way_to_area_blocks(const std::vector< Quad_Coord >& coords, 797 uint32 id, std::map< Uint31_Index, std::vector< Area_Block > >& areas) 799104931465 q bool wraps_around_date_line = false; 801104931465 q if (coords.size() < 2) 805104925465 q std::vector< uint64 > cur_polyline; 8061155454165 q for (std::vector< Quad_Coord >::const_iterator it = coords.begin(); it != coords.end(); ++it) 8081050528765 q if ((it->ll_upper & 0xffffff00) != cur_idx) 8126166960 q if (cur_polyline.size() > 1) 8135125559 q areas[cur_idx].push_back(Area_Block(id, cur_polyline)); 8156166960 q std::vector< Aligned_Segment > aligned_segments; 8166166960 q wraps_around_date_line ^= Area::calc_aligned_segments 8176166960 q (aligned_segments, cur_polyline.back(), 8186166960 q ((uint64)it->ll_upper<<32) | it->ll_lower); 8206166960 q for (std::vector< Aligned_Segment >::const_iterator 82123575460 q it(aligned_segments.begin()); it != aligned_segments.end(); ++it) 82317408560 q cur_polyline.push_back((((uint64)it->ll_upper_)<<32) | it->ll_lower_a); 82417408560 q cur_polyline.push_back((((uint64)it->ll_upper_)<<32) | it->ll_lower_b); 82517408560 q areas[it->ll_upper_].push_back(Area_Block(id, cur_polyline)); 82617408560 q cur_polyline.clear(); 829111093565 q cur_idx = (it->ll_upper & 0xffffff00); 8311050528765 q cur_polyline.push_back(((uint64)it->ll_upper<<32) | it->ll_lower); 833104925465 q if ((cur_idx != 0) && (cur_polyline.size() > 1)) 834104301962 q areas[cur_idx].push_back(Area_Block(id, cur_polyline)); 836104925465 q return wraps_around_date_line; 840std::vector< Quad_Coord > make_geometry(const Way_Skeleton& way, const std::vector< Node >& nodes) 8427036703328 q std::vector< Quad_Coord > result; 8447036703328 q for (std::vector< Node::Id_Type >::const_iterator it3(way.nds.begin()); 84564387861328 q it3 != way.nds.end(); ++it3) 84757351662328 q const Node* node = binary_search_for_id(nodes, *it3); 85357351158328 q result.push_back(Quad_Coord(node->index, node->ll_lower_)); 860std::vector< Uint31_Index > segment_idxs(const std::vector< Quad_Coord >& geometry) 862215558223 q std::vector< uint32 > nd_idxs; 86424718761223 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it) 86524503203223 q nd_idxs.push_back(it->ll_upper); 867215558223 q return calc_segment_idxs(nd_idxs); 871template< typename Object > 872void filter_ways_by_ranges_generic 873 (std::map< Uint31_Index, std::vector< Object > >& ways, 874 const Ranges< Uint31_Index >& ranges) 8761051376 q auto ranges_it = ranges.begin(); 8771051376 q typename std::map< Uint31_Index, std::vector< Object > >::iterator it = ways.begin(); 8781051376 q auto ranges_begin = ranges.begin(); 879238172376 q for (; it != ways.end() && ranges_it != ranges.end(); ) 881237121244 q if (!(it->first < ranges_it.upper_bound())) 883189830243 q else if (!(it->first < ranges_it.lower_bound())) 885189830243 q if ((it->first.val() & 0x80000000) == 0 || (it->first.val() & 0x1) != 0) // Adapt 0x3 88912152233 q std::vector< Object > filtered_ways; 89054576233 q while (!(Uint31_Index(it->first.val() & 0x7fffff00) < ranges_begin.upper_bound())) 89212152233 q for (typename std::vector< Object >::const_iterator it2 = it->second.begin(); 893227710233 q it2 != it->second.end(); ++it2) 895215558223 q auto ranges_it2 = ranges_begin; 896215558223 q std::vector< Uint31_Index > segment_idxs_ = segment_idxs(it2->geometry); 897215558223 q for (std::vector< Uint31_Index >::const_iterator it3 = segment_idxs_.begin(); 8981894447223 q it3 != segment_idxs_.end() && ranges_it2 != ranges.end(); ) 9001844597223 q if (!(*it3 < ranges_it2.upper_bound())) 902985980223 q else if (!(*it3 < ranges_it2.lower_bound())) 904 // A relevant index is found; thus the way is relevant. 905165708219 q filtered_ways.push_back(*it2); 91312152233 q filtered_ways.swap(it->second); 919 // The index of the way is not in the current set of ranges. 920 // Thus it cannot be in the result set. 9251188376 q for (; it != ways.end(); ++it) 930void filter_ways_by_ranges(std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways, 931 const Ranges< Uint31_Index >& ranges) 933568376 q filter_ways_by_ranges_generic(ways, ranges); 937void filter_ways_by_ranges(std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& ways, 938 const Ranges< Uint31_Index >& ranges) 940483326 q filter_ways_by_ranges_generic(ways, ranges); 944void keep_matching_skeletons 945 (std::vector< Node >& result, 946 const std::map< Uint32_Index, std::vector< Node_Skeleton > >& current, 947 const std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >& attic, 9502036262 q std::map< Node_Skeleton::Id_Type, uint64 > timestamp_by_id; 9542036262 q for (std::map< Uint32_Index, std::vector< Node_Skeleton > >::const_iterator it = current.begin(); 95587289262 q it != current.end(); ++it) 9571953334126 q for (std::vector< Node_Skeleton >::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) 9581868081124 q timestamp_by_id[it2->id] = NOW; 9612036262 q for (std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >::const_iterator it = attic.begin(); 96485253126 q for (std::vector< Attic<Node_Skeleton > >::const_iterator it2 = it->second.begin(); 9651381077126 q it2 != it->second.end(); ++it2) 9671295824126 q uint64& stored_timestamp = timestamp_by_id[it2->id]; 9681295824126 q if (it2->timestamp > timestamp && (stored_timestamp == 0 || stored_timestamp > it2->timestamp)) 9691291516126 q stored_timestamp = it2->timestamp; 9732036262 q for (std::map< Uint32_Index, std::vector< Node_Skeleton > >::const_iterator it = current.begin(); 97487289262 q it != current.end(); ++it) 9761953334126 q for (std::vector< Node_Skeleton >::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) 9781868081124 q if (timestamp_by_id[it2->id] == NOW) 9791854043123 q result.push_back(Node(it2->id, it->first.val(), it2->ll_lower)); 9832036262 q for (std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >::const_iterator it = attic.begin(); 98685253126 q for (std::vector< Attic<Node_Skeleton > >::const_iterator it2 = it->second.begin(); 9871381077126 q it2 != it->second.end(); ++it2) 9891295824126 q if (timestamp_by_id[it2->id] == it2->timestamp) 9901286433126 q result.push_back(Node(it2->id, it->first.val(), it2->ll_lower)); 9942036262 q std::sort(result.begin(), result.end(), Node_Comparator_By_Id()); 998Timeless< Uint31_Index, Way_Skeleton > collect_ways( 999 Request_Context& context, 1000 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& rels, 1001 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels, 1002 const Ranges< Uint31_Index >& ranges, 1003 const std::vector< Way::Id_Type >& ids, bool invert_ids, 100655 q return relation_way_members(context, rels, attic_rels, ranges, ids, invert_ids, role_id); 1010Timeless< Uint31_Index, Way_Skeleton > collect_ways( 1011 Request_Context& context, 1012 const std::map< Uint32_Index, std::vector< Node_Skeleton > >& nodes, 1013 const std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >& attic_nodes, 1014 const std::vector< int >* pos, 1015 const std::vector< Way::Id_Type >& ids, bool invert_ids) 101715179 q Timeless< Uint31_Index, Way_Skeleton > result; 101815179 q std::vector< Uint64 > children_ids; 101915179 q std::set< Uint31_Index > req; 102115179 q if (context.get_desired_timestamp() == NOW) 102310847 q extract_ids(nodes).swap(children_ids); 102410847 q extract_parent_indices(nodes).swap(req); 10284338 q std::vector< Uint64 > current_ids = extract_ids(nodes); 10294338 q extract_parent_indices(nodes).swap(req); 10314338 q std::vector< Uint64 > attic_ids = extract_ids(attic_nodes); 10324338 q std::set< Uint31_Index > attic_req = extract_parent_indices(attic_nodes); 10344338 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(), 10354338 q std::back_inserter(children_ids)); 1036456438 q for (std::set< Uint31_Index >::const_iterator it = attic_req.begin(); it != attic_req.end(); ++it) 104155 q collect_items_discrete(context, req, 104255 q And_Predicate< Way_Skeleton, 104355 q Id_Predicate< Way_Skeleton >, Get_Parent_Ways_Predicate > 104455 q (Id_Predicate< Way_Skeleton >(ids), Get_Parent_Ways_Predicate(children_ids, pos)), 104555 q result.current, result.attic); 104714674 q collect_items_discrete(context, req, 104814674 q Get_Parent_Ways_Predicate(children_ids, pos), result.current, result.attic); 10500 collect_items_discrete(context, req, 10510 And_Predicate< Way_Skeleton, 10520 Not_Predicate< Way_Skeleton, Id_Predicate< Way_Skeleton > >, 10530 Get_Parent_Ways_Predicate > 10540 (Not_Predicate< Way_Skeleton, Id_Predicate< Way_Skeleton > > 10550 (Id_Predicate< Way_Skeleton >(ids)), 10560 Get_Parent_Ways_Predicate(children_ids, pos)), 10570 result.current, result.attic); 1063void add_nw_member_objects(Request_Context& context, const Set& input_set, Set& into, 1064 const Ranges< Uint32_Index >* ranges_32_, const Ranges< Uint31_Index >* ranges_31_) 10662556045 q Ranges< Uint32_Index > ranges_32(ranges_32_ ? *ranges_32_ : Ranges< Uint32_Index >::global()); 10672556045 q Ranges< Uint31_Index > ranges_31(ranges_31_ ? *ranges_31_ : Ranges< Uint31_Index >::global()); 10682556045 q Timeless< Uint32_Index, Node_Skeleton > rel_nodes 10692556045 q = relation_node_members(context, input_set.relations, input_set.attic_relations, ranges_32, {}, true); 10712556045 q if (context.get_desired_timestamp() == NOW) 10735226 q relation_way_members(context, input_set.relations, {}, ranges_31, {}, true) 10745226 q .swap(into.ways, into.attic_ways); 10755226 q std::map< Uint31_Index, std::vector< Way_Skeleton > > source_ways = input_set.ways; 10785226 q indexed_set_union(source_ways, into.ways); 10795226 q way_members(context, source_ways, {}, 0, Ranges< Uint32_Index >::global(), {}, true) 10805226 q .swap(into.nodes, into.attic_nodes); 10825226 q sort_second(rel_nodes.current); 10835226 q indexed_set_union(into.nodes, rel_nodes.current); 10872550820 q rel_nodes.swap(into.nodes, into.attic_nodes); 10892550820 q Timeless< Uint31_Index, Way_Skeleton > all_ways 10902550820 q = relation_way_members(context, input_set.relations, input_set.attic_relations, ranges_31, {}, true); 10912550820 q into.ways = all_ways.current; 10922550820 q into.attic_ways = all_ways.attic; 10952550820 q std::map< Uint31_Index, std::vector< Way_Skeleton > > source_ways = input_set.ways; 10962550820 q std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > > source_attic_ways = input_set.attic_ways; 10982550820 q sort_second(source_attic_ways); 10992550820 q indexed_set_union(all_ways.current, source_ways); 11002550820 q indexed_set_union(all_ways.attic, source_attic_ways); 11022550820 q Timeless< Uint32_Index, Node_Skeleton > more_nodes 11032550820 q = way_members(context, all_ways.current, all_ways.attic, 0, Ranges< Uint32_Index >::global(), {}, true); 11062550820 q sort_second(into.attic_nodes); 11072550820 q indexed_set_union(into.nodes, more_nodes.current); 11082550820 q indexed_set_union(into.attic_nodes, more_nodes.attic); 11092550820 q keep_matching_skeletons(into.nodes, into.attic_nodes, context.get_desired_timestamp());