Overpass API regression suite coverage (Saxony) / overpass_api/data/set_comparison.cc

overpass_api/data/set_comparison.cc

839 of 986 instrumented lines run by the suite (85.1%) 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 "../statements/evaluator.h"
20#include "set_comparison.h"
22#include <algorithm>
23#include <map>
24#include <string>
25#include <utility>
26#include <vector>
29Extra_Data_For_Diff::Extra_Data_For_Diff(
30 Resource_Manager& rman, const Statement& stmt, const Set& to_print, unsigned int mode_,
31 double south, double north, double west, double east)
3291481 q : mode(mode_), way_geometry_store(0), attic_way_geometry_store(0),
3391481 q relation_geometry_store(0), attic_relation_geometry_store(0), roles(0), users(0)
3491481 q{
3591481 q if (mode & (Output_Mode::GEOMETRY | Output_Mode::BOUNDS | Output_Mode::CENTER))
3691481 q {
3791481 q way_geometry_store = new Way_Bbox_Geometry_Store(to_print.ways, stmt, rman, south, north, west, east);
3891481 q if (rman.get_desired_timestamp() < NOW)
3961081 q {
4061081 q attic_way_geometry_store = new Way_Bbox_Geometry_Store(
4161081 q to_print.attic_ways, stmt, rman,
4261081 q south, north, west, east);
4361081 q }
4591481 q relation_geometry_store = new Relation_Geometry_Store(
4691481 q to_print.relations, stmt, rman, south, north, west, east);
4791481 q if (rman.get_desired_timestamp() < NOW)
4861081 q {
4961081 q attic_relation_geometry_store = new Relation_Geometry_Store(
5061081 q to_print.attic_relations, stmt, rman,
5161081 q south, north, west, east);
5261081 q }
5391481 q }
5591481 q roles = &relation_member_roles(*rman.get_transaction());
5791481 q if (mode & Output_Mode::META)
5891481 q users = &rman.users();
5991481 q}
62const std::map< uint32, std::string >* Extra_Data_For_Diff::get_users() const
630{
640 return users;
650}
68Extra_Data_For_Diff::~Extra_Data_For_Diff()
6991481 q{
7091481 q delete way_geometry_store;
7191481 q delete attic_way_geometry_store;
7291481 q delete relation_geometry_store;
7391481 q delete attic_relation_geometry_store;
7491481 q}
77void Set_Comparison::set_target(bool target)
7845781 q{
7945781 q final_target = target;
8045781 q std::sort(nodes.begin(), nodes.end());
8145781 q std::sort(ways.begin(), ways.end());
8245781 q std::sort(relations.begin(), relations.end());
8345781 q}
86void Set_Comparison::print_item(Extra_Data_For_Diff& extra_data, uint32 ll_upper, const Node_Skeleton& skel,
87 const std::vector< std::pair< std::string, std::string > >* tags,
88 const OSM_Element_Metadata_Skeleton< Node_Skeleton::Id_Type >* meta,
89 const std::map< uint32, std::string >* users)
90136100734 q{
91136100734 q if (final_target)
92127268034 q compare_item(ll_upper, skel, tags, NOW, meta, users);
938832725 q else
948832725 q store_item(ll_upper, skel, tags, NOW, meta, users);
95136100734 q}
98void Set_Comparison::print_item(Extra_Data_For_Diff& extra_data, uint32 ll_upper, const Attic< Node_Skeleton >& skel,
99 const std::vector< std::pair< std::string, std::string > >* tags,
100 const OSM_Element_Metadata_Skeleton< Node_Skeleton::Id_Type >* meta,
101 const std::map< uint32, std::string >* users)
10210320029 q{
10310320029 q if (final_target)
104598010 q compare_item(ll_upper, skel, tags, skel.timestamp, meta, users);
1059722025 q else
1069722025 q store_item(ll_upper, skel, tags, skel.timestamp, meta, users);
10710320029 q}
110void Set_Comparison::print_item(Extra_Data_For_Diff& extra_data, uint32 ll_upper, const Way_Skeleton& skel,
111 const std::vector< std::pair< std::string, std::string > >* tags,
112 const OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type >* meta,
113 const std::map< uint32, std::string >* users)
11422781039 q{
11522781039 q if (extra_data.way_geometry_store)
11622781039 q {
11722781039 q std::vector< Quad_Coord > geometry = extra_data.way_geometry_store->get_geometry(skel);
11822781039 q Double_Coords double_coords(geometry);
11922781039 q if (final_target)
12022137039 q compare_item(ll_upper, skel, tags,
12122137039 q geometry.empty() ? 0 : bound_variant(double_coords, extra_data.mode),
12222137039 q ((extra_data.mode & Output_Mode::GEOMETRY) && geometry.size() == skel.nds.size()) ? &geometry : 0,
12322137039 q NOW, meta, users);
124644019 q else
125644019 q store_item(ll_upper, skel, tags,
126644019 q geometry.empty() ? 0 : bound_variant(double_coords, extra_data.mode),
127644019 q ((extra_data.mode & Output_Mode::GEOMETRY) && geometry.size() == skel.nds.size()) ? &geometry : 0,
128644019 q NOW, meta, users);
12922781039 q }
1300 else
1310 {
1320 if (final_target)
1330 compare_item(ll_upper, skel, tags, 0, 0, NOW, meta, users);
1340 else
1350 store_item(ll_upper, skel, tags, 0, 0, NOW, meta, users);
1360 }
13722781039 q}
140void Set_Comparison::print_item(Extra_Data_For_Diff& extra_data, uint32 ll_upper, const Attic< Way_Skeleton >& skel,
141 const std::vector< std::pair< std::string, std::string > >* tags,
142 const OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type >* meta,
143 const std::map< uint32, std::string >* users)
1442238432 q{
1452238432 q if (extra_data.attic_way_geometry_store)
1462238432 q {
1472238432 q std::vector< Quad_Coord > geometry = extra_data.attic_way_geometry_store->get_geometry(skel);
1482238432 q Double_Coords double_coords(geometry);
1492238432 q if (final_target)
150203410 q compare_item(ll_upper, skel, tags,
151203410 q geometry.empty() ? 0 : bound_variant(double_coords, extra_data.mode),
152203410 q ((extra_data.mode & Output_Mode::GEOMETRY) && geometry.size() == skel.nds.size()) ? &geometry : 0,
153203410 q skel.timestamp, meta, users);
1542035029 q else
1552035029 q store_item(ll_upper, skel, tags,
1562035029 q geometry.empty() ? 0 : bound_variant(double_coords, extra_data.mode),
1572035029 q ((extra_data.mode & Output_Mode::GEOMETRY) && geometry.size() == skel.nds.size()) ? &geometry : 0,
1582035029 q skel.timestamp, meta, users);
1592238432 q }
1600 else
1610 {
1620 if (final_target)
1630 compare_item(ll_upper, skel, tags, 0, 0, skel.timestamp, meta, users);
1640 else
1650 store_item(ll_upper, skel, tags, 0, 0, skel.timestamp, meta, users);
1660 }
1672238432 q}
170void Set_Comparison::print_item(Extra_Data_For_Diff& extra_data, uint32 ll_upper, const Relation_Skeleton& skel,
171 const std::vector< std::pair< std::string, std::string > >* tags,
172 const OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type >* meta,
173 const std::map< uint32, std::string >* users)
17581213 q if (extra_data.relation_geometry_store)
17681213 q {
17781213 q std::vector< std::vector< Quad_Coord > > geometry = extra_data.relation_geometry_store->get_geometry(skel);
17881213 q Double_Coords double_coords(geometry);
17981213 q if (final_target)
18080213 q compare_item(ll_upper, skel, tags,
18180213 q geometry.empty() ? 0 : bound_variant(double_coords, extra_data.mode),
18280213 q ((extra_data.mode & Output_Mode::GEOMETRY) && geometry.size() == skel.members.size()) ? &geometry : 0,
18380213 q NOW, meta, users);
184102 q else
185102 q store_item(ll_upper, skel, tags,
186102 q geometry.empty() ? 0 : bound_variant(double_coords, extra_data.mode),
187102 q ((extra_data.mode & Output_Mode::GEOMETRY) && geometry.size() == skel.members.size()) ? &geometry : 0,
188102 q NOW, meta, users);
18981213 q }
1900 else
1910 {
1920 if (final_target)
1930 compare_item(ll_upper, skel, tags, 0, 0, NOW, meta, users);
1940 else
1950 store_item(ll_upper, skel, tags, 0, 0, NOW, meta, users);
1960 }
200void Set_Comparison::print_item(Extra_Data_For_Diff& extra_data, uint32 ll_upper, const Attic< Relation_Skeleton >& skel,
201 const std::vector< std::pair< std::string, std::string > >* tags,
202 const OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type >* meta,
203 const std::map< uint32, std::string >* users)
20531011 q if (extra_data.attic_relation_geometry_store)
20631011 q {
20731011 q std::vector< std::vector< Quad_Coord > > geometry = extra_data.attic_relation_geometry_store->get_geometry(skel);
20831011 q Double_Coords double_coords(geometry);
20931011 q if (final_target)
2101244 q compare_item(ll_upper, skel, tags,
2111244 q geometry.empty() ? 0 : bound_variant(double_coords, extra_data.mode),
2121244 q ((extra_data.mode & Output_Mode::GEOMETRY) && geometry.size() == skel.members.size()) ? &geometry : 0,
2131244 q skel.timestamp, meta, users);
2141869 q else
2151869 q store_item(ll_upper, skel, tags,
2161869 q geometry.empty() ? 0 : bound_variant(double_coords, extra_data.mode),
2171869 q ((extra_data.mode & Output_Mode::GEOMETRY) && geometry.size() == skel.members.size()) ? &geometry : 0,
2181869 q skel.timestamp, meta, users);
21931011 q }
2200 else
2210 {
2220 if (final_target)
2230 compare_item(ll_upper, skel, tags, 0, 0, skel.timestamp, meta, users);
2240 else
2250 store_item(ll_upper, skel, tags, 0, 0, skel.timestamp, meta, users);
2260 }
230template< class Index, class Object >
231void Set_Comparison::tags_quadtile
232 (Extra_Data_For_Diff& extra_data, const std::map< Index, std::vector< Object > >& items, Resource_Manager& rman)
233264081 q{
234264081 q Tag_Store< Index, Object > tag_store(*rman.get_transaction());
235264081 q tag_store.prefetch_all(items);
237 // formulate meta query if meta data shall be printed
238264081 q Meta_Collector< Index, typename Object::Id_Type > meta_printer(items, *rman.get_transaction(),
239264081 q (extra_data.mode & Output_Mode::META) ? current_meta_file_properties< Object >() : 0);
241264081 q typename std::map< Index, std::vector< Object > >::const_iterator
242264081 q item_it(items.begin());
243 // print the result
2441736181 q while (item_it != items.end())
2451472167 q {
2461472167 q for (typename std::vector< Object >::const_iterator it2(item_it->second.begin());
247146079067 q it2 != item_it->second.end(); ++it2)
248144606963 q {
249144606963 q print_item(extra_data, item_it->first.val(), *it2, tag_store.get(item_it->first, *it2),
250144606963 q meta_printer.get(item_it->first, it2->id), extra_data.users);
251144606963 q }
2521472167 q ++item_it;
2531472167 q }
254264081 q}
257template< class Index, class Object >
258void Set_Comparison::tags_quadtile_attic
259 (Extra_Data_For_Diff& extra_data, const std::map< Index, std::vector< Attic< Object > > >& items,
260 Resource_Manager& rman)
261175881 q{
262175881 q Tag_Store< Index, Object > tag_store(*rman.get_transaction());
263175881 q tag_store.prefetch_all(items);
264 // formulate meta query if meta data shall be printed
265175881 q Attic_Meta_Collector< Index, Object > meta_printer(
266175881 q items, *rman.get_transaction(), extra_data.mode & Output_Mode::META);
268175881 q typename std::map< Index, std::vector< Attic< Object > > >::const_iterator
269175881 q item_it(items.begin());
2701366781 q while (item_it != items.end())
2711190965 q {
2721190965 q for (typename std::vector< Attic< Object > >::const_iterator it2(item_it->second.begin());
27312962965 q it2 != item_it->second.end(); ++it2)
27411772051 q print_item(extra_data, item_it->first.val(), *it2, tag_store.get(item_it->first, *it2),
27511772051 q meta_printer.get(item_it->first, it2->id, it2->timestamp), extra_data.users);
2761190965 q ++item_it;
2771190965 q }
278175881 q}
281template< class Index, class Object >
282void Set_Comparison::tags_quadtile
283 (Extra_Data_For_Diff& extra_data, const std::map< Index, std::vector< Object > >& items,
284 const std::vector< typename Object::Id_Type >& id_list, Resource_Manager& rman)
28610217 q Tag_Store< Index, Object > tag_store(*rman.get_transaction());
28710217 q tag_store.prefetch_all(items);
289 // formulate meta query if meta data shall be printed
29010217 q Meta_Collector< Index, typename Object::Id_Type > meta_printer(items, *rman.get_transaction(),
29110217 q (extra_data.mode & Output_Mode::META) ? current_meta_file_properties< Object >() : 0);
29310217 q typename std::map< Index, std::vector< Object > >::const_iterator
29410217 q item_it(items.begin());
295 // print the result
296137017 q while (item_it != items.end())
297126811 q {
298126811 q for (typename std::vector< Object >::const_iterator it2(item_it->second.begin());
29916575311 q it2 != item_it->second.end(); ++it2)
30016448510 q {
30116448510 q if (std::binary_search(id_list.begin(), id_list.end(), it2->id))
3021435609 q print_item(extra_data, item_it->first.val(), *it2, tag_store.get(item_it->first, *it2),
3031435609 q meta_printer.get(item_it->first, it2->id), extra_data.users);
30416448510 q }
305126811 q ++item_it;
306126811 q }
310template< class Index, class Object >
311void Set_Comparison::tags_quadtile_attic
312 (Extra_Data_For_Diff& extra_data, const std::map< Index, std::vector< Attic< Object > > >& items,
313 const std::vector< typename Object::Id_Type >& id_list, Resource_Manager& rman)
3157217 q Tag_Store< Index, Object > tag_store(*rman.get_transaction());
3167217 q tag_store.prefetch_all(items);
317 // formulate meta query if meta data shall be printed
3187217 q Attic_Meta_Collector< Index, Object > meta_printer(
3197217 q items, *rman.get_transaction(), extra_data.mode & Output_Mode::META);
3217217 q typename std::map< Index, std::vector< Attic< Object > > >::const_iterator
3227217 q item_it(items.begin());
32384317 q while (item_it != items.end())
32477111 q {
32577111 q for (typename std::vector< Attic< Object > >::const_iterator it2(item_it->second.begin());
326899511 q it2 != item_it->second.end(); ++it2)
32782246 q {
32882246 q if (std::binary_search(id_list.begin(), id_list.end(), it2->id))
32981745 q print_item(extra_data, item_it->first.val(), *it2, tag_store.get(item_it->first, *it2),
33081745 q meta_printer.get(item_it->first, it2->id, it2->timestamp), extra_data.users);
33182246 q }
33277111 q ++item_it;
33377111 q }
337template< typename Index, typename Skeleton >
338std::vector< typename Skeleton::Id_Type > find_still_existing_skeletons
339 (Resource_Manager& rman, uint64 timestamp, const std::vector< Index >& req,
340 const std::vector< typename Skeleton::Id_Type >& searched_ids)
341106833 q{
342106833 q std::vector< typename Skeleton::Id_Type > found_ids;
343106833 q std::map< Index, std::vector< Skeleton > > current_result;
344106833 q std::map< Index, std::vector< Attic< Skeleton > > > attic_result;
346106833 q Request_Context context(0, rman);
347106833 q collect_items_discrete(context, req,
348106833 q Id_Predicate< Skeleton >(searched_ids), timestamp, current_result, attic_result);
349106833 q filter_attic_elements(rman, timestamp, current_result, attic_result);
351106833 q for (typename std::map< Index, std::vector< Skeleton > >::const_iterator it = current_result.begin();
352522433 q it != current_result.end(); ++it)
353415624 q {
354485424 q for (typename std::vector< Skeleton >::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2)
35569810 q found_ids.push_back(it2->id);
356415624 q }
357106833 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::const_iterator it = attic_result.begin();
358500533 q it != attic_result.end(); ++it)
359393724 q {
360393724 q for (typename std::vector< Attic< Skeleton > >::const_iterator it2 = it->second.begin();
361473124 q it2 != it->second.end(); ++it2)
36279413 q found_ids.push_back(it2->id);
363393724 q }
364106833 q std::sort(found_ids.begin(), found_ids.end());
365106833 q found_ids.erase(std::unique(found_ids.begin(), found_ids.end()), found_ids.end());
367106833 q return found_ids;
368106833 q}
371template< typename Index, typename Skeleton >
372std::map< typename Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type > >
373 find_meta_elements
374 (Resource_Manager& rman, uint64 timestamp, const std::vector< Index >& idx_set,
375 const std::vector< typename Skeleton::Id_Type >& searched_ids)
376106833 q{
377106833 q std::map< typename Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type > > result;
379106833 q Block_Backend< Index, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type >,
380106833 q typename std::vector< Index >::const_iterator >
381106833 q attic_meta_db(rman.get_transaction()->data_index(attic_meta_file_properties< Skeleton >()));
382106833 q for (typename Block_Backend< Index, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type >,
383106833 q typename std::vector< Index >::const_iterator >::Discrete_Iterator
384106833 q it = attic_meta_db.discrete_begin(idx_set.begin(), idx_set.end());
385636421333 q !(it == attic_meta_db.discrete_end()); ++it)
386636314524 q {
387636314524 q if (!(timestamp < it.object().timestamp)
388636314524 q && std::binary_search(searched_ids.begin(), searched_ids.end(), it.object().ref))
3894710919 q {
3904710919 q typename std::map< typename Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type > >
3914710919 q ::iterator meta_it = result.find(it.object().ref);
3924710919 q if (meta_it == result.end())
3931063419 q result.insert(std::make_pair(it.object().ref, it.object()));
3943647515 q else if (meta_it->second.timestamp < it.object().timestamp)
3953520815 q meta_it->second = it.object();
3964710919 q }
397636314524 q }
399 // Same thing with current meta data
400106833 q Block_Backend< Index, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type >,
401106833 q typename std::vector< Index >::const_iterator >
402106833 q meta_db(rman.get_transaction()->data_index(current_meta_file_properties< Skeleton >()));
404106833 q for (typename Block_Backend< Index, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type >,
405106833 q typename std::vector< Index >::const_iterator >::Discrete_Iterator
406106833 q it = meta_db.discrete_begin(idx_set.begin(), idx_set.end());
407338309333 q !(it == meta_db.discrete_end()); ++it)
408338202524 q {
409338202524 q if (!(timestamp < it.object().timestamp)
410338202524 q && std::binary_search(searched_ids.begin(), searched_ids.end(), it.object().ref))
41169810 q {
41269810 q typename std::map< typename Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type > >
41369810 q ::iterator meta_it = result.find(it.object().ref);
41469810 q if (meta_it == result.end())
4151232 q result.insert(std::make_pair(it.object().ref, it.object()));
41657510 q else if (meta_it->second.timestamp < it.object().timestamp)
41757210 q meta_it->second = it.object();
41869810 q }
419338202524 q }
421106833 q return result;
422106833 q}
425void Set_Comparison::store_item(uint32 ll_upper, const Node_Skeleton& skel,
426 const std::vector< std::pair< std::string, std::string > >* tags,
427 uint64 timestamp, const OSM_Element_Metadata_Skeleton< Node::Id_Type >* meta,
428 const std::map< uint32, std::string >* users, const Output_Handler::Feature_Action& action,
429 const OSM_Element_Metadata_Skeleton< Node::Id_Type >* new_meta)
43018554728 q{
43118554728 q nodes.push_back(Node_With_Context(ll_upper, skel, timestamp,
43218554728 q meta ? *meta : OSM_Element_Metadata_Skeleton< Node_Skeleton::Id_Type >(),
43318554728 q tags ? *tags : std::vector< std::pair< std::string, std::string > >()));
43418554728 q}
437void Set_Comparison::compare_item(uint32 ll_upper, const Node_Skeleton& skel,
438 const std::vector< std::pair< std::string, std::string > >* tags,
439 uint64 timestamp, const OSM_Element_Metadata_Skeleton< Node::Id_Type >* meta,
440 const std::map< uint32, std::string >* users, const Output_Handler::Feature_Action& action,
441 const OSM_Element_Metadata_Skeleton< Node::Id_Type >* new_meta)
442127866036 q{
443127866036 q std::vector< Node_With_Context >::iterator nodes_it
444127866036 q = std::lower_bound(nodes.begin(), nodes.end(), Node_With_Context(ll_upper, skel, 0));
446127866036 q if (nodes_it == nodes.end() || skel.id < nodes_it->elem.id)
447112681533 q result.different_nodes.push_back(std::make_pair(
448112681533 q Node_With_Context(0xffu, Node_Skeleton(skel.id), 0,
449112681533 q OSM_Element_Metadata_Skeleton< Node_Skeleton::Id_Type >(),
450112681533 q std::vector< std::pair< std::string, std::string > >()),
451112681533 q Node_With_Context(ll_upper, skel, timestamp,
452112681533 q meta ? *meta : OSM_Element_Metadata_Skeleton< Node_Skeleton::Id_Type >(),
453112681533 q tags ? *tags : std::vector< std::pair< std::string, std::string > >())));
45415184528 q else
45515184528 q {
45615184528 q if (!(nodes_it->idx.val() == ll_upper) || !(nodes_it->elem.ll_lower == skel.ll_lower) ||
45715184528 q (tags && !(nodes_it->tags == *tags)) || (meta && !(nodes_it->meta.timestamp == meta->timestamp)))
4586342925 q result.different_nodes.push_back(std::make_pair(*nodes_it, Node_With_Context(ll_upper, skel, timestamp,
4596342925 q meta ? *meta : OSM_Element_Metadata_Skeleton< Node_Skeleton::Id_Type >(),
4606342925 q tags ? *tags : std::vector< std::pair< std::string, std::string > >())));
46215184528 q nodes_it->idx = 0xffu;
46315184528 q }
464127866036 q}
467void Set_Comparison::clear_nodes(Resource_Manager& rman, bool add_deletion_information)
46945781 q if (add_deletion_information)
47017833 q {
47117833 q std::vector< Node_Skeleton::Id_Type > searched_ids;
4728706033 q for (std::vector< Node_With_Context >::const_iterator it = nodes.begin(); it != nodes.end(); ++it)
4738688213 q {
4748688213 q if (it->idx.val() != 0xffu)
475907510 q searched_ids.push_back(it->elem.id);
4768688213 q }
47817833 q std::vector< Uint32_Index > req = get_indexes_< Uint32_Index, Node_Skeleton >(searched_ids, rman, true);
47917833 q std::vector< Node_Skeleton::Id_Type > found_ids
48017833 q = find_still_existing_skeletons< Uint32_Index, Node_Skeleton >(
48117833 q rman, rman.get_desired_timestamp(), req, searched_ids);
48217833 q std::map< Node_Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< Node::Id_Type > > found_meta
48317833 q = find_meta_elements< Node::Index, Node_Skeleton >(rman, rman.get_diff_to_timestamp(), req, searched_ids);
4858706033 q for (std::vector< Node_With_Context >::const_iterator it = nodes.begin(); it != nodes.end(); ++it)
4868688213 q {
4878688213 q if (it->idx.val() != 0xffu)
488907510 q {
489907510 q std::map< Node_Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< Node::Id_Type > >::const_iterator
490907510 q meta_it = found_meta.find(it->elem.id);
491907510 q result.different_nodes.push_back(std::make_pair(*it,
492907510 q Node_With_Context(std::binary_search(found_ids.begin(), found_ids.end(), it->elem.id) ? 0xfdu : 0xffu,
493907510 q Node_Skeleton(it->elem.id), 0,
494907510 q meta_it != found_meta.end() ? meta_it->second
495907510 q : OSM_Element_Metadata_Skeleton< Node_Skeleton::Id_Type >(),
496907510 q std::vector< std::pair< std::string, std::string > >())));
497907510 q }
4988688213 q }
50017833 q searched_ids.clear();
50117833 q for (std::vector< std::pair< Node_With_Context, Node_With_Context > >::const_iterator
50265032733 q it = result.different_nodes.begin(); it != result.different_nodes.end(); ++it)
50365014914 q {
50465014914 q if (it->first.idx.val() == 0xffu)
50561752914 q searched_ids.push_back(it->second.elem.id);
50665014914 q }
50817833 q get_indexes_< Uint32_Index, Node_Skeleton >(searched_ids, rman, true).swap(req);
50917833 q find_still_existing_skeletons< Uint32_Index, Node_Skeleton >(
51017833 q rman, rman.get_diff_from_timestamp(), req, searched_ids).swap(found_ids);
51117833 q find_meta_elements< Node::Index, Node_Skeleton >(
51217833 q rman, rman.get_diff_from_timestamp(), req, searched_ids).swap(found_meta);
51417833 q for (std::vector< std::pair< Node_With_Context, Node_With_Context > >::iterator
51565032733 q it = result.different_nodes.begin(); it != result.different_nodes.end(); ++it)
51665014914 q {
51765014914 q if (it->first.idx.val() == 0xffu)
51861752914 q {
51961752914 q it->first.idx = std::binary_search(found_ids.begin(), found_ids.end(), it->second.elem.id) ? 0xfdu : 0xffu;
52061752914 q it->first.elem = Node_Skeleton(it->second.elem.id);
52261752914 q std::map< Node_Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< Node::Id_Type > >::const_iterator
52361752914 q meta_it = found_meta.find(it->second.elem.id);
52461752914 q if (meta_it != found_meta.end())
5251336 q it->first.meta = meta_it->second;
52661752914 q }
52765014914 q }
52817833 q }
52927948 q else
53027948 q {
5319894448 q for (std::vector< Node_With_Context >::const_iterator it = nodes.begin(); it != nodes.end(); ++it)
5329866515 q {
5339866515 q if (it->idx.val() != 0xffu)
5342462711 q result.different_nodes.push_back(std::make_pair(*it,
5352462711 q Node_With_Context(0xffu, Node_Skeleton(it->elem.id), 0,
5362462711 q OSM_Element_Metadata_Skeleton< Node_Skeleton::Id_Type >(),
5372462711 q std::vector< std::pair< std::string, std::string > >())));
5389866515 q }
53927948 q }
54145781 q std::sort(result.different_nodes.begin(), result.different_nodes.end());
545void Set_Comparison::store_item(uint32 ll_upper, const Way_Skeleton& skel,
546 const std::vector< std::pair< std::string, std::string > >* tags,
547 const std::pair< Quad_Coord, Quad_Coord* >* bounds,
548 const std::vector< Quad_Coord >* geometry,
549 uint64 timestamp, const OSM_Element_Metadata_Skeleton< Way::Id_Type >* meta,
550 const std::map< uint32, std::string >* users, const Output_Handler::Feature_Action& action,
551 const OSM_Element_Metadata_Skeleton< Way::Id_Type >* new_meta)
5522679031 q{
5532679031 q ways.push_back(Way_With_Context(ll_upper, skel,
5542679031 q geometry ? *geometry : std::vector< Quad_Coord >(),
5552679031 q timestamp, meta ? *meta : OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type >(),
5562679031 q tags ? *tags : std::vector< std::pair< std::string, std::string > >()));
5572679031 q}
560void Set_Comparison::compare_item(uint32 ll_upper, const Way_Skeleton& skel,
561 const std::vector< std::pair< std::string, std::string > >* tags,
562 const std::pair< Quad_Coord, Quad_Coord* >* bounds,
563 const std::vector< Quad_Coord >* geometry,
564 uint64 timestamp, const OSM_Element_Metadata_Skeleton< Way::Id_Type >* meta,
565 const std::map< uint32, std::string >* users, const Output_Handler::Feature_Action& action,
566 const OSM_Element_Metadata_Skeleton< Way::Id_Type >* new_meta)
56722340441 q{
56822340441 q std::vector< Way_With_Context >::iterator ways_it
56922340441 q = std::lower_bound(ways.begin(), ways.end(),
57022340441 q Way_With_Context(ll_upper, skel, std::vector< Quad_Coord >(), timestamp));
57222340441 q if (ways_it == ways.end() || skel.id < ways_it->elem.id)
57320033139 q result.different_ways.push_back(std::make_pair(
57420033139 q Way_With_Context(0xffu, Way_Skeleton(skel.id),
57520033139 q std::vector< Quad_Coord >(),
57620033139 q 0, OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type >(),
57720033139 q std::vector< std::pair< std::string, std::string > >()),
57820033139 q Way_With_Context(ll_upper, skel,
57920033139 q geometry ? *geometry : std::vector< Quad_Coord >(),
58020033139 q timestamp, meta ? *meta : OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type >(),
58120033139 q tags ? *tags : std::vector< std::pair< std::string, std::string > >())));
5822307329 q else
5832307329 q {
5842307329 q if (!(ways_it->idx.val() == ll_upper) || !(ways_it->elem.nds == skel.nds) ||
5852307329 q (geometry && !(ways_it->geometry == *geometry)) ||
5862307329 q (tags && !(ways_it->tags == *tags)) || (meta && !(ways_it->meta.timestamp == meta->timestamp)))
5871644827 q result.different_ways.push_back(std::make_pair(*ways_it, Way_With_Context(ll_upper, skel,
5881644827 q geometry ? *geometry : std::vector< Quad_Coord >(),
5891644827 q timestamp, meta ? *meta : OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type >(),
5901644827 q tags ? *tags : std::vector< std::pair< std::string, std::string > >())));
5922307329 q ways_it->idx = 0xffu;
5932307329 q }
59422340441 q}
597void Set_Comparison::clear_ways(Resource_Manager& rman, bool add_deletion_information)
59945781 q if (add_deletion_information)
60017833 q {
60117833 q std::vector< Way_Skeleton::Id_Type > searched_ids;
6021493633 q for (std::vector< Way_With_Context >::const_iterator it = ways.begin(); it != ways.end(); ++it)
6031475814 q {
6041475814 q if (it->idx.val() != 0xffu)
605149711 q searched_ids.push_back(it->elem.id);
6061475814 q }
60817833 q std::vector< Uint31_Index > req = get_indexes_< Uint31_Index, Way_Skeleton >(searched_ids, rman, true);
60917833 q std::vector< Way_Skeleton::Id_Type > found_ids
61017833 q = find_still_existing_skeletons< Uint31_Index, Way_Skeleton >(
61117833 q rman, rman.get_desired_timestamp(), req, searched_ids);
61217833 q std::map< Way_Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< Way::Id_Type > > found_meta
61317833 q = find_meta_elements< Way::Index, Way_Skeleton >(rman, rman.get_diff_to_timestamp(), req, searched_ids);
6151493633 q for (std::vector< Way_With_Context >::const_iterator it = ways.begin(); it != ways.end(); ++it)
6161475814 q {
6171475814 q if (it->idx.val() != 0xffu)
618149711 q {
619149711 q std::map< Way_Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< Way::Id_Type > >::const_iterator
620149711 q meta_it = found_meta.find(it->elem.id);
621149711 q result.different_ways.push_back(std::make_pair(*it,
622149711 q Way_With_Context(std::binary_search(found_ids.begin(), found_ids.end(), it->elem.id) ? 0xfdu : 0xffu,
623149711 q Way_Skeleton(it->elem.id),
624149711 q std::vector< Quad_Coord >(),
625149711 q 0, meta_it != found_meta.end() ? meta_it->second
626149711 q : OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type >(),
627149711 q std::vector< std::pair< std::string, std::string > >())));
628149711 q }
6291475814 q }
63117833 q searched_ids.clear();
63217833 q for (std::vector< std::pair< Way_With_Context, Way_With_Context > >::const_iterator
63310734333 q it = result.different_ways.begin(); it != result.different_ways.end(); ++it)
63410716520 q {
63510716520 q if (it->first.idx.val() == 0xffu)
6369787119 q searched_ids.push_back(it->second.elem.id);
63710716520 q }
63917833 q get_indexes_< Uint31_Index, Way_Skeleton >(searched_ids, rman, true).swap(req);
64017833 q find_still_existing_skeletons< Uint31_Index, Way_Skeleton >(
64117833 q rman, rman.get_diff_from_timestamp(), req, searched_ids).swap(found_ids);
64217833 q find_meta_elements< Way::Index, Way_Skeleton >(
64317833 q rman, rman.get_diff_from_timestamp(), req, searched_ids).swap(found_meta);
64517833 q for (std::vector< std::pair< Way_With_Context, Way_With_Context > >::iterator
64610734333 q it = result.different_ways.begin(); it != result.different_ways.end(); ++it)
64710716520 q {
64810716520 q if (it->first.idx.val() == 0xffu)
6499787119 q {
6509787119 q it->first.idx = std::binary_search(found_ids.begin(), found_ids.end(), it->second.elem.id) ? 0xfdu : 0xffu;
6519787119 q it->first.elem = Way_Skeleton(it->second.elem.id);
6539787119 q std::map< Way_Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< Way::Id_Type > >::const_iterator
6549787119 q meta_it = found_meta.find(it->second.elem.id);
6559787119 q if (meta_it != found_meta.end())
656526 q it->first.meta = meta_it->second;
6579787119 q }
65810716520 q }
65917833 q }
66027948 q else
66127948 q {
6621231148 q for (std::vector< Way_With_Context >::const_iterator it = ways.begin(); it != ways.end(); ++it)
6631203217 q {
6641203217 q if (it->idx.val() != 0xffu)
665222013 q result.different_ways.push_back(std::make_pair(*it,
666222013 q Way_With_Context(0xffu, Way_Skeleton(it->elem.id),
667222013 q std::vector< Quad_Coord >(),
668222013 q 0, OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type >(),
669222013 q std::vector< std::pair< std::string, std::string > >())));
6701203217 q }
67127948 q }
67345781 q std::sort(result.different_ways.begin(), result.different_ways.end());
677void Set_Comparison::store_item(uint32 ll_upper, const Relation_Skeleton& skel,
678 const std::vector< std::pair< std::string, std::string > >* tags,
679 const std::pair< Quad_Coord, Quad_Coord* >* bounds,
680 const std::vector< std::vector< Quad_Coord > >* geometry,
681 uint64 timestamp, const OSM_Element_Metadata_Skeleton< Relation::Id_Type >* meta,
682 const std::map< uint32, std::string >* users, const Output_Handler::Feature_Action& action,
683 const OSM_Element_Metadata_Skeleton< Relation::Id_Type >* new_meta)
6841969 q{
6851969 q relations.push_back(Relation_With_Context(ll_upper, skel,
6861969 q geometry ? *geometry : std::vector< std::vector< Quad_Coord > >(),
6871969 q timestamp, meta ? *meta : OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type >(),
6881969 q tags ? *tags : std::vector< std::pair< std::string, std::string > >()));
6891969 q}
692void Set_Comparison::compare_item(uint32 ll_upper, const Relation_Skeleton& skel,
693 const std::vector< std::pair< std::string, std::string > >* tags,
694 const std::pair< Quad_Coord, Quad_Coord* >* bounds,
695 const std::vector< std::vector< Quad_Coord > >* geometry,
696 uint64 timestamp, const OSM_Element_Metadata_Skeleton< Relation::Id_Type >* meta,
697 const std::map< uint32, std::string >* users, const Output_Handler::Feature_Action& action,
698 const OSM_Element_Metadata_Skeleton< Relation::Id_Type >* new_meta)
70092615 q std::vector< Relation_With_Context >::iterator relations_it
70192615 q = std::lower_bound(relations.begin(), relations.end(),
70292615 q Relation_With_Context(ll_upper, skel, std::vector< std::vector< Quad_Coord > >(), 0));
70492615 q if (relations_it == relations.end() || skel.id < relations_it->elem.id)
70574813 q result.different_relations.push_back(std::make_pair(
70674813 q Relation_With_Context(0xffu, Relation_Skeleton(skel.id),
70774813 q std::vector< std::vector< Quad_Coord > >(),
70874813 q 0, OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type >(),
70974813 q std::vector< std::pair< std::string, std::string > >()),
71074813 q Relation_With_Context(ll_upper, skel,
71174813 q geometry ? *geometry : std::vector< std::vector< Quad_Coord > >(),
71274813 q timestamp, meta ? *meta : OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type >(),
71374813 q tags ? *tags : std::vector< std::pair< std::string, std::string > >())));
7141789 q else
7151789 q {
7161789 q if (!(relations_it->idx.val() == ll_upper) || !(relations_it->elem.members == skel.members) ||
7171789 q (geometry && !(relations_it->geometry == *geometry)) ||
7181789 q (tags && !(relations_it->tags == *tags)) || (meta && !(relations_it->meta.timestamp == meta->timestamp)))
7191629 q result.different_relations.push_back(std::make_pair(*relations_it, Relation_With_Context(ll_upper, skel,
7201629 q geometry ? *geometry : std::vector< std::vector< Quad_Coord > >(),
7211629 q timestamp, meta ? *meta : OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type >(),
7221629 q tags ? *tags : std::vector< std::pair< std::string, std::string > >())));
7241789 q relations_it->idx = 0xffu;
7251789 q }
729void Set_Comparison::clear_relations(Resource_Manager& rman, bool add_deletion_information)
73145781 q if (add_deletion_information)
73217833 q {
73317833 q std::vector< Relation_Skeleton::Id_Type > searched_ids;
73418833 q for (std::vector< Relation_With_Context >::const_iterator it = relations.begin(); it != relations.end(); ++it)
735101 q {
736101 q if (it->idx.val() != 0xffu)
7370 searched_ids.push_back(it->elem.id);
738101 q }
74017833 q std::vector< Uint31_Index > req = get_indexes_< Uint31_Index, Relation_Skeleton >(searched_ids, rman, true);
74117833 q std::vector< Relation_Skeleton::Id_Type > found_ids
74217833 q = find_still_existing_skeletons< Uint31_Index, Relation_Skeleton >(
74317833 q rman, rman.get_diff_to_timestamp(), req, searched_ids);
74417833 q std::map< Relation_Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< Relation::Id_Type > > found_meta
74517833 q = find_meta_elements< Relation::Index, Relation_Skeleton >(
74617833 q rman, rman.get_diff_to_timestamp(), req, searched_ids);
74818833 q for (std::vector< Relation_With_Context >::const_iterator it = relations.begin(); it != relations.end(); ++it)
749101 q {
750101 q if (it->idx.val() != 0xffu)
7510 {
7520 std::map< Relation_Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< Relation::Id_Type > >::const_iterator
7530 meta_it = found_meta.find(it->elem.id);
7540 result.different_relations.push_back(std::make_pair(*it,
7550 Relation_With_Context(std::binary_search(found_ids.begin(), found_ids.end(), it->elem.id) ? 0xfdu : 0xffu,
7560 Relation_Skeleton(it->elem.id),
7570 std::vector< std::vector< Quad_Coord > >(),
7580 0, meta_it != found_meta.end() ? meta_it->second
7590 : OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type >(),
7600 std::vector< std::pair< std::string, std::string > >())));
7610 }
763101 q req = get_indexes_< Uint31_Index, Relation_Skeleton >(searched_ids, rman, true);
764101 q }
76617833 q searched_ids.clear();
76717833 q for (std::vector< std::pair< Relation_With_Context, Relation_With_Context > >::const_iterator
76820733 q it = result.different_relations.begin(); it != result.different_relations.end(); ++it)
769293 q {
770293 q if (it->first.idx.val() == 0xffu)
771193 q searched_ids.push_back(it->second.elem.id);
772293 q }
77417833 q get_indexes_< Uint31_Index, Relation_Skeleton >(searched_ids, rman, true).swap(req);
77517833 q find_still_existing_skeletons< Uint31_Index, Relation_Skeleton >(
77617833 q rman, rman.get_diff_from_timestamp(), req, searched_ids).swap(found_ids);
77717833 q find_meta_elements< Relation::Index, Relation_Skeleton >(
77817833 q rman, rman.get_diff_from_timestamp(), req, searched_ids).swap(found_meta);
78017833 q for (std::vector< std::pair< Relation_With_Context, Relation_With_Context > >::iterator
78120733 q it = result.different_relations.begin(); it != result.different_relations.end(); ++it)
782293 q {
783293 q if (it->first.idx.val() == 0xffu)
784193 q {
785193 q it->first.idx = std::binary_search(found_ids.begin(), found_ids.end(), it->second.elem.id) ? 0xfdu : 0xffu;
786193 q it->first.elem = Relation_Skeleton(it->second.elem.id);
788193 q std::map< Relation_Skeleton::Id_Type, OSM_Element_Metadata_Skeleton< Relation::Id_Type > >::const_iterator
789193 q meta_it = found_meta.find(it->second.elem.id);
790193 q if (meta_it != found_meta.end())
7910 it->first.meta = meta_it->second;
792193 q }
793293 q }
79417833 q }
79527948 q else
79627948 q {
79746948 q for (std::vector< Relation_With_Context >::const_iterator it = relations.begin(); it != relations.end(); ++it)
7981908 q {
7991908 q if (it->idx.val() != 0xffu)
800233 q result.different_relations.push_back(std::make_pair(*it,
801233 q Relation_With_Context(0xffu, Relation_Skeleton(it->elem.id),
802233 q std::vector< std::vector< Quad_Coord > >(),
803233 q 0, OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type >(),
804233 q std::vector< std::pair< std::string, std::string > >())));
8051908 q }
80627948 q }
80845781 q std::sort(result.different_relations.begin(), result.different_relations.end());
812struct Derived_Structure_Handle
814 Derived_Structure_Handle(Uint31_Index idx, const Derived_Structure& elem_)
8152119 q : elem(&elem_), center(elem_.get_geometry() && elem_.get_geometry()->has_center() ?
8160 Point_Double(elem_.get_geometry()->center_lat(), elem_.get_geometry()->center_lon())
8172119 q : Point_Double(100., 0.)) {}
819 bool operator<(const Derived_Structure_Handle& rhs) const;
821 const Derived_Structure* elem;
822 Point_Double center;
823};
826int compare_geometry(const Opaque_Geometry& lhs_geom, const Opaque_Geometry& rhs_geom)
82841 q if (lhs_geom.has_center())
8290 {
8300 if (rhs_geom.has_center())
8310 {
8320 if (lhs_geom.center_lat() < rhs_geom.center_lat())
8330 return -1;
8340 if (rhs_geom.center_lat() < lhs_geom.center_lat())
8350 return 1;
8360 if (lhs_geom.center_lon() < rhs_geom.center_lon())
8370 return -1;
8380 if (rhs_geom.center_lon() < lhs_geom.center_lon())
8390 return 1;
8400 }
8410 else
8420 return -1;
8430 }
84441 q else if (rhs_geom.has_center())
8450 return 1;
84741 q if (lhs_geom.has_components())
84941 q if (rhs_geom.has_components())
85141 q const std::vector< Opaque_Geometry* >& lhs_comp = *lhs_geom.get_components();
85241 q const std::vector< Opaque_Geometry* >& rhs_comp = *rhs_geom.get_components();
85441 q if (lhs_comp.size() != rhs_comp.size())
8550 return lhs_comp.size() < rhs_comp.size() ? -1 : 1;
85741 q for (uint i = 0; i < lhs_comp.size(); ++i)
8580 {
8590 int cmp = compare_geometry(*lhs_comp[i], *rhs_comp[i]);
8600 if (cmp)
8610 return cmp;
8620 }
86441 q return 0;
8660 else
8670 return 1;
8690 else if (rhs_geom.has_components())
8700 return -1;
8720 if (lhs_geom.has_line_geometry())
8730 {
8740 if (rhs_geom.has_line_geometry())
8750 {
8760 const std::vector< Point_Double >& lhs_comp = *lhs_geom.get_line_geometry();
8770 const std::vector< Point_Double >& rhs_comp = *rhs_geom.get_line_geometry();
8790 if (lhs_comp.size() != rhs_comp.size())
8800 return lhs_comp.size() < rhs_comp.size() ? -1 : 1;
8820 for (uint i = 0; i < lhs_comp.size(); ++i)
8830 {
8840 if (lhs_comp[i] < rhs_comp[i])
8850 return -1;
8860 if (rhs_comp[i] < lhs_comp[i])
8870 return 1;
8880 }
8900 return 0;
8910 }
8920 else
8930 return -1;
8940 }
8950 else if (rhs_geom.has_line_geometry())
8960 return 1;
8980 if (lhs_geom.has_multiline_geometry())
8990 {
9000 if (rhs_geom.has_multiline_geometry())
9010 {
9020 const std::vector< std::vector< Point_Double > >& lhs_comp = *lhs_geom.get_multiline_geometry();
9030 const std::vector< std::vector< Point_Double > >& rhs_comp = *rhs_geom.get_multiline_geometry();
9050 if (lhs_comp.size() != rhs_comp.size())
9060 return lhs_comp.size() < rhs_comp.size() ? -1 : 1;
9080 for (uint i = 0; i < lhs_comp.size(); ++i)
9090 {
9100 if (lhs_comp[i].size() < rhs_comp[i].size())
9110 return -1;
9120 if (rhs_comp[i].size() < lhs_comp[i].size())
9130 return 1;
9150 for (uint j = 0; j < lhs_comp[i].size(); ++j)
9160 {
9170 if (lhs_comp[i][j] < rhs_comp[i][j])
9180 return -1;
9190 if (rhs_comp[i][j] < lhs_comp[i][j])
9200 return 1;
9210 }
9220 }
9240 return 0;
9250 }
9260 else
9270 return -1;
9280 }
9290 else if (rhs_geom.has_multiline_geometry())
9300 return 1;
9320 return 0;
9330}
936bool Derived_Structure_Handle::operator<(const Derived_Structure_Handle& rhs) const
93711639 q{
93811639 q if (center.lat < 100.)
9390 {
9400 if (rhs.center.lat < 100.)
9410 {
9420 if (center.lat != rhs.center.lat)
9430 return center.lat < rhs.center.lat;
9440 if (center.lon != rhs.center.lon)
9450 return center.lon < rhs.center.lon;
9460 }
9470 else
9480 return true;
9490 }
95011639 q else if (rhs.center.lat < 100.)
9510 return false;
95311639 q if (elem->get_geometry())
95541 q if (rhs.elem->get_geometry())
95741 q int cmp = compare_geometry(*elem->get_geometry(), *rhs.elem->get_geometry());
95841 q if (cmp < 0)
9590 return true;
96041 q else if (cmp > 0)
9610 return false;
9630 else
9640 return true;
96611599 q else if (rhs.elem->get_geometry())
9670 return false;
96911639 q std::vector< std::pair< std::string, std::string > >::const_iterator it_tl = elem->tags.begin();
97011639 q std::vector< std::pair< std::string, std::string > >::const_iterator it_tr = rhs.elem->tags.begin();
97116929 q while (it_tl != elem->tags.end() && it_tr != rhs.elem->tags.end())
97212439 q {
97312439 q if (*it_tl == *it_tr)
9745298 q {
9755298 q ++it_tl;
9765298 q ++it_tr;
9775298 q }
9787145 q else if (it_tl->first == "_next" || it_tl->first == "_previous")
9790 ++it_tl;
9807145 q else if (it_tr->first == "_next" || it_tr->first == "_previous")
9810 ++it_tr;
9827145 q else if (*it_tl < *it_tr)
9834474 q return true;
9842675 q else
9852675 q return false;
98612439 q }
9874498 q while (it_tl != elem->tags.end() && (it_tl->first == "_next" || it_tl->first == "_previous"))
9880 ++it_tl;
9894498 q while (it_tr != rhs.elem->tags.end() && (it_tr->first == "_next" || it_tr->first == "_previous"))
9900 ++it_tr;
9924498 q if (it_tr != rhs.elem->tags.end())
9930 return true;
9944498 q if (it_tl != elem->tags.end())
9950 return false;
9974498 q return false;
9984498 q}
1001void Set_Comparison::compute_deriveds(std::map< Uint31_Index, std::vector< Derived_Structure > > rhs_deriveds)
100344081 q std::vector< Derived_Structure_Handle > lhs_handles;
100444081 q for (std::map< Uint31_Index, std::vector< Derived_Structure > >::const_iterator
100546181 q it_idx = lhs_set_.deriveds.begin(); it_idx != lhs_set_.deriveds.end(); ++it_idx)
1007219 q for (std::vector< Derived_Structure >::const_iterator it_elem = it_idx->second.begin();
1008779 q it_elem != it_idx->second.end(); ++it_elem)
1009569 q lhs_handles.push_back(Derived_Structure_Handle(it_idx->first, *it_elem));
101144081 q std::sort(lhs_handles.begin(), lhs_handles.end());
101344081 q std::vector< Derived_Structure_Handle > rhs_handles;
101444081 q for (std::map< Uint31_Index, std::vector< Derived_Structure > >::const_iterator
101546181 q it_idx = rhs_deriveds.begin(); it_idx != rhs_deriveds.end(); ++it_idx)
1017219 q for (std::vector< Derived_Structure >::const_iterator it_elem = it_idx->second.begin();
10181769 q it_elem != it_idx->second.end(); ++it_elem)
10191559 q rhs_handles.push_back(Derived_Structure_Handle(it_idx->first, *it_elem));
102144081 q std::sort(rhs_handles.begin(), rhs_handles.end());
102344081 q std::vector< Derived_Structure_Handle >::const_iterator it_lhs = lhs_handles.begin();
102444081 q std::vector< Derived_Structure_Handle >::const_iterator it_rhs = rhs_handles.begin();
102658981 q while (it_lhs != lhs_handles.end() && it_rhs != rhs_handles.end())
10271499 q {
10281499 q if (*it_lhs < *it_rhs)
1030102 q result.lhs_deriveds.push_back(*it_lhs->elem);
1031102 q ++it_lhs;
10331399 q else if (*it_rhs < *it_lhs)
1035954 q result.rhs_deriveds.push_back(*it_rhs->elem);
1036954 q ++it_rhs;
1038448 q else
1040448 q ++it_lhs;
1041448 q ++it_rhs;
10431499 q }
104444281 q while (it_lhs != lhs_handles.end())
104621 q result.lhs_deriveds.push_back(*it_lhs->elem);
104721 q ++it_lhs;
104945681 q while (it_rhs != rhs_handles.end())
1051163 q result.rhs_deriveds.push_back(*it_rhs->elem);
1052163 q ++it_rhs;
1057Diff_Set Set_Comparison::compare_to_lhs(Resource_Manager& rman, const Statement& stmt,
1058 const Set& input_set, double south, double north, double west, double east, bool add_deletion_information)
106044081 q result.clear();
106244081 q uint64 rhs_timestamp = rman.get_desired_timestamp();
106344081 q rman.set_desired_timestamp(lhs_timestamp_);
106544081 q Extra_Data_For_Diff extra_data_lhs(rman, stmt, lhs_set_, Output_Mode::ID
106644081 q | Output_Mode::COORDS | Output_Mode::NDS | Output_Mode::MEMBERS
106744081 q | Output_Mode::TAGS | Output_Mode::VERSION | Output_Mode::META
106844081 q | Output_Mode::GEOMETRY, south, north, west, east);
107044081 q tags_quadtile(extra_data_lhs, lhs_set_.nodes, rman);
107144081 q if (rman.get_desired_timestamp() != NOW)
107244081 q tags_quadtile_attic(extra_data_lhs, lhs_set_.attic_nodes, rman);
107444081 q tags_quadtile(extra_data_lhs, lhs_set_.ways, rman);
107544081 q if (rman.get_desired_timestamp() != NOW)
107644081 q tags_quadtile_attic(extra_data_lhs, lhs_set_.attic_ways, rman);
107844081 q tags_quadtile(extra_data_lhs, lhs_set_.relations, rman);
107944081 q if (rman.get_desired_timestamp() != NOW)
108044081 q tags_quadtile_attic(extra_data_lhs, lhs_set_.attic_relations, rman);
108244081 q rman.set_desired_timestamp(rhs_timestamp);
108444081 q set_target(true);
108644081 q Extra_Data_For_Diff extra_data_rhs(rman, stmt, input_set, Output_Mode::ID
108744081 q | Output_Mode::COORDS | Output_Mode::NDS | Output_Mode::MEMBERS
108844081 q | Output_Mode::TAGS | Output_Mode::VERSION | Output_Mode::META
108944081 q | Output_Mode::GEOMETRY, south, north, west, east);
109144081 q tags_quadtile(extra_data_rhs, input_set.nodes, rman);
109244081 q if (rman.get_desired_timestamp() != NOW)
109314623 q tags_quadtile_attic(extra_data_rhs, input_set.attic_nodes, rman);
109444081 q clear_nodes(rman, add_deletion_information);
109644081 q tags_quadtile(extra_data_rhs, input_set.ways, rman);
109744081 q if (rman.get_desired_timestamp() != NOW)
109814623 q tags_quadtile_attic(extra_data_rhs, input_set.attic_ways, rman);
109944081 q clear_ways(rman, add_deletion_information);
110144081 q tags_quadtile(extra_data_rhs, input_set.relations, rman);
110244081 q if (rman.get_desired_timestamp() != NOW)
110314623 q tags_quadtile_attic(extra_data_rhs, input_set.attic_relations, rman);
110444081 q clear_relations(rman, add_deletion_information);
110644081 q compute_deriveds(input_set.deriveds);
110844081 q Diff_Set local_result;
110944081 q local_result.swap(result);
111044081 q return local_result;
1114template< typename A, typename B >
1115struct First_Comparator
1117 bool operator()(const std::pair< A, B >& lhs, const std::pair< A, B >& rhs)
111828975317 q {
111928975317 q return lhs.first < rhs.first;
112028975317 q }
1124template< typename Index, typename Id_Type, typename Maybe_Attic >
1125void eval_lhs_elems(const std::map< Index, std::vector< Maybe_Attic > >& items,
1126 std::vector< std::pair< Id_Type, std::string > >& result, Set_With_Context& into_context, Eval_Task& task)
112810217 q for (typename std::map< Index, std::vector< Maybe_Attic > >::const_iterator it_idx = items.begin();
1129120517 q it_idx != items.end(); ++it_idx)
1130110310 q {
1131110310 q for (typename std::vector< Maybe_Attic >::const_iterator it_elem = it_idx->second.begin();
11323021410 q it_elem != it_idx->second.end(); ++it_elem)
1133291117 q result.push_back(std::make_pair(
1134291117 q it_elem->id, task.eval(into_context.get_context(it_idx->first, *it_elem), 0)));
1135110310 q }
113710217 q std::sort(result.begin(), result.end(), First_Comparator< Id_Type, std::string >());
1141template< typename Index, typename Id_Type, typename Maybe_Attic >
1142void eval_rhs_elems(const std::map< Index, std::vector< Maybe_Attic > >& items,
1143 std::vector< std::pair< Id_Type, std::string > >& lhs_set, std::vector< Id_Type >& result,
1144 Set_With_Context& into_context, Eval_Task& task)
114610217 q for (typename std::map< Index, std::vector< Maybe_Attic > >::const_iterator it_idx = items.begin();
1147103817 q it_idx != items.end(); ++it_idx)
114993612 q for (typename std::vector< Maybe_Attic >::const_iterator it_elem = it_idx->second.begin();
115016547412 q it_elem != it_idx->second.end(); ++it_elem)
115116453811 q {
115216453811 q std::string rhs_val = task.eval(into_context.get_context(it_idx->first, *it_elem), 0);
115316453811 q typename std::vector< std::pair< Id_Type, std::string > >::iterator it_lhs =
115416453811 q std::lower_bound(lhs_set.begin(), lhs_set.end(), std::make_pair(it_elem->id, ""),
115516453811 q First_Comparator< Id_Type, std::string >());
115716453811 q if (it_lhs == lhs_set.end() || !(it_lhs->first == it_elem->id))
115814174211 q {
115914174211 q if (!rhs_val.empty())
116014170410 q result.push_back(it_elem->id);
116114174211 q }
1162227966 q else
1163227966 q {
1164227966 q if (rhs_val != it_lhs->second)
116518592 q result.push_back(it_elem->id);
1167227966 q it_lhs->second.clear();
1168227966 q }
116916453811 q }
1174template< typename Id_Type >
1175void clear_elems(std::vector< std::pair< Id_Type, std::string > >& lhs_set, std::vector< Id_Type >& result)
11775117 q for (typename std::vector< std::pair< Id_Type, std::string > >::const_iterator it_lhs = lhs_set.begin();
11782916217 q it_lhs != lhs_set.end(); ++it_lhs)
1179291117 q {
1180291117 q if (!it_lhs->second.empty())
118163124 q result.push_back(it_lhs->first);
1182291117 q }
11845117 q lhs_set.clear();
11855117 q std::sort(result.begin(), result.end());
1189template< typename Index, typename Id_Type, typename Maybe_Attic >
1190void filter_by_id(std::map< Index, std::vector< Maybe_Attic > >& items, const std::vector< Id_Type >& id_list)
119210217 q for (typename std::map< Index, std::vector< Maybe_Attic > >::iterator it_idx = items.begin();
1193120517 q it_idx != items.end(); ++it_idx)
1194110310 q {
1195110310 q std::vector< Maybe_Attic > result;
1196110310 q for (typename std::vector< Maybe_Attic >::const_iterator it_elem = it_idx->second.begin();
11973021410 q it_elem != it_idx->second.end(); ++it_elem)
1198291117 q {
1199291117 q if (std::binary_search(id_list.begin(), id_list.end(), it_elem->id))
120081714 q result.push_back(*it_elem);
1201291117 q }
1202110310 q result.swap(it_idx->second);
1203110310 q }
1207Diff_Set Set_Comparison::compare_to_lhs(Resource_Manager& rman, const Statement& stmt,
1208 const Set& input_set, Evaluator* evaluator, bool add_deletion_information)
12101717 q result.clear();
12121717 q uint64 rhs_timestamp = rman.get_desired_timestamp();
12131717 q rman.set_desired_timestamp(lhs_timestamp_);
12161717 q Requested_Context requested_context = evaluator->request_context();
12171717 q Prepare_Task_Context context(requested_context, stmt, rman);
12191717 q Owner< Eval_Task > task(evaluator->get_string_task(context, 0));
12211717 q Set_With_Context into_context;
12221717 q into_context.name = "";
12231717 q into_context.parent = &context;
12241717 q into_context.prefetch(requested_context.object_usage, lhs_set_, stmt, rman);
12261717 q if (task)
12281717 q node_values.clear();
12291717 q eval_lhs_elems(lhs_set_.nodes, node_values, into_context, *task);
12301717 q eval_lhs_elems(lhs_set_.attic_nodes, node_values, into_context, *task);
12321717 q way_values.clear();
12331717 q eval_lhs_elems(lhs_set_.ways, way_values, into_context, *task);
12341717 q eval_lhs_elems(lhs_set_.attic_ways, way_values, into_context, *task);
12361717 q relation_values.clear();
12371717 q eval_lhs_elems(lhs_set_.relations, relation_values, into_context, *task);
12381717 q eval_lhs_elems(lhs_set_.attic_relations, relation_values, into_context, *task);
12421717 q rman.set_desired_timestamp(rhs_timestamp);
12441717 q std::vector< Node_Skeleton::Id_Type > changed_nodes;
12451717 q std::vector< Way_Skeleton::Id_Type > changed_ways;
12461717 q std::vector< Relation_Skeleton::Id_Type > changed_relations;
12481717 q Requested_Context requested_context = evaluator->request_context();
12491717 q Prepare_Task_Context context(requested_context, stmt, rman);
12511717 q Owner< Eval_Task > task(evaluator->get_string_task(context, 0));
12531717 q Set_With_Context into_context;
12541717 q into_context.name = "";
12551717 q into_context.parent = &context;
12561717 q into_context.prefetch(requested_context.object_usage, input_set, stmt, rman);
12581717 q if (task)
12601717 q eval_rhs_elems(input_set.nodes, node_values, changed_nodes, into_context, *task);
12611717 q eval_rhs_elems(input_set.attic_nodes, node_values, changed_nodes, into_context, *task);
12621717 q clear_elems(node_values, changed_nodes);
12641717 q eval_rhs_elems(input_set.ways, way_values, changed_ways, into_context, *task);
12651717 q eval_rhs_elems(input_set.attic_ways, way_values, changed_ways, into_context, *task);
12661717 q clear_elems(way_values, changed_ways);
12681717 q eval_rhs_elems(input_set.relations, relation_values, changed_relations, into_context, *task);
12691717 q eval_rhs_elems(input_set.attic_relations, relation_values, changed_relations, into_context, *task);
12701717 q clear_elems(relation_values, changed_relations);
12741717 q rman.set_desired_timestamp(lhs_timestamp_);
12761717 q filter_by_id(lhs_set_.nodes, changed_nodes);
12771717 q filter_by_id(lhs_set_.attic_nodes, changed_nodes);
12781717 q filter_by_id(lhs_set_.ways, changed_ways);
12791717 q filter_by_id(lhs_set_.attic_ways, changed_ways);
12801717 q filter_by_id(lhs_set_.relations, changed_relations);
12811717 q filter_by_id(lhs_set_.attic_relations, changed_relations);
12831717 q Extra_Data_For_Diff extra_data_lhs(rman, stmt, lhs_set_, Output_Mode::ID
12841717 q | Output_Mode::COORDS | Output_Mode::NDS | Output_Mode::MEMBERS
12851717 q | Output_Mode::TAGS | Output_Mode::VERSION | Output_Mode::META
12861717 q | Output_Mode::GEOMETRY, 1., 0., 0., 0.);
12881717 q tags_quadtile(extra_data_lhs, lhs_set_.nodes, changed_nodes, rman);
12891717 q if (rman.get_desired_timestamp() != NOW)
12901717 q tags_quadtile_attic(extra_data_lhs, lhs_set_.attic_nodes, changed_nodes, rman);
12921717 q tags_quadtile(extra_data_lhs, lhs_set_.ways, changed_ways, rman);
12931717 q if (rman.get_desired_timestamp() != NOW)
12941717 q tags_quadtile_attic(extra_data_lhs, lhs_set_.attic_ways, changed_ways, rman);
12961717 q tags_quadtile(extra_data_lhs, lhs_set_.relations, changed_relations, rman);
12971717 q if (rman.get_desired_timestamp() != NOW)
12981717 q tags_quadtile_attic(extra_data_lhs, lhs_set_.attic_relations, changed_relations, rman);
13001717 q rman.set_desired_timestamp(rhs_timestamp);
13021717 q set_target(true);
13041717 q Extra_Data_For_Diff extra_data_rhs(rman, stmt, input_set, Output_Mode::ID
13051717 q | Output_Mode::COORDS | Output_Mode::NDS | Output_Mode::MEMBERS
13061717 q | Output_Mode::TAGS | Output_Mode::VERSION | Output_Mode::META
13071717 q | Output_Mode::GEOMETRY, 1., 0., 0., 0.);
13091717 q tags_quadtile(extra_data_rhs, input_set.nodes, changed_nodes, rman);
13101717 q if (rman.get_desired_timestamp() != NOW)
131177 q tags_quadtile_attic(extra_data_rhs, input_set.attic_nodes, changed_nodes, rman);
13121717 q clear_nodes(rman, add_deletion_information);
13141717 q tags_quadtile(extra_data_rhs, input_set.ways, changed_ways, rman);
13151717 q if (rman.get_desired_timestamp() != NOW)
131677 q tags_quadtile_attic(extra_data_rhs, input_set.attic_ways, changed_ways, rman);
13171717 q clear_ways(rman, add_deletion_information);
13191717 q tags_quadtile(extra_data_rhs, input_set.relations, changed_relations, rman);
13201717 q if (rman.get_desired_timestamp() != NOW)
132177 q tags_quadtile_attic(extra_data_rhs, input_set.attic_relations, changed_relations, rman);
13221717 q clear_relations(rman, add_deletion_information);
13241717 q Diff_Set local_result;
13251717 q local_result.swap(result);
13261717 q return local_result;