Skip to content

Commit 00e1c01

Browse files
committed
Further integration after request.
1 parent cd594e0 commit 00e1c01

File tree

5 files changed

+71
-128
lines changed

5 files changed

+71
-128
lines changed

src/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,5 +318,5 @@ EXTRA_DIST = \
318318
rules/areas_delta.osm3s
319319

320320
# Put test-bin here and test-bin/Makefile in configure.ac to activate test-bin
321-
#SUBDIRS = test-bin
322-
SUBDIRS =
321+
SUBDIRS = test-bin
322+
#SUBDIRS =

src/configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ fi
7373

7474
AC_SUBST(COMPRESS_LIBS, ["$COMPRESS_LIBS"])
7575

76-
#AC_CONFIG_FILES([Makefile test-bin/Makefile])
77-
AC_CONFIG_FILES([Makefile])
76+
AC_CONFIG_FILES([Makefile test-bin/Makefile])
77+
#AC_CONFIG_FILES([Makefile])
7878
AC_OUTPUT
7979
AC_SYS_LARGEFILE
8080

src/overpass_api/frontend/map_ql_parser.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,23 +256,21 @@ TStatement* create_has_kv_statement(typename TStatement::Factory& stmt_factory,
256256

257257
template< class TStatement >
258258
TStatement* create_id_query_statement(typename TStatement::Factory& stmt_factory,
259-
std::string type, std::vector< std::string > ref, std::string into, uint line_nr)
259+
std::string type, const std::vector< std::string >& ref, std::string into, uint line_nr)
260260
{
261261
std::map< std::string, std::string > attr;
262-
int i;
263-
std::vector< std::string >::iterator it;
264262

265263
attr["type"] = type;
266264
attr["into"] = into;
267265

268-
for(it = ref.begin(), i = 0; it != ref.end(); ++it, ++i)
266+
for (uint i = 0; i < ref.size(); ++i)
269267
{
270268
std::stringstream id;
271269
if (i == 0)
272270
id << "ref";
273271
else
274272
id << "ref_" << i;
275-
attr[id.str()] = *it;
273+
attr[id.str()] = ref[i];
276274
}
277275

278276
return stmt_factory.create_statement("id-query", line_nr, attr);
@@ -289,8 +287,7 @@ TStatement* create_item_statement(typename TStatement::Factory& stmt_factory,
289287

290288
template< class TStatement >
291289
TStatement* create_bbox_statement(typename TStatement::Factory& stmt_factory,
292-
std::string south, std::string north, std::string west, std::string east,
293-
std::string into, uint line_nr)
290+
std::string south, std::string north, std::string west, std::string east, std::string into, uint line_nr)
294291
{
295292
std::map< std::string, std::string > attr;
296293
attr["s"] = south;

src/overpass_api/statements/id_query.cc

Lines changed: 42 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -32,74 +32,23 @@ bool Id_Query_Statement::area_query_exists_ = false;
3232
Generic_Statement_Maker< Id_Query_Statement > Id_Query_Statement::statement_maker("id-query");
3333

3434

35-
template< class TIndex, class TObject >
36-
void collect_elems(Resource_Manager& rman, const File_Properties& prop,
37-
const std::set<Uint64::Id_Type> & ref_ids,
38-
std::map< TIndex, std::vector< TObject > >& elems)
39-
{
40-
std::set< TIndex > req;
41-
{
42-
Random_File< uint64, TIndex > random(rman.get_transaction()->random_index(&prop));
43-
for (std::set<Uint64::Id_Type>::iterator it_ref = ref_ids.begin(); it_ref != ref_ids.end(); it_ref++)
44-
req.insert(random.get(*it_ref));
45-
}
46-
Block_Backend< TIndex, TObject > elems_db(rman.get_transaction()->data_index(&prop));
47-
for (typename Block_Backend< TIndex, TObject >::Discrete_Iterator
48-
it(elems_db.discrete_begin(req.begin(), req.end()));
49-
!(it == elems_db.discrete_end()); ++it)
50-
{
51-
if (ref_ids.find(it.object().id.val()) != ref_ids.end())
52-
elems[it.index()].push_back(it.object());
53-
}
54-
}
55-
56-
57-
template< class TIndex, class TObject >
58-
void collect_elems(Resource_Manager& rman, const File_Properties& prop,
59-
const std::set<Uint64::Id_Type> & ref_ids,
60-
const std::vector< typename TObject::Id_Type >& ids, bool invert_ids,
61-
std::map< TIndex, std::vector< TObject > >& elems)
62-
{
63-
std::set< TIndex > req;
64-
{
65-
Random_File< uint64, TIndex > random(rman.get_transaction()->random_index(&prop));
66-
for (std::set<Uint64::Id_Type>::iterator it_ref = ref_ids.begin(); it_ref != ref_ids.end(); it_ref++)
67-
{
68-
if (binary_search(ids.begin(), ids.end(), *it_ref) ^ invert_ids)
69-
req.insert(random.get(*it_ref));
70-
}
71-
}
72-
Block_Backend< TIndex, TObject > elems_db(rman.get_transaction()->data_index(&prop));
73-
for (typename Block_Backend< TIndex, TObject >::Discrete_Iterator
74-
it(elems_db.discrete_begin(req.begin(), req.end()));
75-
!(it == elems_db.discrete_end()); ++it)
76-
{
77-
if ((ref_ids.find(it.object().id.val()) != ref_ids.end())
78-
&& (binary_search(ids.begin(), ids.end(), it.object().id) ^ invert_ids))
79-
elems[it.index()].push_back(it.object());
80-
}
81-
}
82-
83-
8435
void collect_elems_flat(Resource_Manager& rman,
85-
const std::set<Uint64::Id_Type> & ref_ids,
86-
const std::vector< Area_Skeleton::Id_Type >& ids, bool invert_ids,
36+
const std::vector< uint64 >& ids,
8737
std::map< Uint31_Index, std::vector< Area_Skeleton > >& elems)
8838
{
8939
Block_Backend< Uint31_Index, Area_Skeleton > elems_db
9040
(rman.get_transaction()->data_index(area_settings().AREAS));
9141
for (Block_Backend< Uint31_Index, Area_Skeleton >::Flat_Iterator
9242
it = elems_db.flat_begin(); !(it == elems_db.flat_end()); ++it)
9343
{
94-
if ((ref_ids.find(it.object().id.val()) != ref_ids.end())
95-
&& (binary_search(ids.begin(), ids.end(), it.object().id) ^ invert_ids))
44+
if (std::binary_search(ids.begin(), ids.end(), it.object().id.val()))
9645
elems[it.index()].push_back(it.object());
9746
}
9847
}
9948

10049

10150
template< class TIndex, class TObject >
102-
void filter_elems(const std::set<Uint64::Id_Type> & ref_ids,
51+
void filter_elems(const std::vector< uint64 > & ids,
10352
std::map< TIndex, std::vector< TObject > >& elems)
10453
{
10554
for (typename std::map< TIndex, std::vector< TObject > >::iterator it = elems.begin();
@@ -109,7 +58,7 @@ void filter_elems(const std::set<Uint64::Id_Type> & ref_ids,
10958
for (typename std::vector< TObject >::const_iterator iit = it->second.begin();
11059
iit != it->second.end(); ++iit)
11160
{
112-
if (ref_ids.find(iit->id.val()) != ref_ids.end())
61+
if (std::binary_search(ids.begin(), ids.end(), iit->id.val()))
11362
local_into.push_back(*iit);
11463
}
11564
it->second.swap(local_into);
@@ -150,9 +99,8 @@ bool Id_Query_Constraint::get_node_ids(Resource_Manager& rman, std::vector< Node
15099
{
151100
ids.clear();
152101
if (stmt->get_type() == Statement::NODE)
153-
{
154-
ids.assign(stmt->get_ref_ids().begin(), stmt->get_ref_ids().end());
155-
}
102+
ids.assign(stmt->get_refs().begin(), stmt->get_refs().end());
103+
156104
return true;
157105
}
158106

@@ -161,9 +109,8 @@ bool Id_Query_Constraint::get_way_ids(Resource_Manager& rman, std::vector< Way_S
161109
{
162110
ids.clear();
163111
if (stmt->get_type() == Statement::WAY)
164-
{
165-
ids.assign(stmt->get_ref_ids().begin(), stmt->get_ref_ids().end());
166-
}
112+
ids.assign(stmt->get_refs().begin(), stmt->get_refs().end());
113+
167114
return true;
168115
}
169116

@@ -172,18 +119,17 @@ bool Id_Query_Constraint::get_relation_ids(Resource_Manager& rman, std::vector<
172119
{
173120
ids.clear();
174121
if (stmt->get_type() == Statement::RELATION)
175-
{
176-
ids.assign(stmt->get_ref_ids().begin(), stmt->get_ref_ids().end());
177-
}
122+
ids.assign(stmt->get_refs().begin(), stmt->get_refs().end());
123+
178124
return true;
179125
}
180126

181127

182128
bool Id_Query_Constraint::get_ranges(Resource_Manager& rman, std::set< std::pair< Uint32_Index, Uint32_Index > >& ranges)
183129
{
184130
std::vector< Node_Skeleton::Id_Type > ids;
185-
186-
ids.assign(stmt->get_ref_ids().begin(), stmt->get_ref_ids().end());
131+
ids.assign(stmt->get_refs().begin(), stmt->get_refs().end());
132+
187133
std::vector< Uint32_Index > req = get_indexes_< Uint32_Index, Node_Skeleton >(ids, rman);
188134

189135
ranges.clear();
@@ -200,13 +146,13 @@ bool Id_Query_Constraint::get_ranges(Resource_Manager& rman, std::set< std::pair
200146
if (stmt->get_type() == Statement::WAY)
201147
{
202148
std::vector< Way_Skeleton::Id_Type > ids;
203-
ids.assign(stmt->get_ref_ids().begin(), stmt->get_ref_ids().end());
149+
ids.assign(stmt->get_refs().begin(), stmt->get_refs().end());
204150
get_indexes_< Uint31_Index, Way_Skeleton >(ids, rman).swap(req);
205151
}
206152
else
207153
{
208154
std::vector< Relation_Skeleton::Id_Type > ids;
209-
ids.assign(stmt->get_ref_ids().begin(), stmt->get_ref_ids().end());
155+
ids.assign(stmt->get_refs().begin(), stmt->get_refs().end());
210156
get_indexes_< Uint31_Index, Relation_Skeleton >(ids, rman).swap(req);
211157
}
212158

@@ -222,30 +168,30 @@ void Id_Query_Constraint::filter(Resource_Manager& rman, Set& into, uint64 times
222168
{
223169
if (stmt->get_type() == Statement::NODE)
224170
{
225-
filter_elems(stmt->get_ref_ids(), into.nodes);
226-
filter_elems(stmt->get_ref_ids(), into.attic_nodes);
171+
filter_elems(stmt->get_refs(), into.nodes);
172+
filter_elems(stmt->get_refs(), into.attic_nodes);
227173
}
228174
else
229175
into.nodes.clear();
230176

231177
if (stmt->get_type() == Statement::WAY)
232178
{
233-
filter_elems(stmt->get_ref_ids(), into.ways);
234-
filter_elems(stmt->get_ref_ids(), into.attic_ways);
179+
filter_elems(stmt->get_refs(), into.ways);
180+
filter_elems(stmt->get_refs(), into.attic_ways);
235181
}
236182
else
237183
into.ways.clear();
238184

239185
if (stmt->get_type() == Statement::RELATION)
240186
{
241-
filter_elems(stmt->get_ref_ids(), into.relations);
242-
filter_elems(stmt->get_ref_ids(), into.attic_relations);
187+
filter_elems(stmt->get_refs(), into.relations);
188+
filter_elems(stmt->get_refs(), into.attic_relations);
243189
}
244190
else
245191
into.relations.clear();
246192

247193
if (stmt->get_type() == Statement::AREA)
248-
filter_elems(stmt->get_ref_ids(), into.areas);
194+
filter_elems(stmt->get_refs(), into.areas);
249195
else
250196
into.areas.clear();
251197
}
@@ -295,28 +241,30 @@ Id_Query_Statement::Id_Query_Statement
295241
add_static_error(temp.str());
296242
}
297243

298-
ref = atoll(attributes["ref"].c_str());
244+
uint64 ref = atoll(attributes["ref"].c_str());
299245

300-
if (ref.val() > 0)
301-
ref_ids.insert(ref.val());
246+
if (ref > 0)
247+
refs.push_back(ref);
302248

303-
for (std::map<std::string, std::string>::iterator it = attributes.begin();
249+
for (std::map< std::string, std::string >::iterator it = attributes.begin();
304250
it != attributes.end(); ++it)
305251
{
306252
if (it->first.find("ref_") == 0)
307253
{
308254
ref = atoll(it->second.c_str());
309-
if (ref.val() > 0)
310-
ref_ids.insert(ref.val());
255+
if (ref > 0)
256+
refs.push_back(ref);
311257
}
312258
}
259+
std::sort(refs.begin(), refs.end());
260+
refs.erase(std::unique(refs.begin(), refs.end()), refs.end());
313261

314-
lower = atoll(attributes["lower"].c_str());
315-
upper = atoll(attributes["upper"].c_str());
262+
uint64 lower = atoll(attributes["lower"].c_str());
263+
uint64 upper = atoll(attributes["upper"].c_str());
316264

317-
if (ref.val() <= 0)
265+
if (ref <= 0)
318266
{
319-
if (lower.val() == 0 || upper.val() == 0)
267+
if (lower == 0 || upper == 0)
320268
{
321269
std::ostringstream temp;
322270
temp<<"For the attribute \"ref\" of the element \"id-query\""
@@ -331,10 +279,10 @@ Id_Query_Statement::Id_Query_Statement
331279
upper = ++ref;
332280
}
333281

334-
if (lower.val() > 0 && upper.val() > 0)
282+
if (lower > 0 && upper > 0)
335283
{
336-
for (Uint64::Id_Type i = lower.val(); i < upper.val(); ++i)
337-
ref_ids.insert(i);
284+
for (uint64 i = lower; i < upper; ++i)
285+
refs.push_back(i);
338286
}
339287
}
340288

@@ -393,12 +341,12 @@ struct Attic_Skeleton_By_Id
393341

394342

395343
template< typename Index, typename Skeleton >
396-
void get_elements(const std::set<Uint64::Id_Type> & ref_ids, Statement* stmt, Resource_Manager& rman,
344+
void get_elements(const std::vector< uint64 >& refs, Statement* stmt, Resource_Manager& rman,
397345
std::map< Index, std::vector< Skeleton > >& current_result,
398346
std::map< Index, std::vector< Attic< Skeleton > > >& attic_result)
399347
{
400348
std::vector< typename Skeleton::Id_Type > ids;
401-
ids.assign(ref_ids.begin(), ref_ids.end());
349+
ids.assign(refs.begin(), refs.end());
402350
std::vector< Index > req = get_indexes_< Index, Skeleton >(ids, rman);
403351

404352
if (rman.get_desired_timestamp() == NOW)
@@ -418,13 +366,13 @@ void Id_Query_Statement::execute(Resource_Manager& rman)
418366
Set into;
419367

420368
if (type == NODE)
421-
get_elements(ref_ids, this, rman, into.nodes, into.attic_nodes);
369+
get_elements(refs, this, rman, into.nodes, into.attic_nodes);
422370
else if (type == WAY)
423-
get_elements(ref_ids, this, rman, into.ways, into.attic_ways);
371+
get_elements(refs, this, rman, into.ways, into.attic_ways);
424372
else if (type == RELATION)
425-
get_elements(ref_ids, this, rman, into.relations, into.attic_relations);
373+
get_elements(refs, this, rman, into.relations, into.attic_relations);
426374
else if (type == AREA)
427-
collect_elems_flat(rman, ref_ids, std::vector< Area_Skeleton::Id_Type >(), true, into.areas);
375+
collect_elems_flat(rman, refs, into.areas);
428376

429377
transfer_output(rman, into);
430378
rman.health_check(*this);

0 commit comments

Comments
 (0)