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) 3196 q for (const auto& i : ways) 332793 q for (const auto& j : i.second) 359633 q auto it3 = pos.begin(); 3619243 q while (it3 != pos.end() && *it3 < 0) 389612 q if (*it3 + (int)j.nds.size() >= 0) 399612 q ids.push_back(j.nds[*it3 + j.nds.size()]); 429633 q while (it3 != pos.end() && *it3 == 0) 4416333 q while(it3 != pos.end()) 466702 q if (*it3 < (int)j.nds.size()+1) 476702 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) 58248073 q for (const auto& i : ways) 6020356650 q for (const auto& j : i.second) 6248027450 q for (auto k : j.nds) 631614576550 q ids.push_back(k); 69template< typename Container > 70void way_nd_ids_once(const Container& ways, std::vector< Node::Id_Type >& ids) 725128 q for (const auto& i : ways) 741091119 q for (const auto& j : i.second) 764581119 q auto size = ids.size(); 774581119 q for (auto k : j.nds) 7855588119 q ids.push_back(k); 794581119 q std::sort(ids.begin()+size, ids.end()); 804581119 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) 892718 q for (const auto& i : ways) 917486511 q for (const auto& j : i.second) 9316478311 q if (j.nds.empty()) 9516478311 q ids.push_back(j.nds.front()); 9616478311 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) 107243763 q std::vector< Node::Id_Type > ids; 10996 q way_nd_ids_pos(ways, *pos, ids); 111242860 q way_nd_ids_plain(ways, ids); 113243763 q if (!attic_ways.empty()) 1160 way_nd_ids_pos(attic_ways, *pos, ids); 1182511 q way_nd_ids_plain(attic_ways, ids); 121243763 q std::sort(ids.begin(), ids.end()); 122243763 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) 1333928 q std::vector< Node::Id_Type > ids; 1343928 q way_nd_ids_once(ways, ids); 1361210 q way_nd_ids_once(attic_ways, ids); 1383928 q std::sort(ids.begin(), ids.end()); 1403928 q decltype(ids.size()) lower = 0; 1413928 q decltype(ids.size()) upper = 0; 1423928 q decltype(ids.size()) target = 0; 14350122628 q while (lower < ids.size()) 145104601519 q while (upper < ids.size() && ids[lower] == ids[upper]) 14750118719 q if (lower_limit <= upper - lower && upper - lower <= upper_limit) 14840238517 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) 1622118 q std::vector< Node::Id_Type > ids; 1632118 q way_nd_ids_plain(ways, ids); 16565 q way_nd_ids_plain(attic_ways, ids); 1672118 q std::sort(ids.begin(), ids.end()); 1692118 q std::vector< Node::Id_Type > fl_ids; 1702118 q way_nd_firstlast(ways, fl_ids); 17265 q way_nd_firstlast(attic_ways, fl_ids); 1742118 q std::sort(fl_ids.begin(), fl_ids.end()); 1762118 q decltype(ids.size()) lower = 0; 1772118 q decltype(ids.size()) upper = 0; 1782118 q decltype(fl_ids.size()) fl_lower = 0; 1792118 q decltype(fl_ids.size()) fl_upper = 0; 1802118 q decltype(ids.size()) target = 0; 181496592418 q while (lower < ids.size()) 1831042895511 q while (upper < ids.size() && ids[lower] == ids[upper]) 185496590311 q while (fl_lower < fl_ids.size() && fl_ids[fl_lower] < ids[lower]) 187496590311 q fl_upper = fl_lower; 188529546911 q while (fl_upper < fl_ids.size() && fl_ids[fl_upper] == ids[lower]) 190496590311 q if (lower_limit <= 2*(upper - lower) + fl_lower - fl_upper 191496590311 q && 2*(upper - lower) + fl_lower - fl_upper <= upper_limit) 19233747611 q ids[target++] = ids[lower]; 194496590311 q fl_lower = fl_upper; 202Ranges< Uint32_Index > calc_node_children_ranges(const std::vector< uint32 >& way_rel_idxs) 20412627442 q Ranges< Uint32_Index > result; 20612627442 q for (std::vector< uint32 >::const_iterator it = way_rel_idxs.begin(); 2071030770442 q it != way_rel_idxs.end(); ++it) 219311719311 q lat = upper_ilat(*it & 0x2aaaaaa8); 220311719311 q lon = upper_ilon(*it & 0x55555554); 22323119167 q else if (*it & 0x00000002) 22523046166 q lat = upper_ilat(*it & 0x2aaaaa80); 22623046166 q lon = upper_ilon(*it & 0x55555540); 229739 q else if (*it & 0x00000004) 231539 q lat = upper_ilat(*it & 0x2aaaa800); 232539 q lon = upper_ilon(*it & 0x55555400); 235202 q else if (*it & 0x00000008) 237102 q lat = upper_ilat(*it & 0x2aaa8000); 238102 q lon = upper_ilon(*it & 0x55554000); 241102 q else if (*it & 0x00000010) 243102 q lat = upper_ilat(*it & 0x2aa80000); 244102 q lon = upper_ilon(*it & 0x55540000); 2470 else if (*it & 0x00000020) 2490 lat = upper_ilat(*it & 0x2a800000); 2500 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 266334838314 q result.push_back(ll_upper(lat<<16, lon<<16), ll_upper((lat+offset-1)<<16, (lon+offset-1)<<16)+1); 267334838314 q result.push_back(ll_upper(lat<<16, (lon+offset)<<16), ll_upper((lat+offset-1)<<16, (lon+2*offset-1)<<16)+1); 268334838314 q result.push_back(ll_upper((lat+offset)<<16, lon<<16), ll_upper((lat+2*offset-1)<<16, (lon+offset-1)<<16)+1); 270334838314 q ll_upper((lat+offset)<<16, (lon+offset)<<16), ll_upper((lat+2*offset-1)<<16, (lon+2*offset-1)<<16)+1); 271334838314 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); 278683305325 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) 2904576416 q std::vector< uint32 > parents; 29274510416 q for (auto it = current_rels.begin(); it != current_rels.end(); ++it) 29469934187 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 29749253176 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) 29943464155 q for (std::vector< Uint31_Index >::const_iterator it3 = it2->node_idxs.begin(); 30084257155 q it3 != it2->node_idxs.end(); ++it3) 30140793136 q parents.push_back(it3->val()); 30564145168 q parents.push_back(it->first.val()); 30745230416 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it) 3094065445 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 312333741 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) 31438423 q for (std::vector< Uint31_Index >::const_iterator it3 = it2->node_idxs.begin(); 315108423 q it3 != it2->node_idxs.end(); ++it3) 3167009 q parents.push_back(it3->val()); 3203770138 q parents.push_back(it->first.val()); 3234576416 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) 3314709420 q std::vector< Uint31_Index > parents; 3324709420 q std::vector< Uint31_Index > children_idxs; 33489409420 q for (auto it = current_rels.begin(); it != current_rels.end(); ++it) 33684700188 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0)) 338 // Treat relations with really large indices: get the ways indexes explicitly 33957162178 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) 34150860157 q for (std::vector< Uint31_Index >::const_iterator it3 = it2->way_idxs.begin(); 3422747443157 q it3 != it2->way_idxs.end(); ++it3) 3432696583157 q children_idxs.push_back(*it3); 34778398169 q parents.push_back(it->first); 34948622420 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it) 3514391376 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0)) 353 // Treat relations with really large indices: get the ways indexes explicitly 3541006672 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) 356600659 q for (std::vector< Uint31_Index >::const_iterator it3 = it2->way_idxs.begin(); 35746380259 q it3 != it2->way_idxs.end(); ++it3) 35845779659 q children_idxs.push_back(*it3); 3623985364 q parents.push_back(it->first); 3654709420 q std::sort(children_idxs.begin(), children_idxs.end()); 3664709420 q children_idxs.erase(std::unique(children_idxs.begin(), children_idxs.end()), children_idxs.end()); 3684709420 q return collect_way_req(parents, children_idxs); 372Ranges< Uint31_Index > uint31_to_ranges(const std::vector< Uint31_Index >& arg) 3743021 q Ranges< Uint31_Index > result; 37616347 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) 3844709420 q Ranges< Uint31_Index > req = calc_children_(parents); 3864709420 q for (std::vector< Uint31_Index >::const_iterator it = children_idxs.begin(); 3871201303420 q it != children_idxs.end(); ++it) 3881196594173 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) 39931 q std::vector< Index > result; 40131 q Random_File< typename Skeleton::Id_Type, Index > current( 40231 q context.random_index(current_skeleton_file_properties< Skeleton >())); 4031311 q for (auto it = ids.begin(); it != ids.end(); ++it) 4041281 q result.push_back(current.get(it->val())); 40631 q if (context.get_desired_timestamp() != NOW) 40831 q Random_File< typename Skeleton::Id_Type, Index > attic_random( 40931 q context.random_index(attic_skeleton_file_properties< Skeleton >())); 41031 q std::vector< typename Skeleton::Id_Type > idx_list_ids; 4111311 q for (auto it = ids.begin(); it != ids.end(); ++it) 4131281 q if (attic_random.get(it->val()).val() == 0) 4151281 q else if (attic_random.get(it->val()) == 0xff) 416931 q idx_list_ids.push_back(it->val()); 418351 q result.push_back(attic_random.get(it->val())); 42131 q Block_Backend< typename Skeleton::Id_Type, Index > idx_list_db 42231 q (context.data_index(attic_idx_list_properties< Skeleton >())); 42331 q for (auto it = idx_list_db.discrete_begin(idx_list_ids.begin(), idx_list_ids.end()); 4242301 q !(it == idx_list_db.discrete_end()); ++it) 4252271 q result.push_back(it.object()); 42831 q std::sort(result.begin(), result.end()); 42931 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) 4382721 q std::vector< Uint31_Index > req; 4402721 q Random_File< Relation_Skeleton::Id_Type, Uint31_Index > random( 4412721 q context.random_index(osm_base_settings().RELATIONS)); 4422721 q for (std::vector< Relation::Id_Type >::const_iterator 443820121 q it(map_ids.begin()); it != map_ids.end(); ++it) 44481746 q req.push_back(random.get(it->val())); 4462721 q std::sort(req.begin(), req.end()); 4472721 q req.erase(unique(req.begin(), req.end()), req.end()); 4492721 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) 45631 q std::vector< Uint31_Index > req = get_indexes< Uint31_Index, Relation_Skeleton >(context, map_ids); 45731 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) 4662721 q std::vector< Relation::Id_Type > map_ids; 4681520521 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. 4701517814 q filter_for_member_ids(it->second, map_ids, Relation_Entry::RELATION); 4722721 q std::sort(map_ids.begin(), map_ids.end()); 4732721 q map_ids.erase(std::unique(map_ids.begin(), map_ids.end()), map_ids.end()); 4742721 q context.get_health_guard().check(); 4752721 q Ranges< Uint31_Index > current = collect_relation_req(context, map_ids); 4762721 q context.get_health_guard().check(); 47941721 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. 4813906 q filter_for_member_ids(it->second, map_ids, Relation_Entry::RELATION); 4832721 q std::sort(map_ids.begin(), map_ids.end()); 4842721 q map_ids.erase(std::unique(map_ids.begin(), map_ids.end()), map_ids.end()); 48731 q context.get_health_guard().check(); 48831 q Ranges< Uint31_Index > attic = collect_attic_relation_req(context, map_ids); 48931 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) 4992492101 q std::vector< uint32 > parents; 501215779101 q for (auto it = ways.begin(); it != ways.end(); ++it) 50321328766 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 5061108546 q for (std::vector< Way_Skeleton >::const_iterator it2 = it->second.begin(); 5075057946 q it2 != it->second.end(); ++it2) 5093949445 q for (std::vector< Quad_Coord >::const_iterator it3 = it2->geometry.begin(); 510784560245 q it3 != it2->geometry.end(); ++it3) 511780610845 q parents.push_back(it3->ll_upper); 51520220264 q parents.push_back(it->first.val()); 5173447101 q for (auto it = attic_ways.begin(); it != attic_ways.end(); ++it) 51995523 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 52222317 q for (std::vector< Attic< Way_Skeleton > >::const_iterator it2 = it->second.begin(); 52356917 q it2 != it->second.end(); ++it2) 52534617 q for (std::vector< Quad_Coord >::const_iterator it3 = it2->geometry.begin(); 5267585017 q it3 != it2->geometry.end(); ++it3) 5277550417 q parents.push_back(it3->ll_upper); 53173223 q parents.push_back(it->first.val()); 5332492101 q std::sort(parents.begin(), parents.end()); 5342492101 q parents.erase(unique(parents.begin(), parents.end()), parents.end()); 5362492101 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) 54424645 q std::vector< uint32 > parents; 54696045 q for (auto it = ways.begin(); it != ways.end(); ++it) 54771422 q parents.push_back(it->first.val()); 54839045 q for (auto it = attic_ways.begin(); it != attic_ways.end(); ++it) 54914410 q parents.push_back(it->first.val()); 55124645 q std::sort(parents.begin(), parents.end()); 55224645 q parents.erase(unique(parents.begin(), parents.end()), parents.end()); 55424645 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) 5633825 q std::vector< Relation::Id_Type > ids; 56673 q for (auto it = rels.begin(); it != rels.end(); ++it) 56741 q filter_for_member_ids(it->second, ids, Relation_Entry::RELATION, *role_id); 5711521822 q for (auto it = rels.begin(); it != rels.end(); ++it) 5721518313 q filter_for_member_ids(it->second, ids, Relation_Entry::RELATION); 57773 q for (auto it = rels.begin(); it != rels.end(); ++it) 57841 q filter_for_member_ids(it->second, ids, Relation_Entry::RELATION, *role_id); 579263 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it) 580231 q filter_for_member_ids(it->second, ids, Relation_Entry::RELATION, *role_id); 5841521822 q for (auto it = rels.begin(); it != rels.end(); ++it) 5851518313 q filter_for_member_ids(it->second, ids, Relation_Entry::RELATION); 58640222 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it) 5873675 q filter_for_member_ids(it->second, ids, Relation_Entry::RELATION); 5903825 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) 60011649437 q std::vector< Id_Type > copy_ids = working_ids; 60255 q working_ids.erase(std::set_intersection 60355 q (extra_ids.begin(), extra_ids.end(), copy_ids.begin(), copy_ids.end(), 60455 q working_ids.begin()), working_ids.end()); 60611644436 q working_ids.erase(std::set_difference 60711644436 q (copy_ids.begin(), copy_ids.end(), extra_ids.begin(), extra_ids.end(), 60811644436 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) 6193024 q std::vector< Relation::Id_Type > intersect_ids = relation_relation_member_ids(parents, attic_parents, role_id); 6203024 q context.get_health_guard().check(); 6213024 q sieve_first_arg(intersect_ids, children_ids, invert_ids); 6233024 q return collect_items_range< Uint31_Index, Relation_Skeleton >(context, 6243024 q children_ranges.is_global() 6253024 q ? relation_relation_member_indices(context, parents, attic_parents) : children_ranges, 6263024 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) 6374569420 q std::vector< Way::Id_Type > intersect_ids = relation_way_member_ids(relations, attic_relations, role_id); 6384569420 q context.get_health_guard().check(); 6394569420 q sieve_first_arg(intersect_ids, way_ids, invert_ids); 6414569420 q return collect_items_range< Uint31_Index, Way_Skeleton >(context, way_ranges.intersect( 6424569420 q relation_way_member_indices(relations, attic_relations)), 6434569420 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) 652135110 q std::vector< Way::Id_Type > intersect_ids = relation_way_member_ids({}, relations); 653135110 q context.get_health_guard().check(); 655135110 q auto timeless = collect_items_range< Uint31_Index, Way_Skeleton >(context, way_ranges.intersect( 656135110 q relation_way_member_indices({}, relations)), 657135110 q Id_Predicate< Way_Skeleton >(intersect_ids)); 659135110 q std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > > result; 660135110 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) 6697050429 q auto result = collect_items_range< Uint32_Index, Node_Skeleton >( 6707050429 q context, ranges, Id_Predicate< Node_Skeleton >(target_ids)); 6717050429 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) 6844558416 q std::vector< Node::Id_Type > intersect_ids = relation_node_member_ids(relations, attic_relations, role_id); 6854558416 q context.get_health_guard().check(); 6864558416 q sieve_first_arg(intersect_ids, node_ids, invert_ids); 6894558416 q context, intersect_ids, node_ranges.intersect( 6904558416 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) 699135110 q std::vector< Node::Id_Type > intersect_ids = relation_node_member_ids(relations, {}); 700135110 q context.get_health_guard().check(); 702 // Retrieve all nodes referred by the ways. 703135110 q auto timeless = collect_items_range< Uint32_Index, Node_Skeleton >( 704135110 q context, node_ranges, Id_Predicate< Node_Skeleton >(intersect_ids)); 706135110 q std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > > result; 707135110 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) 720243263 q std::vector< Node::Id_Type > intersect_ids = way_nd_ids(ways, attic_ways, pos); 721243263 q context.get_health_guard().check(); 722243263 q sieve_first_arg(intersect_ids, node_ids, invert_ids); 724243263 q return paired_items_range(context, intersect_ids, 725243263 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) 7373928 q std::vector< Node::Id_Type > intersect_ids = way_cnt_nd_ids(ways, attic_ways, lower_limit, upper_limit); 7383928 q context.get_health_guard().check(); 7393928 q sieve_first_arg(intersect_ids, node_ids, invert_ids); 7413928 q return paired_items_range(context, intersect_ids, 7423928 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) 7542118 q std::vector< Node::Id_Type > intersect_ids = way_link_nd_ids(ways, attic_ways, lower_limit, upper_limit); 7552118 q context.get_health_guard().check(); 7562118 q sieve_first_arg(intersect_ids, node_ids, invert_ids); 7582118 q return paired_items_range(context, intersect_ids, 7592118 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) 7668960585 q static std::map< uint32, std::string > roles; 770585585 q Block_Backend< Uint32_Index, String_Object > roles_db 771585585 q (transaction.data_index(osm_base_settings().RELATION_ROLES)); 772585585 q for (Block_Backend< Uint32_Index, String_Object >::Flat_Iterator 773204165585 q it(roles_db.flat_begin()); !(it == roles_db.flat_end()); ++it) 774203580585 q roles[it.index().val()] = it.object().val(); 781uint32 determine_role_id(Transaction& transaction, const std::string& role) 7833121 q const std::map< uint32, std::string >& roles = relation_member_roles(transaction); 784261121 q for (std::map< uint32, std::string >::const_iterator it = roles.begin(); it != roles.end(); ++it) 786261121 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) 79939426076 q bool wraps_around_date_line = false; 80139426076 q if (coords.size() < 2) 80539421976 q std::vector< uint64 > cur_polyline; 8061001747076 q for (std::vector< Quad_Coord >::const_iterator it = coords.begin(); it != coords.end(); ++it) 808962325176 q if ((it->ll_upper & 0xffffff00) != cur_idx) 8127674371 q if (cur_polyline.size() > 1) 8136653171 q areas[cur_idx].push_back(Area_Block(id, cur_polyline)); 8157674371 q std::vector< Aligned_Segment > aligned_segments; 8167674371 q wraps_around_date_line ^= Area::calc_aligned_segments 8177674371 q (aligned_segments, cur_polyline.back(), 8187674371 q ((uint64)it->ll_upper<<32) | it->ll_lower); 8207674371 q for (std::vector< Aligned_Segment >::const_iterator 82133015571 q it(aligned_segments.begin()); it != aligned_segments.end(); ++it) 82325341271 q cur_polyline.push_back((((uint64)it->ll_upper_)<<32) | it->ll_lower_a); 82425341271 q cur_polyline.push_back((((uint64)it->ll_upper_)<<32) | it->ll_lower_b); 82525341271 q areas[it->ll_upper_].push_back(Area_Block(id, cur_polyline)); 82625341271 q cur_polyline.clear(); 82947099676 q cur_idx = (it->ll_upper & 0xffffff00); 831962325176 q cur_polyline.push_back(((uint64)it->ll_upper<<32) | it->ll_lower); 83339421976 q if ((cur_idx != 0) && (cur_polyline.size() > 1)) 83438957076 q areas[cur_idx].push_back(Area_Block(id, cur_polyline)); 83639421976 q return wraps_around_date_line; 840std::vector< Quad_Coord > make_geometry(const Way_Skeleton& way, const std::vector< Node >& nodes) 8422037836301 q std::vector< Quad_Coord > result; 8442037836301 q for (std::vector< Node::Id_Type >::const_iterator it3(way.nds.begin()); 84527213552301 q it3 != way.nds.end(); ++it3) 84725175812301 q const Node* node = binary_search_for_id(nodes, *it3); 85325175716301 q result.push_back(Quad_Coord(node->index, node->ll_lower_)); 860std::vector< Uint31_Index > segment_idxs(const std::vector< Quad_Coord >& geometry) 862111612215 q std::vector< uint32 > nd_idxs; 86422672167215 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it) 86522560555215 q nd_idxs.push_back(it->ll_upper); 867111612215 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) 876897328 q auto ranges_it = ranges.begin(); 877897328 q typename std::map< Uint31_Index, std::vector< Object > >::iterator it = ways.begin(); 878897328 q auto ranges_begin = ranges.begin(); 879141661328 q for (; it != ways.end() && ranges_it != ranges.end(); ) 881140764231 q if (!(it->first < ranges_it.upper_bound())) 88399947229 q else if (!(it->first < ranges_it.lower_bound())) 88599940228 q if ((it->first.val() & 0x80000000) == 0 || (it->first.val() & 0x1) != 0) // Adapt 0x3 88910854223 q std::vector< Object > filtered_ways; 89044132223 q while (!(Uint31_Index(it->first.val() & 0x7fffff00) < ranges_begin.upper_bound())) 89210854223 q for (typename std::vector< Object >::const_iterator it2 = it->second.begin(); 893122466223 q it2 != it->second.end(); ++it2) 895111612215 q auto ranges_it2 = ranges_begin; 896111612215 q std::vector< Uint31_Index > segment_idxs_ = segment_idxs(it2->geometry); 897111612215 q for (std::vector< Uint31_Index >::const_iterator it3 = segment_idxs_.begin(); 8981767305215 q it3 != segment_idxs_.end() && ranges_it2 != ranges.end(); ) 9001725650215 q if (!(*it3 < ranges_it2.upper_bound())) 902883803214 q else if (!(*it3 < ranges_it2.lower_bound())) 904 // A relevant index is found; thus the way is relevant. 90569957212 q filtered_ways.push_back(*it2); 91310854223 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. 9251760328 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) 933488328 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) 940409276 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, 9501793232 q std::map< Node_Skeleton::Id_Type, uint64 > timestamp_by_id; 9541793232 q for (std::map< Uint32_Index, std::vector< Node_Skeleton > >::const_iterator it = current.begin(); 955186590232 q it != current.end(); ++it) 9571404338111 q for (std::vector< Node_Skeleton >::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) 9581219541108 q timestamp_by_id[it2->id] = NOW; 9611793232 q for (std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >::const_iterator it = attic.begin(); 964184797111 q for (std::vector< Attic<Node_Skeleton > >::const_iterator it2 = it->second.begin(); 965662667111 q it2 != it->second.end(); ++it2) 967477870106 q uint64& stored_timestamp = timestamp_by_id[it2->id]; 968477870106 q if (it2->timestamp > timestamp && (stored_timestamp == 0 || stored_timestamp > it2->timestamp)) 969476671106 q stored_timestamp = it2->timestamp; 9731793232 q for (std::map< Uint32_Index, std::vector< Node_Skeleton > >::const_iterator it = current.begin(); 974186590232 q it != current.end(); ++it) 9761404338111 q for (std::vector< Node_Skeleton >::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) 9781219541108 q if (timestamp_by_id[it2->id] == NOW) 9791211205107 q result.push_back(Node(it2->id, it->first.val(), it2->ll_lower)); 9831793232 q for (std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >::const_iterator it = attic.begin(); 986184797111 q for (std::vector< Attic<Node_Skeleton > >::const_iterator it2 = it->second.begin(); 987662667111 q it2 != it->second.end(); ++it2) 989477870106 q if (timestamp_by_id[it2->id] == it2->timestamp) 990475496106 q result.push_back(Node(it2->id, it->first.val(), it2->ll_lower)); 9941793232 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, 100654 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) 101714589 q Timeless< Uint31_Index, Way_Skeleton > result; 101814589 q std::vector< Uint64 > children_ids; 101914589 q std::set< Uint31_Index > req; 102114589 q if (context.get_desired_timestamp() == NOW) 102310665 q extract_ids(nodes).swap(children_ids); 102410665 q extract_parent_indices(nodes).swap(req); 10283936 q std::vector< Uint64 > current_ids = extract_ids(nodes); 10293936 q extract_parent_indices(nodes).swap(req); 10313936 q std::vector< Uint64 > attic_ids = extract_ids(attic_nodes); 10323936 q std::set< Uint31_Index > attic_req = extract_parent_indices(attic_nodes); 10343936 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(), 10353936 q std::back_inserter(children_ids)); 1036355236 q for (std::set< Uint31_Index >::const_iterator it = attic_req.begin(); it != attic_req.end(); ++it) 104165 q collect_items_discrete(context, req, 104265 q And_Predicate< Way_Skeleton, 104365 q Id_Predicate< Way_Skeleton >, Get_Parent_Ways_Predicate > 104465 q (Id_Predicate< Way_Skeleton >(ids), Get_Parent_Ways_Predicate(children_ids, pos)), 104565 q result.current, result.attic); 104713984 q collect_items_discrete(context, req, 104813984 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_) 1066239433 q Ranges< Uint32_Index > ranges_32(ranges_32_ ? *ranges_32_ : Ranges< Uint32_Index >::global()); 1067239433 q Ranges< Uint31_Index > ranges_31(ranges_31_ ? *ranges_31_ : Ranges< Uint31_Index >::global()); 1068239433 q Timeless< Uint32_Index, Node_Skeleton > rel_nodes 1069239433 q = relation_node_members(context, input_set.relations, input_set.attic_relations, ranges_32, {}, true); 1071239433 q if (context.get_desired_timestamp() == NOW) 107369426 q relation_way_members(context, input_set.relations, {}, ranges_31, {}, true) 107469426 q .swap(into.ways, into.attic_ways); 107569426 q std::map< Uint31_Index, std::vector< Way_Skeleton > > source_ways = input_set.ways; 107869426 q indexed_set_union(source_ways, into.ways); 107969426 q way_members(context, source_ways, {}, 0, Ranges< Uint32_Index >::global(), {}, true) 108069426 q .swap(into.nodes, into.attic_nodes); 108269426 q sort_second(rel_nodes.current); 108369426 q indexed_set_union(into.nodes, rel_nodes.current); 108717009 q rel_nodes.swap(into.nodes, into.attic_nodes); 108917009 q Timeless< Uint31_Index, Way_Skeleton > all_ways 109017009 q = relation_way_members(context, input_set.relations, input_set.attic_relations, ranges_31, {}, true); 109117009 q into.ways = all_ways.current; 109217009 q into.attic_ways = all_ways.attic; 109517009 q std::map< Uint31_Index, std::vector< Way_Skeleton > > source_ways = input_set.ways; 109617009 q std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > > source_attic_ways = input_set.attic_ways; 109717009 q sort_second(source_ways); 109817009 q sort_second(source_attic_ways); 109917009 q indexed_set_union(all_ways.current, source_ways); 110017009 q indexed_set_union(all_ways.attic, source_attic_ways); 110217009 q Timeless< Uint32_Index, Node_Skeleton > more_nodes 110317009 q = way_members(context, all_ways.current, all_ways.attic, 0, Ranges< Uint32_Index >::global(), {}, true); 110517009 q sort_second(into.nodes); 110617009 q sort_second(into.attic_nodes); 110717009 q indexed_set_union(into.nodes, more_nodes.current); 110817009 q indexed_set_union(into.attic_nodes, more_nodes.attic); 110917009 q keep_matching_skeletons(into.nodes, into.attic_nodes, context.get_desired_timestamp());