Overpass API regression suite coverage (Nova Scotia) / overpass_api/data/collect_members.cc

overpass_api/data/collect_members.cc

734 of 771 instrumented lines run by the suite (95.2%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
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.
9 *
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.
14 *
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/>.
17 */
19#include "abstract_processing.h"
20#include "collect_members.h"
21#include "utils.h"
23#include <cstdint>
25//-----------------------------------------------------------------------------
27template< typename Container >
28void way_nd_ids_pos(
29 const Container& ways, const std::vector< int >& pos, std::vector< Node::Id_Type >& ids)
3196 q for (const auto& i : ways)
322793 q {
332793 q for (const auto& j : i.second)
349633 q {
359633 q auto it3 = pos.begin();
3619243 q while (it3 != pos.end() && *it3 < 0)
379612 q {
389612 q if (*it3 + (int)j.nds.size() >= 0)
399612 q ids.push_back(j.nds[*it3 + j.nds.size()]);
409612 q ++it3;
419612 q }
429633 q while (it3 != pos.end() && *it3 == 0)
430 ++it3;
4416333 q while(it3 != pos.end())
456702 q {
466702 q if (*it3 < (int)j.nds.size()+1)
476702 q ids.push_back(j.nds[*it3-1]);
486702 q ++it3;
496702 q }
509633 q }
512793 q }
55template< typename Container >
56void way_nd_ids_plain(const Container& ways, std::vector< Node::Id_Type >& ids)
57248073 q{
58248073 q for (const auto& i : ways)
5920356650 q {
6020356650 q for (const auto& j : i.second)
6148027450 q {
6248027450 q for (auto k : j.nds)
631614576550 q ids.push_back(k);
6448027450 q }
6520356650 q }
66248073 q}
69template< typename Container >
70void way_nd_ids_once(const Container& ways, std::vector< Node::Id_Type >& ids)
725128 q for (const auto& i : ways)
731091119 q {
741091119 q for (const auto& j : i.second)
754581119 q {
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());
814581119 q }
821091119 q }
86template< typename Container >
87void way_nd_firstlast(const Container& ways, std::vector< Node::Id_Type >& ids)
892718 q for (const auto& i : ways)
907486511 q {
917486511 q for (const auto& j : i.second)
9216478311 q {
9316478311 q if (j.nds.empty())
940 continue;
9516478311 q ids.push_back(j.nds.front());
9616478311 q ids.push_back(j.nds.back());
9716478311 q }
987486511 q }
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)
106243763 q{
107243763 q std::vector< Node::Id_Type > ids;
108243763 q if (pos)
10996 q way_nd_ids_pos(ways, *pos, ids);
110242860 q else
111242860 q way_nd_ids_plain(ways, ids);
113243763 q if (!attic_ways.empty())
1152511 q if (pos)
1160 way_nd_ids_pos(attic_ways, *pos, ids);
1172511 q else
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());
124243763 q return ids;
125243763 q}
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);
1353928 q if (!attic_ways.empty())
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())
14450118719 q {
145104601519 q while (upper < ids.size() && ids[lower] == ids[upper])
14654482819 q ++upper;
14750118719 q if (lower_limit <= upper - lower && upper - lower <= upper_limit)
14840238517 q ids[target++] = ids[lower];
14950118719 q lower = upper;
15050118719 q }
1513928 q ids.resize(target);
1533928 q return ids;
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);
1642118 q if (!attic_ways.empty())
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);
1712118 q if (!attic_ways.empty())
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())
182496590311 q {
1831042895511 q while (upper < ids.size() && ids[lower] == ids[upper])
184546305211 q ++upper;
185496590311 q while (fl_lower < fl_ids.size() && fl_ids[fl_lower] < ids[lower])
1860 ++fl_lower;
187496590311 q fl_upper = fl_lower;
188529546911 q while (fl_upper < fl_ids.size() && fl_ids[fl_upper] == ids[lower])
18932956611 q ++fl_upper;
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];
193496590311 q lower = upper;
194496590311 q fl_lower = fl_upper;
195496590311 q }
1962118 q ids.resize(target);
1982118 q return ids;
202Ranges< Uint32_Index > calc_node_children_ranges(const std::vector< uint32 >& way_rel_idxs)
20312627442 q{
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)
2081018143337 q {
2091018143337 q if (*it & 0x80000000)
210334838314 q {
211334838314 q uint32 lat = 0;
212334838314 q uint32 lon = 0;
213334838314 q uint32 lat_u = 0;
214334838314 q uint32 lon_u = 0;
215334838314 q uint32 offset = 0;
217334838314 q if (*it & 0x00000001)
218311719311 q {
219311719311 q lat = upper_ilat(*it & 0x2aaaaaa8);
220311719311 q lon = upper_ilon(*it & 0x55555554);
221311719311 q offset = 2;
222311719311 q }
22323119167 q else if (*it & 0x00000002)
22423046166 q {
22523046166 q lat = upper_ilat(*it & 0x2aaaaa80);
22623046166 q lon = upper_ilon(*it & 0x55555540);
22723046166 q offset = 8;
22823046166 q }
229739 q else if (*it & 0x00000004)
230539 q {
231539 q lat = upper_ilat(*it & 0x2aaaa800);
232539 q lon = upper_ilon(*it & 0x55555400);
233539 q offset = 0x20;
234539 q }
235202 q else if (*it & 0x00000008)
236102 q {
237102 q lat = upper_ilat(*it & 0x2aaa8000);
238102 q lon = upper_ilon(*it & 0x55554000);
239102 q offset = 0x80;
240102 q }
241102 q else if (*it & 0x00000010)
242102 q {
243102 q lat = upper_ilat(*it & 0x2aa80000);
244102 q lon = upper_ilon(*it & 0x55540000);
245102 q offset = 0x200;
246102 q }
2470 else if (*it & 0x00000020)
2480 {
2490 lat = upper_ilat(*it & 0x2a800000);
2500 lon = upper_ilon(*it & 0x55400000);
2510 offset = 0x800;
2520 }
2530 else if (*it & 0x00000040)
2540 {
2550 lat = upper_ilat(*it & 0x28000000);
2560 lon = upper_ilon(*it & 0x54000000);
2570 offset = 0x2000;
2580 }
2590 else // *it == 0x80000080
2600 {
2610 lat = 0;
2620 lon = 0;
2630 offset = 0x8000;
2640 }
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);
269334838314 q result.push_back(
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)
2720 {
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);
2750 }
276334838314 q }
277683305325 q else
278683305325 q result.push_back(*it, (*it) + 1);
2791018143337 q }
28012627442 q result.sort();
28212627442 q return result;
28312627442 q}
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)
29369934187 q {
29469934187 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0))
2955789176 q {
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)
29843464155 q {
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());
30243464155 q }
3035789176 q }
30464145168 q else
30564145168 q parents.push_back(it->first.val());
30669934187 q }
30745230416 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it)
3084065445 q {
3094065445 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0))
310295341 q {
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)
31338423 q {
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());
31738423 q }
318295341 q }
3193770138 q else
3203770138 q parents.push_back(it->first.val());
3214065445 q }
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)
33584700188 q {
33684700188 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0))
3376302178 q {
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)
34050860157 q {
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);
34450860157 q }
3456302178 q }
34678398169 q else
34778398169 q parents.push_back(it->first);
34884700188 q }
34948622420 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it)
3504391376 q {
3514391376 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0))
352406072 q {
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)
355600659 q {
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);
359600659 q }
360406072 q }
3613985364 q else
3623985364 q parents.push_back(it->first);
3634391376 q }
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;
3753021 q for (auto i : arg)
37616347 q result.push_back(i, inc(i));
3773021 q return result;
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));
3904709420 q req.sort();
3914709420 q return req;
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)
4121281 q {
4131281 q if (attic_random.get(it->val()).val() == 0)
4140 ;
4151281 q else if (attic_random.get(it->val()) == 0xff)
416931 q idx_list_ids.push_back(it->val());
417351 q else
418351 q result.push_back(attic_random.get(it->val()));
4191281 q }
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());
43131 q return result;
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();
4782721 q map_ids.clear();
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());
4852721 q if (!map_ids.empty())
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);
4912420 q return current;
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)
50221328766 q {
50321328766 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x1) == 0)) // Adapt 0x3
5041108546 q {
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)
5083949445 q {
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);
5123949445 q }
5131108546 q }
51420220264 q else
51520220264 q parents.push_back(it->first.val());
51621328766 q }
5173447101 q for (auto it = attic_ways.begin(); it != attic_ways.end(); ++it)
51895523 q {
51995523 q if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x1) == 0)) // Adapt 0x3
52022317 q {
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)
52434617 q {
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);
52834617 q }
52922317 q }
53073223 q else
53173223 q parents.push_back(it->first.val());
53295523 q }
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;
5643825 q if (role_id)
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);
5693522 q else
5711521822 q for (auto it = rels.begin(); it != rels.end(); ++it)
5721518313 q filter_for_member_ids(it->second, ids, Relation_Entry::RELATION);
5753825 q if (role_id)
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);
5823522 q else
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());
5923825 q return ids;
596template< typename Id_Type >
597void sieve_first_arg(
598 std::vector< Id_Type >& working_ids, const std::vector< Id_Type >& extra_ids, bool invert_ids)
59911649437 q{
60011649437 q std::vector< Id_Type > copy_ids = working_ids;
60111649437 q if (!invert_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());
60511644436 q else
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());
60911649437 q}
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());
661135110 q return result;
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());
6737050429 q return result;
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);
6884558416 q return paired_items_range(
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());
708135110 q return result;
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)
719243263 q{
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));
726243263 q}
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;
7688960585 q if (roles.empty())
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();
7778960585 q return roles;
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)
785261121 q {
786261121 q if (it->second == role)
7873121 q return it->first;
788261121 q }
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)
79839426076 q{
79939426076 q bool wraps_around_date_line = false;
80139426076 q if (coords.size() < 2)
802412 q return false;
80439421976 q uint32 cur_idx = 0;
80539421976 q std::vector< uint64 > cur_polyline;
8061001747076 q for (std::vector< Quad_Coord >::const_iterator it = coords.begin(); it != coords.end(); ++it)
807962325176 q {
808962325176 q if ((it->ll_upper & 0xffffff00) != cur_idx)
80947099676 q {
81047099676 q if (cur_idx != 0)
8117674371 q {
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);
8197674371 q cur_polyline.clear();
8207674371 q for (std::vector< Aligned_Segment >::const_iterator
82133015571 q it(aligned_segments.begin()); it != aligned_segments.end(); ++it)
82225341271 q {
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();
82725341271 q }
8287674371 q }
82947099676 q cur_idx = (it->ll_upper & 0xffffff00);
83047099676 q }
831962325176 q cur_polyline.push_back(((uint64)it->ll_upper<<32) | it->ll_lower);
832962325176 q }
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;
83739426076 q}
840std::vector< Quad_Coord > make_geometry(const Way_Skeleton& way, const std::vector< Node >& nodes)
8412037836301 q{
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)
84625175812301 q {
84725175812301 q const Node* node = binary_search_for_id(nodes, *it3);
84825175812301 q if (node == 0)
849968 q {
850968 q result.clear();
851968 q return result;
852968 q }
85325175716301 q result.push_back(Quad_Coord(node->index, node->ll_lower_));
85425175716301 q }
8562037740301 q return result;
8572037836301 q}
860std::vector< Uint31_Index > segment_idxs(const std::vector< Quad_Coord >& geometry)
861111612215 q{
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);
868111612215 q}
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(); )
880140764231 q {
881140764231 q if (!(it->first < ranges_it.upper_bound()))
88240817227 q ++ranges_it;
88399947229 q else if (!(it->first < ranges_it.lower_bound()))
88499940228 q {
88599940228 q if ((it->first.val() & 0x80000000) == 0 || (it->first.val() & 0x1) != 0) // Adapt 0x3
88689086219 q ++it;
88710854223 q else
88810854223 q {
88910854223 q std::vector< Object > filtered_ways;
89044132223 q while (!(Uint31_Index(it->first.val() & 0x7fffff00) < ranges_begin.upper_bound()))
89133278219 q ++ranges_begin;
89210854223 q for (typename std::vector< Object >::const_iterator it2 = it->second.begin();
893122466223 q it2 != it->second.end(); ++it2)
894111612215 q {
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(); )
8991725650215 q {
9001725650215 q if (!(*it3 < ranges_it2.upper_bound()))
901841847215 q ++ranges_it2;
902883803214 q else if (!(*it3 < ranges_it2.lower_bound()))
90369957212 q {
904 // A relevant index is found; thus the way is relevant.
90569957212 q filtered_ways.push_back(*it2);
90669957212 q break;
90769957212 q }
908813846212 q else
909813846212 q ++it3;
9101725650215 q }
911111612215 q }
91310854223 q filtered_ways.swap(it->second);
91410854223 q ++it;
91510854223 q }
91699940228 q }
91772 q else
919 // The index of the way is not in the current set of ranges.
920 // Thus it cannot be in the result set.
92172 q it->second.clear();
92272 q ++it;
924140764231 q }
9251760328 q for (; it != ways.end(); ++it)
9268635 q it->second.clear();
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,
948 uint64 timestamp)
9501793232 q std::map< Node_Skeleton::Id_Type, uint64 > timestamp_by_id;
9521793232 q result.clear();
9541793232 q for (std::map< Uint32_Index, std::vector< Node_Skeleton > >::const_iterator it = current.begin();
955186590232 q it != current.end(); ++it)
956184797111 q {
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;
959184797111 q }
9611793232 q for (std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >::const_iterator it = attic.begin();
962186590232 q it != attic.end(); ++it)
963184797111 q {
964184797111 q for (std::vector< Attic<Node_Skeleton > >::const_iterator it2 = it->second.begin();
965662667111 q it2 != it->second.end(); ++it2)
966477870106 q {
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;
970477870106 q }
971184797111 q }
9731793232 q for (std::map< Uint32_Index, std::vector< Node_Skeleton > >::const_iterator it = current.begin();
974186590232 q it != current.end(); ++it)
975184797111 q {
9761404338111 q for (std::vector< Node_Skeleton >::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
9771219541108 q {
9781219541108 q if (timestamp_by_id[it2->id] == NOW)
9791211205107 q result.push_back(Node(it2->id, it->first.val(), it2->ll_lower));
9801219541108 q }
981184797111 q }
9831793232 q for (std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >::const_iterator it = attic.begin();
984186590232 q it != attic.end(); ++it)
985184797111 q {
986184797111 q for (std::vector< Attic<Node_Skeleton > >::const_iterator it2 = it->second.begin();
987662667111 q it2 != it->second.end(); ++it2)
988477870106 q {
989477870106 q if (timestamp_by_id[it2->id] == it2->timestamp)
990475496106 q result.push_back(Node(it2->id, it->first.val(), it2->ll_lower));
991477870106 q }
992184797111 q }
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,
1004 uint32* role_id)
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);
10263936 q else
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)
1037351336 q req.insert(*it);
104014589 q if (!invert_ids)
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);
104613984 q else if (ids.empty())
104713984 q collect_items_discrete(context, req,
104813984 q Get_Parent_Ways_Predicate(children_ids, pos), result.current, result.attic);
10490 else
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);
105914589 q return result;
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;
107669426 q sort_second(source_ways);
107769426 q sort_second(into.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);
108169426 q sort_second(into.nodes);
108269426 q sort_second(rel_nodes.current);
108369426 q indexed_set_union(into.nodes, rel_nodes.current);
108517009 q else
108617009 q {
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;
109317009 q all_ways.sort();
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);
110417009 q more_nodes.sort();
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());
111017009 q }