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

overpass_api/data/collect_members.h

472 of 500 instrumented lines run by the suite (94.4%) 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)
139886328 q auto ranges_it = ranges.begin();
140886328 q typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::iterator it = relations.begin();
14152037328 q for (; it != relations.end() && ranges_it != ranges.end(); )
14251151153 q {
14351151153 q if (!(it->first < ranges_it.upper_bound()))
14422183151 q ++ranges_it;
14528968153 q else if (!(it->first < ranges_it.lower_bound()))
14612239152 q ++it;
147167294 q else
148167294 q {
149167294 q it->second.clear();
150167294 q ++it;
151167294 q }
15251151153 q }
1531299328 q for (; it != relations.end(); ++it)
1544132 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)
1655348 q Request_Context context(&query, rman);
1665348 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_)
178979453 q : ids(&ids_), invert_ids(invert_ids_), ranges(ranges_), query(&query_), rman(&rman_),
179979453 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)
203979453 q if (ranges.empty())
2041811 q return false;
205961452 q Request_Context context(&query, rman);
206961452 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)
215979453 q elements.clear();
216979453 q attic_elements.clear();
217979453 q if (invert_ids)
219626291 q if (ids->empty())
220617289 q return get_elements_by_id_from_db_generic(
221617289 q elements, attic_elements, Trivial_Predicate< Object >(), ranges, min_idx, *query, *rman);
22296 q else
22396 q return get_elements_by_id_from_db_generic(
22496 q elements, attic_elements, Not_Predicate< Object, Id_Predicate< Object > >(Id_Predicate< Object >(*ids)),
22596 q ranges, min_idx, *query, *rman);
227353207 q return get_elements_by_id_from_db_generic(
228353207 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)
2389237555 q if (timestamp != NOW)
2397206246 q {
2407206246 q std::vector< Index > idx_set;
2417206246 q for (typename std::map< Index, std::vector< Skeleton > >::const_iterator it = current.begin();
2421225457246 q it != current.end(); ++it)
2431218251231 q idx_set.push_back(it->first);
2447206246 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::const_iterator it = attic.begin();
2451245402246 q it != attic.end(); ++it)
2461238196231 q idx_set.push_back(it->first);
2477206246 q std::sort(idx_set.begin(), idx_set.end());
2487206246 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
2517206246 q std::map< Index, std::vector< typename Skeleton::Id_Type > > deleted_items;
2537206246 q Block_Backend< Index, Attic< typename Skeleton::Id_Type >, typename std::vector< Index >::const_iterator >
2547206246 q undeleted_db(rman.get_transaction()->data_index(attic_undeleted_file_properties< Skeleton >()));
2557206246 q for (auto it = undeleted_db.discrete_begin(idx_set.begin(), idx_set.end());
2561362748246 q !(it == undeleted_db.discrete_end()); ++it)
2571355542217 q {
2581355542217 q if (it.object().timestamp <= timestamp)
259434679197 q continue;
261920863209 q typename std::map< Index, std::vector< Skeleton > >::iterator cit = current.find(it.index());
262920863209 q if (cit != current.end())
263881290209 q {
26411273879209 q for (typename std::vector< Skeleton >::iterator it2 = cit->second.begin(); it2 != cit->second.end(); )
26510392589181 q {
26610392589181 q if (it2->id == it.object())
26735796146 q {
26835796146 q *it2 = cit->second.back();
26935796146 q cit->second.pop_back();
27035796146 q }
27110356793181 q else
27210356793181 q ++it2;
27310392589181 q }
274881290209 q }
276920863209 q typename std::map< Index, std::vector< Attic< Skeleton > > >::iterator ait = attic.find(it.index());
277920863209 q if (ait != attic.end())
278919035208 q {
279919035208 q for (typename std::vector< Attic< Skeleton > >::iterator it2 = ait->second.begin();
28050707560208 q it2 != ait->second.end(); )
28149788525182 q {
28249788525182 q if (it2->id == it.object() && it.object().timestamp < it2->timestamp)
283125426142 q {
284125426142 q *it2 = ait->second.back();
285125426142 q ait->second.pop_back();
286125426142 q }
28749663099182 q else
28849663099182 q ++it2;
28949788525182 q }
290919035208 q }
291920863209 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
2977206246 q std::map< Index, std::map< typename Skeleton::Id_Type, std::pair< uint64, uint64 > > >
2987206246 q timestamp_by_id_by_idx;
2997206246 q for (typename std::map< Index, std::vector< Skeleton > >::const_iterator it = current.begin();
3001225457246 q it != current.end(); ++it)
3011218251231 q {
3021218251231 q std::map< typename Skeleton::Id_Type, std::pair< uint64, uint64 > >& entry
3031218251231 q = timestamp_by_id_by_idx[it->first];
3041218251231 q for (typename std::vector< Skeleton >::const_iterator it2 = it->second.begin();
3057979971231 q it2 != it->second.end(); ++it2)
3066761720215 q entry[it2->id] = std::make_pair(0, NOW);
3071218251231 q }
3087206246 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::const_iterator it = attic.begin();
3091245402246 q it != attic.end(); ++it)
3101238196231 q {
3111238196231 q std::map< typename Skeleton::Id_Type, std::pair< uint64, uint64 > >& entry
3121238196231 q = timestamp_by_id_by_idx[it->first];
3131238196231 q for (typename std::vector< Attic< Skeleton > >::const_iterator it2 = it->second.begin();
3142843961231 q it2 != it->second.end(); ++it2)
3151605765196 q entry[it2->id] = std::make_pair(0, it2->timestamp);
3161238196231 q }
3187206246 q Block_Backend< Index, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type >,
3197206246 q typename std::vector< Index >::const_iterator >
3207206246 q attic_meta_db(rman.get_transaction()->data_index
3217206246 q (attic_meta_file_properties< Skeleton >()));
3227206246 q for (auto it = attic_meta_db.discrete_begin(idx_set.begin(), idx_set.end());
32370020825246 q !(it == attic_meta_db.discrete_end()); ++it)
32470013619227 q {
32570013619227 q auto tit = timestamp_by_id_by_idx[it.index()].find(it.object().ref);
32670013619227 q if (tit != timestamp_by_id_by_idx[it.index()].end())
3275679111199 q {
3285679111199 q if (timestamp < it.object().timestamp)
3294290749189 q tit->second.second = std::min(tit->second.second, it.object().timestamp);
3301388362179 q else
3311388362179 q tit->second.first = std::max(tit->second.first, it.object().timestamp);
3325679111199 q }
33370013619227 q }
335 // Same thing with current meta data
3367206246 q Block_Backend< Index, OSM_Element_Metadata_Skeleton< typename Skeleton::Id_Type >,
3377206246 q typename std::vector< Index >::const_iterator >
3387206246 q meta_db(rman.get_transaction()->data_index
3397206246 q (current_meta_file_properties< Skeleton >()));
3417206246 q for (auto it = meta_db.discrete_begin(idx_set.begin(), idx_set.end());
34267891156246 q !(it == meta_db.discrete_end()); ++it)
34367883950224 q {
34467883950224 q auto tit = timestamp_by_id_by_idx[it.index()].find(it.object().ref);
34567883950224 q if (tit != timestamp_by_id_by_idx[it.index()].end())
3467617047220 q {
3477617047220 q if (timestamp < it.object().timestamp)
3483121728206 q tit->second.second = std::min(tit->second.second, it.object().timestamp);
3494495319174 q else
3504495319174 q tit->second.first = std::max(tit->second.first, it.object().timestamp);
3517617047220 q }
35267883950224 q }
354 // Filter current: only keep elements that have already existed at timestamp
3557206246 q for (typename std::map< Index, std::vector< Skeleton > >::iterator it = current.begin();
3561225457246 q it != current.end(); ++it)
3571218251231 q {
3581218251231 q std::vector< Skeleton > result;
3591218251231 q std::map< typename Skeleton::Id_Type, std::pair< uint64, uint64 > >& entry
3601218251231 q = timestamp_by_id_by_idx[it->first];
3621218251231 q for (typename std::vector< Skeleton >::const_iterator it2 = it->second.begin();
3637979971231 q it2 != it->second.end(); ++it2)
3646761720215 q {
3656761720215 q if (entry[it2->id].first > 0)
3664549883181 q {
3674549883181 q if (entry[it2->id].second == NOW)
3684469209170 q result.push_back(*it2);
36980674137 q else
37080674137 q attic[it->first].push_back(Attic< Skeleton >(*it2, entry[it2->id].second));
3714549883181 q }
3726761720215 q }
3741218251231 q result.swap(it->second);
3751218251231 q }
377 // Filter attic: only keep elements that have already existed at timestamp
3787206246 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::iterator it = attic.begin();
3791245474246 q it != attic.end(); ++it)
3801238268231 q {
3811238268231 q std::vector< Attic< Skeleton > > result;
3821238268231 q std::map< typename Skeleton::Id_Type, std::pair< uint64, uint64 > >& entry
3831238268231 q = timestamp_by_id_by_idx[it->first];
3851238268231 q for (typename std::vector< Attic< Skeleton > >::const_iterator it2 = it->second.begin();
3862924707231 q it2 != it->second.end(); ++it2)
3871686439198 q {
3881686439198 q if (entry[it2->id].first > 0)
389604405178 q {
390604405178 q result.push_back(*it2);
391604405178 q result.back().timestamp = entry[it2->id].second;
392604405178 q }
3931686439198 q }
3951238268231 q result.swap(it->second);
3961238268231 q }
3977206246 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)
407288595193 q{
408288595193 q for (typename std::vector< Relation_Skeleton >::const_iterator it2(relations.begin());
409713836193 q it2 != relations.end(); ++it2)
410425241183 q {
411425241183 q for (std::vector< Relation_Entry >::const_iterator it3(it2->members.begin());
41216481877183 q it3 != it2->members.end(); ++it3)
41316056636183 q {
41416056636183 q if (it3->type == type)
4157101456182 q ids.push_back(Ref_Type(it3->ref.val()));
41616056636183 q }
417425241183 q }
418288595193 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)
4241808 q{
4251808 q for (typename std::vector< Relation_Skeleton >::const_iterator it2(relations.begin());
4262648 q it2 != relations.end(); ++it2)
427848 q {
428848 q for (std::vector< Relation_Entry >::const_iterator it3(it2->members.begin());
42989308 q it3 != it2->members.end(); ++it3)
43088468 q {
43188468 q if (it3->type == type && it3->role == role_id)
4320 ids.push_back(Ref_Type(it3->ref.val()));
43388468 q }
434848 q }
4351808 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)
4444696417 q std::vector< Node::Id_Type > ids;
4454696417 q if (role_id)
447155 q for (auto it = rels.begin(); it != rels.end(); ++it)
44892 q filter_for_member_ids(it->second, ids, Relation_Entry::NODE, *role_id);
4504690416 q else
4514690416 q {
45286558416 q for (auto it = rels.begin(); it != rels.end(); ++it)
45381868190 q filter_for_member_ids(it->second, ids, Relation_Entry::NODE);
4544690416 q }
4564696417 q if (role_id)
458905 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it)
459843 q filter_for_member_ids(it->second, ids, Relation_Entry::NODE, *role_id);
4614690416 q else
4624690416 q {
46336559416 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it)
4643186939 q filter_for_member_ids(it->second, ids, Relation_Entry::NODE);
4654690416 q }
4674696417 q sort(ids.begin(), ids.end());
4684696417 q ids.erase(unique(ids.begin(), ids.end()), ids.end());
4704696417 q return ids;
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)
4794709420 q std::vector< Way::Id_Type > ids;
4804709420 q if (role_id)
482195 q for (auto it = rels.begin(); it != rels.end(); ++it)
483112 q filter_for_member_ids(it->second, ids, Relation_Entry::WAY, *role_id);
4854701418 q else
4864701418 q {
48789390418 q for (auto it = rels.begin(); it != rels.end(); ++it)
48884689187 q filter_for_member_ids(it->second, ids, Relation_Entry::WAY);
4894701418 q }
4914709420 q if (role_id)
493535 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it)
494451 q filter_for_member_ids(it->second, ids, Relation_Entry::WAY, *role_id);
4964701418 q else
4974701418 q {
49848569418 q for (auto it = attic_rels.begin(); it != attic_rels.end(); ++it)
4994386876 q filter_for_member_ids(it->second, ids, Relation_Entry::WAY);
5004701418 q }
5024709420 q sort(ids.begin(), ids.end());
5034709420 q ids.erase(unique(ids.begin(), ids.end()), ids.end());
5054709420 q return ids;
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)
5158864433 q if (timestamp == NOW)
5162337293 q {
5172337293 q attic.clear();
5182337293 q return;
5192337293 q }
5216527196 q std::map< typename Skeleton::Id_Type, uint64 > timestamp_by_id;
52364857196 q for (auto it = current.begin(); it != current.end(); ++it)
5245833048 q {
52516744648 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
52610911641 q timestamp_by_id[it2->id] = NOW;
5275833048 q }
52967719196 q for (auto it = attic.begin(); it != attic.end(); ++it)
5306119249 q {
53112906249 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
5326787030 q {
5336787030 q uint64& stored_timestamp = timestamp_by_id[it2->id];
5346787030 q if (it2->timestamp > timestamp && (stored_timestamp == 0 || stored_timestamp > it2->timestamp))
5356770030 q stored_timestamp = it2->timestamp;
5366787030 q }
5376119249 q }
53964857196 q for (auto it = current.begin(); it != current.end(); ++it)
5405833048 q {
5415833048 q std::vector< Skeleton > local_into;
54216744648 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
54310911641 q {
54410911641 q if (timestamp_by_id[it2->id] == NOW)
54510834641 q local_into.push_back(*it2);
54610911641 q }
5475833048 q local_into.swap(it->second);
5485833048 q }
55067719196 q for (auto it = attic.begin(); it != attic.end(); ++it)
5516119249 q {
5526119249 q std::vector< Attic< Skeleton > > local_into;
55312906249 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
5546787030 q {
5556787030 q if (timestamp_by_id[it2->id] == it2->timestamp)
5566754630 q local_into.push_back(*it2);
5576787030 q }
5586119249 q local_into.swap(it->second);
5596119249 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)
570835164 q std::map< typename Skeleton::Id_Type, uint64 > timestamp_by_id;
572835164 q result.clear();
574571919164 q for (auto it = current.begin(); it != current.end(); ++it)
57557108460 q {
57660075260 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
5772966853 q timestamp_by_id[it2->id] = NOW;
57857108460 q }
580571919164 q for (auto it = attic.begin(); it != attic.end(); ++it)
58157108460 q {
58257108460 q for (typename std::vector< Attic< Skeleton > >::const_iterator it2 = it->second.begin();
58359286460 q it2 != it->second.end(); ++it2)
5842178059 q {
5852178059 q uint64& stored_timestamp = timestamp_by_id[it2->id];
5862178059 q if (it2->timestamp > timestamp && (stored_timestamp == 0 || stored_timestamp > it2->timestamp))
5872111759 q stored_timestamp = it2->timestamp;
5882178059 q }
58957108460 q }
591571919164 q for (auto it = current.begin(); it != current.end(); ++it)
59257108460 q {
59360075260 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
5942966853 q {
5952966853 q if (timestamp_by_id[it2->id] == NOW)
5962895253 q result[it->first].push_back(Attic< Skeleton >(*it2, NOW));
5972966853 q }
59857108460 q }
600571919164 q for (auto it = attic.begin(); it != attic.end(); ++it)
60157108460 q {
60259286460 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
6032178059 q {
6042178059 q if (timestamp_by_id[it2->id] == it2->timestamp)
6052077459 q result[it->first].push_back(Attic< Skeleton >(*it2, it2->timestamp));
6062178059 q }
60757108460 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)
62365670 q for (typename std::map< TIndex, std::vector< TObject > >::iterator it = modify.begin();
62417907070 q it != modify.end(); ++it)
62517841447 q {
62617841447 q sort(it->second.begin(), it->second.end());
62717841447 q typename std::map< TIndex, std::vector< TObject > >::const_iterator
62817841447 q from_it = read.find(it->first);
62917841447 q if (from_it == read.end())
6300 {
6310 it->second.clear();
6320 continue;
6330 }
63417841447 q std::vector< TObject > local_into;
63517841447 q for (typename std::vector< TObject >::const_iterator iit = from_it->second.begin();
636132006247 q iit != from_it->second.end(); ++iit)
637114164847 q {
638114164847 q if (std::binary_search(it->second.begin(), it->second.end(), *iit))
639114164544 q local_into.push_back(*iit);
640114164847 q }
64117841447 q it->second.swap(local_into);
64217841447 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)
659970325 q std::vector< std::pair< Index, const Skeleton* > > skels_by_id;
660970325 q for (typename std::map< Index, std::vector< Skeleton > >::const_iterator it = skels.begin();
66153084325 q it != skels.end(); ++it)
66252114131 q {
66352114131 q for (typename std::vector< Skeleton >::const_iterator iit = it->second.begin();
664118667131 q iit != it->second.end(); ++iit)
66566553119 q skels_by_id.push_back(std::make_pair(it->first, &*iit));
66652114131 q }
667970325 q sort(skels_by_id.begin(), skels_by_id.end(), order_by_id);
669970325 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)
67823898 q std::vector< std::pair< Index, const Skeleton* > > skels_by_id;
67923898 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::const_iterator it = skels.begin();
6801138298 q it != skels.end(); ++it)
6811114452 q {
6821114452 q for (typename std::vector< Attic< Skeleton > >::const_iterator iit = it->second.begin();
6832560552 q iit != it->second.end(); ++iit)
6841446149 q skels_by_id.push_back(std::make_pair(it->first, &*iit));
6851114452 q }
68623898 q sort(skels_by_id.begin(), skels_by_id.end(), order_by_id);
68823898 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)
69712793 q for (typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::iterator it = relations.begin();
698592493 q it != relations.end(); ++it)
699579751 q {
700579751 q std::vector< Relation_Skeleton > local_into;
701579751 q for (typename std::vector< Relation_Skeleton >::const_iterator iit = it->second.begin();
7022374251 q iit != it->second.end(); ++iit)
7031794549 q {
7041794549 q for (std::vector< Relation_Entry >::const_iterator nit = iit->members.begin();
705137892749 q nit != iit->members.end(); ++nit)
706136302249 q {
707136302249 q if (nit->type == Relation_Entry::NODE)
7081186946 q {
7091186946 q const std::pair< Uint32_Index, const Node_Skeleton* >* second_nd =
7101186946 q binary_search_for_pair_id(node_members_by_id, nit->ref);
7111186946 q if (second_nd)
71211613 q {
71311613 q local_into.push_back(*iit);
71411613 q break;
71511613 q }
7161186946 q }
717135115348 q else if (nit->type == Relation_Entry::WAY)
718132914948 q {
719132914948 q const std::pair< Uint31_Index, const Way_Skeleton* >* second_nd =
720132914948 q binary_search_for_pair_id(way_members_by_id, nit->ref32());
721132914948 q if (second_nd)
722192441 q {
723192441 q local_into.push_back(*iit);
724192441 q break;
725192441 q }
726132914948 q }
727136302249 q }
7281794549 q }
729579751 q it->second.swap(local_into);
730579751 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)
7662137556 q {
7672137556 q return (a.second->id < b.second->id);
7682137556 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)
7761085445127 q {
7771085445127 q return (a.second->id < b.second->id);
7781085445127 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)
785564121 q std::vector< Id_Type > ids;
78724455121 q for (auto it = elems.begin(); it != elems.end(); ++it)
7882389178 q {
78938690078 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
79036300976 q ids.push_back(Id_Type(it2->id.val()));
7912389178 q }
793564121 q std::sort(ids.begin(), ids.end());
795564121 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)
8043734 q std::vector< Id_Type > ids;
806527534 q for (auto it = current.begin(); it != current.end(); ++it)
807523820 q {
8086660520 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
8096136718 q ids.push_back(Id_Type(it2->id.val()));
810523820 q }
8118534 q for (auto it = attic.begin(); it != attic.end(); ++it)
812486 q {
813566 q for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
81483 q ids.push_back(Id_Type(it2->id.val()));
815486 q }
8173734 q std::sort(ids.begin(), ids.end());
8193734 q return ids;
823template< class TIndex, class TObject >
824std::set< Uint31_Index > extract_parent_indices(const std::map< TIndex, std::vector< TObject > >& elems)
826513111 q std::vector< uint32 > children;
828513111 q for (typename std::map< TIndex, std::vector< TObject > >::const_iterator
82928985111 q it(elems.begin()); it != elems.end(); ++it)
8302847275 q children.push_back(it->first.val());
833513111 q std::vector< uint32 > parents = calc_parents(children);
835513111 q std::set< Uint31_Index > req;
836100114111 q for (std::vector< uint32 >::const_iterator it = parents.begin(); it != parents.end(); ++it)
83799601111 q req.insert(Uint31_Index(*it));
839513111 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)
8671670961 q for (typename std::map< Index, std::vector< Object > >::iterator it1 = arg.begin(); it1 != arg.end(); ++it1)
8681646543 q {
8691646543 q std::vector< Object > into;
8703178643 q for (typename std::vector< Object >::iterator it2 = it1->second.begin(); it2 != it1->second.end(); ++it2)
8711532143 q {
8721532143 q if (!it2->nds.empty() && it2->nds.front() == it2->nds.back())
873102331 q into.push_back(*it2);
8741532143 q }
8751646543 q into.swap(it1->second);
8761646543 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