Overpass API regression suite coverage (Saxony) / overpass_api/data/collect_members.h

overpass_api/data/collect_members.h

473 of 500 instrumented lines run by the suite (94.6%) 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#ifndef DE__OSM3S___OVERPASS_API__DATA__COLLECT_MEMBERS_H
20#define DE__OSM3S___OVERPASS_API__DATA__COLLECT_MEMBERS_H
22#include "../core/datatypes.h"
23#include "../statements/statement.h"
24#include "abstract_processing.h"
25#include "collect_items.h"
26#include "filenames.h"
28#include <map>
29#include <set>
30#include <vector>
33class Resource_Manager;
34class Statement;
37Timeless< Uint31_Index, Relation_Skeleton > relation_relation_members
38 (Request_Context& context,
39 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& parents,
40 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_parents,
41 const Ranges< Uint31_Index >& children_ranges,
42 const std::vector< Relation::Id_Type >& children_ids, bool invert_ids, const uint32* role_id = 0);
44Timeless< Uint31_Index, Way_Skeleton > relation_way_members
45 (Request_Context& context,
46 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& relations,
47 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_relations,
48 const Ranges< Uint31_Index >& way_ranges,
49 const std::vector< Way::Id_Type >& way_ids, bool invert_ids, const uint32* role_id = 0);
51std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > > relation_way_members
52 (Request_Context& context,
53 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& relations,
54 const Ranges< Uint31_Index >& way_ranges);
56Timeless< Uint32_Index, Node_Skeleton > relation_node_members
57 (Request_Context& context,
58 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& relations,
59 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_relations,
60 const Ranges< Uint32_Index >& node_ranges,
61 const std::vector< Node::Id_Type >& node_ids, bool invert_ids = false, const uint32* role_id = 0);
63std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > > relation_node_members
64 (Request_Context& context,
65 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& relations,
66 const Ranges< Uint32_Index >& node_ranges);
68Timeless< Uint32_Index, Node_Skeleton > way_members(
69 Request_Context& context,
70 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,
71 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways,
72 const std::vector< int >* pos,
73 const Ranges< Uint32_Index >& node_ranges,
74 const std::vector< Node::Id_Type >& node_ids, bool invert_ids = false);
76Timeless< Uint32_Index, Node_Skeleton > way_cnt_members(
77 Request_Context& context,
78 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,
79 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways,
80 unsigned int lower_limit, unsigned int upper_limit,
81 const Ranges< Uint32_Index >& node_ranges,
82 const std::vector< Node::Id_Type >& node_ids, bool invert_ids = false);
84Timeless< Uint32_Index, Node_Skeleton > way_link_members(
85 Request_Context& context,
86 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,
87 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways,
88 unsigned int lower_limit, unsigned int upper_limit,
89 const Ranges< Uint32_Index >& node_ranges,
90 const std::vector< Node::Id_Type >& node_ids, bool invert_ids = false);
92template< typename Relation_Skeleton >
93std::vector< Node::Id_Type > relation_node_member_ids
94 (const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& rels,
95 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels,
96 const uint32* role_id = 0);
98std::vector< Relation::Id_Type > relation_relation_member_ids(
99 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& rels,
100 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels,
101 const uint32* role_id = 0);
103std::vector< Node::Id_Type > way_nd_ids(
104 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,
105 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways,
106 const std::vector< int >* pos);
108std::vector< Node::Id_Type > way_cnt_nd_ids(
109 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,
110 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways,
111 unsigned int lower_limit, unsigned int upper_limit);
113std::vector< Node::Id_Type > way_link_nd_ids(
114 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,
115 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways,
116 unsigned int lower_limit, unsigned int upper_limit);
118const std::map< uint32, std::string >& relation_member_roles(Transaction& transaction);
119uint32 determine_role_id(Transaction& transaction, const std::string& role);
122bool add_way_to_area_blocks(const std::vector< Quad_Coord >& coords,
123 uint32 id, std::map< Uint31_Index, std::vector< Area_Block > >& areas);
126std::vector< Quad_Coord > make_geometry(const Way_Skeleton& way, const std::vector< Node >& nodes);
129void filter_ways_by_ranges(std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,
130 const Ranges< Uint31_Index >& ranges);
131void filter_ways_by_ranges(std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& ways,
132 const Ranges< Uint31_Index >& ranges);
135template< typename Relation_Skeleton >
136void filter_relations_by_ranges(
137 std::map< Uint31_Index, std::vector< Relation_Skeleton > >& relations, const Ranges< Uint31_Index >& ranges)
1391038376 q auto ranges_it = ranges.begin();
1401038376 q typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::iterator it = relations.begin();
14140120376 q for (; it != relations.end() && ranges_it != ranges.end(); )
14239082139 q {
14339082139 q if (!(it->first < ranges_it.upper_bound()))
14415730135 q ++ranges_it;
14523352138 q else if (!(it->first < ranges_it.lower_bound()))
14623339137 q ++it;
147132 q else
148132 q {
149132 q it->second.clear();
150132 q ++it;
151132 q }
15239082139 q }
1531053376 q for (; it != relations.end(); ++it)
154153 q it->second.clear();
158//-----------------------------------------------------------------------------
161template < typename Index, typename Skeleton >
162Timeless< Index, Skeleton > get_elements_from_db(
163 const Ranges< Index >& ranges, const Statement& query, Resource_Manager& rman)
1654843 q Request_Context context(&query, rman);
1664843 q return collect_items_range< Index, Skeleton >(context, ranges, Trivial_Predicate< Skeleton >());
170template < typename Index, typename Object >
171class Collect_Items
173public:
174 Collect_Items(
175 const std::vector< typename Object::Id_Type >& ids_, bool invert_ids_,
176 const Ranges< Index >& ranges_,
177 const Statement& query_, Resource_Manager& rman_)
178956500 q : ids(&ids_), invert_ids(invert_ids_), ranges(ranges_), query(&query_), rman(&rman_),
179956500 q min_idx(ranges_.empty() ? Index() : ranges_.begin().lower_bound()) {}
181 bool get_chunk(
182 std::map< Index, std::vector< Object > >& elements,
183 std::map< Index, std::vector< Attic< Object > > >& attic_elements);
185private:
186 const std::vector< typename Object::Id_Type >* ids;
187 bool invert_ids;
188 Ranges< Index > ranges;
189 const Statement* query;
190 Resource_Manager* rman;
191 Index min_idx;
192};
195template < typename Index, typename Object, typename Predicate >
196bool get_elements_by_id_from_db_generic(
197 std::map< Index, std::vector< Object > >& elements,
198 std::map< Index, std::vector< Attic< Object > > >& attic_elements,
199 const Predicate& pred,
200 const Ranges< Index >& ranges, Index& cur_idx,
201 const Statement& query, Resource_Manager& rman)
203960500 q if (ranges.empty())
2042116 q return false;
205939499 q Request_Context context(&query, rman);
206939499 q return collect_items_range(context, ranges, pred, cur_idx, elements, attic_elements);
210template < typename Index, typename Object >
211bool Collect_Items< Index, Object >::get_chunk(
212 std::map< Index, std::vector< Object > >& elements,
213 std::map< Index, std::vector< Attic< Object > > >& attic_elements)
215960500 q elements.clear();
216960500 q attic_elements.clear();
217960500 q if (invert_ids)
219578300 q if (ids->empty())
220573298 q return get_elements_by_id_from_db_generic(
221573298 q elements, attic_elements, Trivial_Predicate< Object >(), ranges, min_idx, *query, *rman);
22253 q else
22353 q return get_elements_by_id_from_db_generic(
22453 q elements, attic_elements, Not_Predicate< Object, Id_Predicate< Object > >(Id_Predicate< Object >(*ids)),
22553 q ranges, min_idx, *query, *rman);
227382252 q return get_elements_by_id_from_db_generic(
228382252 q elements, attic_elements, Id_Predicate< Object >(*ids), ranges, min_idx, *query, *rman);
232template< typename Index, typename Skeleton >
233void filter_attic_elements
234 (Resource_Manager& rman, uint64 timestamp,
235 std::map< Index, std::vector< Skeleton > >& current,
236 std::map< Index, std::vector< Attic< Skeleton > > >& attic)
23780947621 q{
23880947621 q if (timestamp != NOW)
23978709280 q {
24078709280 q std::vector< Index > idx_set;
24178709280 q for (typename std::map< Index, std::vector< Skeleton > >::const_iterator it = current.begin();
242443382280 q it != current.end(); ++it)
243364673263 q idx_set.push_back(it->first);
24478709280 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::const_iterator it = attic.begin();
245439447280 q it != attic.end(); ++it)
246360738263 q idx_set.push_back(it->first);
24778709280 q std::sort(idx_set.begin(), idx_set.end());
24878709280 q idx_set.erase(std::unique(idx_set.begin(), idx_set.end()), idx_set.end());
250 // Remove elements that have been deleted at the given point of time
25178709280 q std::map< Index, std::vector< typename Skeleton::Id_Type > > deleted_items;
25378709280 q Block_Backend< Index, Attic< typename Skeleton::Id_Type >, typename std::vector< Index >::const_iterator >
25478709280 q undeleted_db(rman.get_transaction()->data_index(attic_undeleted_file_properties< Skeleton >()));
25578709280 q for (auto it = undeleted_db.discrete_begin(idx_set.begin(), idx_set.end());
2563179655280 q !(it == undeleted_db.discrete_end()); ++it)
2573100946258 q {
2583100946258 q if (it.object().timestamp <= timestamp)
2592029629242 q continue;
2611071317247 q typename std::map< Index, std::vector< Skeleton > >::iterator cit = current.find(it.index());
2621071317247 q if (cit != current.end())
2631068192245 q {
264202457326245 q for (typename std::vector< Skeleton >::iterator it2 = cit->second.begin(); it2 != cit->second.end(); )
265201389134202 q {
266201389134202 q if (it2->id == it.object())
26720168148 q {
26820168148 q *it2 = cit->second.back();
26920168148 q cit->second.pop_back();
27020168148 q }
271201368966200 q else
272201368966200 q ++it2;
273201389134202 q }
2741068192245 q }
2761071317247 q typename std::map< Index, std::vector< Attic< Skeleton > > >::iterator ait = attic.find(it.index());
2771071317247 q if (ait != attic.end())
2781065660246 q {
2791065660246 q for (typename std::vector< Attic< Skeleton > >::iterator it2 = ait->second.begin();
280331993645246 q it2 != ait->second.end(); )
281330927985217 q {
282330927985217 q if (it2->id == it.object() && it.object().timestamp < it2->timestamp)
283212411159 q {
284212411159 q *it2 = ait->second.back();
285212411159 q ait->second.pop_back();
286212411159 q }
287330715574216 q else
288330715574216 q ++it2;
289330927985217 q }
2901065660246 q }
2911071317247 q }
294 // Confirm elements that are backed by meta data
295 // Update element's expiration timestamp if a meta exists that is older than the current
296 // expiration date and younger than timestamp
29778709280 q std::map< Index, std::map< typename Skeleton::Id_Type, std::pair< uint64, uint64 > > >
29878709280 q timestamp_by_id_by_idx;
29978709280 q for (typename std::map< Index, std::vector< Skeleton > >::const_iterator it = current.begin();
300443382280 q it != current.end(); ++it)
301364673263 q {
302364673263 q std::map< typename Skeleton::Id_Type, std::pair< uint64, uint64 > >& entry
303364673263 q = timestamp_by_id_by_idx[it->first];
304364673263 q for (typename std::vector< Skeleton >::const_iterator it2 = it->second.begin();
3055212198263 q it2 != it->second.end(); ++it2)
3064847525217 q entry[it2->id] = std::make_pair(0, NOW);
307364673263 q }
30878709280 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::const_iterator it = attic.begin();
309439447280 q it != attic.end(); ++it)
310360738263 q {
311360738263 q std::map< typename Skeleton::Id_Type, std::pair< uint64, uint64 > >& entry
312360738263 q = timestamp_by_id_by_idx[it->first];
313360738263 q for (typename std::vector< Attic< Skeleton > >::const_iterator it2 = it->second.begin();
3142049308263 q it2 != it->second.end(); ++it2)
3151688570234 q entry[it2->id] = std::make_pair(0, it2->timestamp);
316360738263 q }
31878709280 q Block_Backend< Index, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type >,
31978709280 q typename std::vector< Index >::const_iterator >
32078709280 q attic_meta_db(rman.get_transaction()->data_index
32178709280 q (attic_meta_file_properties< Skeleton >()));
32278709280 q for (auto it = attic_meta_db.discrete_begin(idx_set.begin(), idx_set.end());
323100475689280 q !(it == attic_meta_db.discrete_end()); ++it)
324100396980263 q {
325100396980263 q auto tit = timestamp_by_id_by_idx[it.index()].find(it.object().ref);
326100396980263 q if (tit != timestamp_by_id_by_idx[it.index()].end())
32712253949240 q {
32812253949240 q if (timestamp < it.object().timestamp)
3295148074221 q tit->second.second = std::min(tit->second.second, it.object().timestamp);
3307105875217 q else
3317105875217 q tit->second.first = std::max(tit->second.first, it.object().timestamp);
33212253949240 q }
333100396980263 q }
335 // Same thing with current meta data
33678709280 q Block_Backend< Index, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type >,
33778709280 q typename std::vector< Index >::const_iterator >
33878709280 q meta_db(rman.get_transaction()->data_index
33978709280 q (current_meta_file_properties< Skeleton >()));
34178709280 q for (auto it = meta_db.discrete_begin(idx_set.begin(), idx_set.end());
34276092202280 q !(it == meta_db.discrete_end()); ++it)
34376013493252 q {
34476013493252 q auto tit = timestamp_by_id_by_idx[it.index()].find(it.object().ref);
34576013493252 q if (tit != timestamp_by_id_by_idx[it.index()].end())
3466128821246 q {
3476128821246 q if (timestamp < it.object().timestamp)
3483300252234 q tit->second.second = std::min(tit->second.second, it.object().timestamp);
3492828569187 q else
3502828569187 q tit->second.first = std::max(tit->second.first, it.object().timestamp);
3516128821246 q }
35276013493252 q }
354 // Filter current: only keep elements that have already existed at timestamp
35578709280 q for (typename std::map< Index, std::vector< Skeleton > >::iterator it = current.begin();
356443382280 q it != current.end(); ++it)
357364673263 q {
358364673263 q std::vector< Skeleton > result;
359364673263 q std::map< typename Skeleton::Id_Type, std::pair< uint64, uint64 > >& entry
360364673263 q = timestamp_by_id_by_idx[it->first];
362364673263 q for (typename std::vector< Skeleton >::const_iterator it2 = it->second.begin();
3635212198263 q it2 != it->second.end(); ++it2)
3644847525217 q {
3654847525217 q if (entry[it2->id].first > 0)
3662933653186 q {
3672933653186 q if (entry[it2->id].second == NOW)
3682776154177 q result.push_back(*it2);
369157499150 q else
370157499150 q attic[it->first].push_back(Attic< Skeleton >(*it2, entry[it2->id].second));
3712933653186 q }
3724847525217 q }
374364673263 q result.swap(it->second);
375364673263 q }
377 // Filter attic: only keep elements that have already existed at timestamp
37878709280 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::iterator it = attic.begin();
379439573280 q it != attic.end(); ++it)
380360864264 q {
381360864264 q std::vector< Attic< Skeleton > > result;
382360864264 q std::map< typename Skeleton::Id_Type, std::pair< uint64, uint64 > >& entry
383360864264 q = timestamp_by_id_by_idx[it->first];
385360864264 q for (typename std::vector< Attic< Skeleton > >::const_iterator it2 = it->second.begin();
3862206933264 q it2 != it->second.end(); ++it2)
3871846069237 q {
3881846069237 q if (entry[it2->id].first > 0)
389985019213 q {
390985019213 q result.push_back(*it2);
391985019213 q result.back().timestamp = entry[it2->id].second;
392985019213 q }
3931846069237 q }
395360864264 q result.swap(it->second);
396360864264 q }
39778709280 q }
39880947621 q}
401//-----------------------------------------------------------------------------
404template< typename Ref_Type, typename Relation_Skeleton >
405void filter_for_member_ids(const std::vector< Relation_Skeleton >& relations,
406 std::vector< Ref_Type >& ids, uint32 type)
407152339190 q{
408152339190 q for (typename std::vector< Relation_Skeleton >::const_iterator it2(relations.begin());
409540771190 q it2 != relations.end(); ++it2)
410388432169 q {
411388432169 q for (std::vector< Relation_Entry >::const_iterator it3(it2->members.begin());
41282717213169 q it3 != it2->members.end(); ++it3)
41382328781169 q {
41482328781169 q if (it3->type == type)
41539418077169 q ids.push_back(Ref_Type(it3->ref.val()));
41682328781169 q }
417388432169 q }
418152339190 q}
421template< typename Ref_Type, typename Relation_Skeleton >
422void filter_for_member_ids(const std::vector< Relation_Skeleton >& relations,
423 std::vector< Ref_Type >& ids, uint32 type, uint32 role_id)
42472896 q{
42572896 q for (typename std::vector< Relation_Skeleton >::const_iterator it2(relations.begin());
426305256 q it2 != relations.end(); ++it2)
427232366 q {
428232366 q for (std::vector< Relation_Entry >::const_iterator it3(it2->members.begin());
42919268406 q it3 != it2->members.end(); ++it3)
43019036046 q {
43119036046 q if (it3->type == type && it3->role == role_id)
432421 q ids.push_back(Ref_Type(it3->ref.val()));
43319036046 q }
434232366 q }
43572896 q}
438template< typename Relation_Skeleton >
439std::vector< Node::Id_Type > relation_node_member_ids
440 (const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& rels,
441 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels,
442 const uint32* role_id)
44328099473 q{
44428099473 q std::vector< Node::Id_Type > ids;
44528099473 q if (role_id)
447203 q for (auto it = rels.begin(); it != rels.end(); ++it)
448151 q filter_for_member_ids(it->second, ids, Relation_Entry::NODE, *role_id);
45028094472 q else
45128094472 q {
45296230472 q for (auto it = rels.begin(); it != rels.end(); ++it)
45368136183 q filter_for_member_ids(it->second, ids, Relation_Entry::NODE);
45428094472 q }
45628099473 q if (role_id)
458513 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it)
459461 q filter_for_member_ids(it->second, ids, Relation_Entry::NODE, *role_id);
46128094472 q else
46228094472 q {
46332100472 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it)
464400639 q filter_for_member_ids(it->second, ids, Relation_Entry::NODE);
46528094472 q }
46728099473 q sort(ids.begin(), ids.end());
46828099473 q ids.erase(unique(ids.begin(), ids.end()), ids.end());
47028099473 q return ids;
47128099473 q}
474inline std::vector< Way::Id_Type > relation_way_member_ids
475 (const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& rels,
476 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels,
477 const uint32* role_id = 0)
47828110477 q{
47928110477 q std::vector< Way::Id_Type > ids;
48028110477 q if (role_id)
481107 q {
48267477 q for (auto it = rels.begin(); it != rels.end(); ++it)
48367373 q filter_for_member_ids(it->second, ids, Relation_Entry::WAY, *role_id);
484107 q }
48528100474 q else
48628100474 q {
48769748474 q for (auto it = rels.begin(); it != rels.end(); ++it)
48841648181 q filter_for_member_ids(it->second, ids, Relation_Entry::WAY);
48928100474 q }
49128110477 q if (role_id)
492107 q {
4934077 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it)
4943972 q filter_for_member_ids(it->second, ids, Relation_Entry::WAY, *role_id);
495107 q }
49628100474 q else
49728100474 q {
49857164474 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it)
4992906473 q filter_for_member_ids(it->second, ids, Relation_Entry::WAY);
50028100474 q }
50228110477 q sort(ids.begin(), ids.end());
50328110477 q ids.erase(unique(ids.begin(), ids.end()), ids.end());
50528110477 q return ids;
50628110477 q}
509template< typename Index, typename Skeleton >
510void keep_matching_skeletons
511 (std::map< Index, std::vector< Skeleton > >& current,
512 std::map< Index, std::vector< Attic< Skeleton > > >& attic,
513 uint64 timestamp)
51479195489 q{
51579195489 q if (timestamp == NOW)
5161071325 q {
5171071325 q attic.clear();
5181071325 q return;
5191071325 q }
52178124222 q std::map< typename Skeleton::Id_Type, uint64 > timestamp_by_id;
523141008222 q for (auto it = current.begin(); it != current.end(); ++it)
5246288454 q {
52547675054 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
52641386650 q timestamp_by_id[it2->id] = NOW;
5276288454 q }
529132997222 q for (auto it = attic.begin(); it != attic.end(); ++it)
5305487354 q {
53113541354 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
5328054028 q {
5338054028 q uint64& stored_timestamp = timestamp_by_id[it2->id];
5348054028 q if (it2->timestamp > timestamp && (stored_timestamp == 0 || stored_timestamp > it2->timestamp))
5358037628 q stored_timestamp = it2->timestamp;
5368054028 q }
5375487354 q }
539141008222 q for (auto it = current.begin(); it != current.end(); ++it)
5406288454 q {
5416288454 q std::vector< Skeleton > local_into;
54247675054 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
54341386650 q {
54441386650 q if (timestamp_by_id[it2->id] == NOW)
54541311750 q local_into.push_back(*it2);
54641386650 q }
5476288454 q local_into.swap(it->second);
5486288454 q }
550132997222 q for (auto it = attic.begin(); it != attic.end(); ++it)
5515487354 q {
5525487354 q std::vector< Attic< Skeleton > > local_into;
55313541354 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
5548054028 q {
5558054028 q if (timestamp_by_id[it2->id] == it2->timestamp)
5568022928 q local_into.push_back(*it2);
5578054028 q }
5585487354 q local_into.swap(it->second);
5595487354 q }
56078124222 q}
563template< typename Index, typename Skeleton >
564void keep_matching_skeletons
565 (std::map< Index, std::vector< Attic< Skeleton > > >& result,
566 const std::map< Index, std::vector< Skeleton > >& current,
567 const std::map< Index, std::vector< Attic< Skeleton > > >& attic,
568 uint64 timestamp)
570930181 q std::map< typename Skeleton::Id_Type, uint64 > timestamp_by_id;
572930181 q result.clear();
57446427181 q for (auto it = current.begin(); it != current.end(); ++it)
5754549748 q {
5768427548 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
5773877844 q timestamp_by_id[it2->id] = NOW;
5784549748 q }
58046427181 q for (auto it = attic.begin(); it != attic.end(); ++it)
5814549748 q {
5824549748 q for (typename std::vector< Attic< Skeleton > >::const_iterator it2 = it->second.begin();
5838143748 q it2 != it->second.end(); ++it2)
5843594048 q {
5853594048 q uint64& stored_timestamp = timestamp_by_id[it2->id];
5863594048 q if (it2->timestamp > timestamp && (stored_timestamp == 0 || stored_timestamp > it2->timestamp))
5873497648 q stored_timestamp = it2->timestamp;
5883594048 q }
5894549748 q }
59146427181 q for (auto it = current.begin(); it != current.end(); ++it)
5924549748 q {
5938427548 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
5943877844 q {
5953877844 q if (timestamp_by_id[it2->id] == NOW)
5963801744 q result[it->first].push_back(Attic< Skeleton >(*it2, NOW));
5973877844 q }
5984549748 q }
60046427181 q for (auto it = attic.begin(); it != attic.end(); ++it)
6014549748 q {
6028143748 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
6033594048 q {
6043594048 q if (timestamp_by_id[it2->id] == it2->timestamp)
6053449748 q result[it->first].push_back(Attic< Skeleton >(*it2, it2->timestamp));
6063594048 q }
6074549748 q }
611void keep_matching_skeletons
612 (std::vector< Node >& result,
613 const std::map< Uint32_Index, std::vector< Node_Skeleton > >& current,
614 const std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >& attic,
615 uint64 timestamp);
618template< typename TIndex, typename TObject >
619void item_filter_map
620 (std::map< TIndex, std::vector< TObject > >& modify,
621 const std::map< TIndex, std::vector< TObject > >& read)
62387696 q for (typename std::map< TIndex, std::vector< TObject > >::iterator it = modify.begin();
6243503696 q it != modify.end(); ++it)
6253416059 q {
6263416059 q sort(it->second.begin(), it->second.end());
6273416059 q typename std::map< TIndex, std::vector< TObject > >::const_iterator
6283416059 q from_it = read.find(it->first);
6293416059 q if (from_it == read.end())
6300 {
6310 it->second.clear();
6320 continue;
6330 }
6343416059 q std::vector< TObject > local_into;
6353416059 q for (typename std::vector< TObject >::const_iterator iit = from_it->second.begin();
63633492059 q iit != from_it->second.end(); ++iit)
63730076059 q {
63830076059 q if (std::binary_search(it->second.begin(), it->second.end(), *iit))
63929954559 q local_into.push_back(*iit);
64030076059 q }
6413416059 q it->second.swap(local_into);
6423416059 q }
646template< typename First, typename Second >
647void swap_components(std::pair< First, Second > pair, First& first, Second& second)
649 first.swap(pair.first);
650 second.swap(pair.second);
654template< typename Index, typename Skeleton, typename Order_By_Id >
655std::vector< std::pair< Index, const Skeleton* > > order_by_id
656 (const std::map< Index, std::vector< Skeleton > >& skels,
657 const Order_By_Id& order_by_id)
6591116372 q std::vector< std::pair< Index, const Skeleton* > > skels_by_id;
6601116372 q for (typename std::map< Index, std::vector< Skeleton > >::const_iterator it = skels.begin();
66164638372 q it != skels.end(); ++it)
66263522113 q {
66363522113 q for (typename std::vector< Skeleton >::const_iterator iit = it->second.begin();
664360015113 q iit != it->second.end(); ++iit)
665296493101 q skels_by_id.push_back(std::make_pair(it->first, &*iit));
66663522113 q }
6671116372 q sort(skels_by_id.begin(), skels_by_id.end(), order_by_id);
6691116372 q return skels_by_id;
673template< typename Index, typename Skeleton, typename Order_By_Id >
674std::vector< std::pair< Index, const Skeleton* > > order_attic_by_id
675 (const std::map< Index, std::vector< Attic< Skeleton > > >& skels,
676 const Order_By_Id& order_by_id)
678250110 q std::vector< std::pair< Index, const Skeleton* > > skels_by_id;
679250110 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::const_iterator it = skels.begin();
6808311110 q it != skels.end(); ++it)
681806141 q {
682806141 q for (typename std::vector< Attic< Skeleton > >::const_iterator iit = it->second.begin();
6833988341 q iit != it->second.end(); ++iit)
6843182241 q skels_by_id.push_back(std::make_pair(it->first, &*iit));
685806141 q }
686250110 q sort(skels_by_id.begin(), skels_by_id.end(), order_by_id);
688250110 q return skels_by_id;
692template< typename Relation_Skeleton >
693void filter_relations_expensive(const std::vector< std::pair< Uint32_Index, const Node_Skeleton* > > node_members_by_id,
694 const std::vector< std::pair< Uint31_Index, const Way_Skeleton* > > way_members_by_id,
695 std::map< Uint31_Index, std::vector< Relation_Skeleton > >& relations)
69713390 q for (typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::iterator it = relations.begin();
698772290 q it != relations.end(); ++it)
699758940 q {
700758940 q std::vector< Relation_Skeleton > local_into;
701758940 q for (typename std::vector< Relation_Skeleton >::const_iterator iit = it->second.begin();
7026049840 q iit != it->second.end(); ++iit)
7035290936 q {
7045290936 q for (std::vector< Relation_Entry >::const_iterator nit = iit->members.begin();
705985508836 q nit != iit->members.end(); ++nit)
706980620036 q {
707980620036 q if (nit->type == Relation_Entry::NODE)
70844174033 q {
70944174033 q const std::pair< Uint32_Index, const Node_Skeleton* >* second_nd =
71044174033 q binary_search_for_pair_id(node_members_by_id, nit->ref);
71144174033 q if (second_nd)
712130722 q {
713130722 q local_into.push_back(*iit);
714130722 q break;
715130722 q }
71644174033 q }
717936446036 q else if (nit->type == Relation_Entry::WAY)
718933473336 q {
719933473336 q const std::pair< Uint31_Index, const Way_Skeleton* >* second_nd =
720933473336 q binary_search_for_pair_id(way_members_by_id, nit->ref32());
721933473336 q if (second_nd)
722271430 q {
723271430 q local_into.push_back(*iit);
724271430 q break;
725271430 q }
726933473336 q }
727980620036 q }
7285290936 q }
729758940 q it->second.swap(local_into);
730758940 q }
734Ranges< Uint31_Index > collect_way_req(
735 const std::vector< Uint31_Index >& parents,
736 const std::vector< Uint31_Index >& children_idxs);
739Ranges< Uint31_Index > relation_way_member_indices
740 (const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& current_rels,
741 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels);
744Ranges< Uint32_Index > calc_node_children_ranges(const std::vector< uint32 >& way_rel_idxs);
747Ranges< Uint32_Index > relation_node_member_indices(
748 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& current_rels,
749 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels);
752Ranges< Uint32_Index > way_nd_indices(
753 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,
754 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways);
757Ranges< Uint32_Index > way_covered_indices(
758 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,
759 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways);
762struct Order_By_Node_Id
764 bool operator() (const std::pair< Uint32_Index, const Node_Skeleton* >& a,
765 const std::pair< Uint32_Index, const Node_Skeleton* >& b)
76695318992 q {
76795318992 q return (a.second->id < b.second->id);
76895318992 q }
769};
772struct Order_By_Way_Id
774 bool operator() (const std::pair< Uint31_Index, const Way_Skeleton* >& a,
775 const std::pair< Uint31_Index, const Way_Skeleton* >& b)
7764381372115 q {
7774381372115 q return (a.second->id < b.second->id);
7784381372115 q }
779};
782template< typename Index, typename Object, typename Id_Type = Relation_Entry::Ref_Type >
783std::vector< Id_Type > extract_ids(const std::map< Index, std::vector< Object > >& elems)
785530121 q std::vector< Id_Type > ids;
78747038121 q for (auto it = elems.begin(); it != elems.end(); ++it)
7884650875 q {
789217070275 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
790212419472 q ids.push_back(Id_Type(it2->id.val()));
7914650875 q }
793530121 q std::sort(ids.begin(), ids.end());
795530121 q return ids;
799template< typename Index, typename Object, typename Id_Type = Relation_Entry::Ref_Type >
800std::vector< Id_Type > extract_ids(
801 const std::map< Index, std::vector< Object > >& current,
802 const std::map< Index, std::vector< Attic< Object > > >& attic)
8043332 q std::vector< Id_Type > ids;
8061283932 q for (auto it = current.begin(); it != current.end(); ++it)
8071280620 q {
8085336220 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
8094055618 q ids.push_back(Id_Type(it2->id.val()));
8101280620 q }
81130432 q for (auto it = attic.begin(); it != attic.end(); ++it)
8122717 q {
81314737 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
81412024 q ids.push_back(Id_Type(it2->id.val()));
8152717 q }
8173332 q std::sort(ids.begin(), ids.end());
8193332 q return ids;
823template< class TIndex, class TObject >
824std::set< Uint31_Index > extract_parent_indices(const std::map< TIndex, std::vector< TObject > >& elems)
826535112 q std::vector< uint32 > children;
828535112 q for (typename std::map< TIndex, std::vector< TObject > >::const_iterator
82957615112 q it(elems.begin()); it != elems.end(); ++it)
8305708070 q children.push_back(it->first.val());
833535112 q std::vector< uint32 > parents = calc_parents(children);
835535112 q std::set< Uint31_Index > req;
836118437112 q for (std::vector< uint32 >::const_iterator it = parents.begin(); it != parents.end(); ++it)
837117902112 q req.insert(Uint31_Index(*it));
839535112 q return req;
843Timeless< Uint31_Index, Way_Skeleton > collect_ways(
844 Request_Context& context,
845 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& rels,
846 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels,
847 const Ranges< Uint31_Index >& ranges,
848 const std::vector< Way::Id_Type >& ids, bool invert_ids,
849 uint32* role_id = 0);
852Timeless< Uint31_Index, Way_Skeleton > collect_ways(
853 Request_Context& context,
854 const std::map< Uint32_Index, std::vector< Node_Skeleton > >& nodes,
855 const std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >& attic_nodes,
856 const std::vector< int >* pos,
857 const std::vector< Way::Id_Type >& ids, bool invert_ids);
860void add_nw_member_objects(Request_Context& context, const Set& input_set, Set& into,
861 const Ranges< Uint32_Index >* ranges_32 = 0, const Ranges< Uint31_Index >* ranges_31 = 0);
864template< typename Index, typename Object >
865void filter_elems_for_closed_ways(std::map< Index, std::vector< Object > >& arg)
8671652371 q for (typename std::map< Index, std::vector< Object > >::iterator it1 = arg.begin(); it1 != arg.end(); ++it1)
8681621931 q {
8691621931 q std::vector< Object > into;
87014092731 q for (typename std::vector< Object >::iterator it2 = it1->second.begin(); it2 != it1->second.end(); ++it2)
87112470831 q {
87212470831 q if (!it2->nds.empty() && it2->nds.front() == it2->nds.back())
8737426629 q into.push_back(*it2);
87412470831 q }
8751621931 q into.swap(it1->second);
8761621931 q }
880template< typename Index, typename Object >
881Timeless< Index, Object >& Timeless< Index, Object >::filter_by_id(
882 const std::vector< typename Object::Id_Type >& ids)
8830{
8840 for (auto& i : current)
8850 {
8860 std::vector< Object > into;
8870 for (const auto& j : i.second)
8880 {
8890 if (std::binary_search(ids.begin(), ids.end(), j.id))
8900 into.push_back(j);
8910 }
8920 into.swap(i.second);
8930 }
8940 for (auto& i : attic)
8950 {
8960 std::vector< Attic< Object > > into;
8970 for (const auto& j : i.second)
8980 {
8990 if (std::binary_search(ids.begin(), ids.end(), j.id))
9000 into.push_back(j);
9010 }
9020 into.swap(i.second);
9030 }
9050 return *this;
9060}
909#endif