Skip to content

Commit 6e4d723

Browse files
committed
Complete implementation of get_ranges for recurse to cover corner case.
1 parent 69915d2 commit 6e4d723

File tree

3 files changed

+216
-97
lines changed

3 files changed

+216
-97
lines changed

src/overpass_api/data/collect_members.cc

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -314,91 +314,6 @@ std::vector< Uint31_Index > relation_relation_member_indices
314314
}
315315

316316

317-
template< typename Relation_Skeleton >
318-
std::set< std::pair< Uint32_Index, Uint32_Index > > relation_node_member_indices
319-
(const Statement* stmt, Resource_Manager& rman,
320-
typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator rels_begin,
321-
typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator rels_end)
322-
{
323-
std::vector< uint32 > parents;
324-
325-
for (typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator
326-
it = rels_begin; it != rels_end; ++it)
327-
{
328-
if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0))
329-
{
330-
// Treat relations with really large indices: get the node indexes from the segement indexes
331-
for (typename std::vector< Relation_Skeleton >::const_iterator it2 = it->second.begin();
332-
it2 != it->second.end(); ++it2)
333-
{
334-
for (std::vector< Uint31_Index >::const_iterator it3 = it2->node_idxs.begin();
335-
it3 != it2->node_idxs.end(); ++it3)
336-
parents.push_back(it3->val());
337-
}
338-
}
339-
else
340-
parents.push_back(it->first.val());
341-
}
342-
if (stmt)
343-
rman.health_check(*stmt);
344-
345-
return collect_node_req(stmt, rman, std::vector< Node::Id_Type >(), parents);
346-
}
347-
348-
349-
template< typename Relation_Skeleton >
350-
std::set< std::pair< Uint32_Index, Uint32_Index > > relation_node_member_indices
351-
(const Statement* stmt, Resource_Manager& rman,
352-
typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator rels_begin,
353-
typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator rels_end,
354-
typename std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >::const_iterator
355-
attic_rels_begin,
356-
typename std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >::const_iterator
357-
attic_rels_end)
358-
{
359-
std::vector< uint32 > parents;
360-
361-
for (typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator
362-
it = rels_begin; it != rels_end; ++it)
363-
{
364-
if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0))
365-
{
366-
// Treat relations with really large indices: get the node indexes from the segement indexes
367-
for (typename std::vector< Relation_Skeleton >::const_iterator it2 = it->second.begin();
368-
it2 != it->second.end(); ++it2)
369-
{
370-
for (std::vector< Uint31_Index >::const_iterator it3 = it2->node_idxs.begin();
371-
it3 != it2->node_idxs.end(); ++it3)
372-
parents.push_back(it3->val());
373-
}
374-
}
375-
else
376-
parents.push_back(it->first.val());
377-
}
378-
for (typename std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >::const_iterator
379-
it = attic_rels_begin; it != attic_rels_end; ++it)
380-
{
381-
if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0))
382-
{
383-
// Treat relations with really large indices: get the node indexes from the segement indexes
384-
for (typename std::vector< Attic< Relation_Skeleton > >::const_iterator it2 = it->second.begin();
385-
it2 != it->second.end(); ++it2)
386-
{
387-
for (std::vector< Uint31_Index >::const_iterator it3 = it2->node_idxs.begin();
388-
it3 != it2->node_idxs.end(); ++it3)
389-
parents.push_back(it3->val());
390-
}
391-
}
392-
else
393-
parents.push_back(it->first.val());
394-
}
395-
if (stmt)
396-
rman.health_check(*stmt);
397-
398-
return collect_node_req(stmt, rman, std::vector< Node::Id_Type >(), parents);
399-
}
400-
401-
402317
std::set< std::pair< Uint32_Index, Uint32_Index > > way_nd_indices
403318
(const Statement* stmt, Resource_Manager& rman,
404319
std::map< Uint31_Index, std::vector< Way_Skeleton > >::const_iterator ways_begin,

src/overpass_api/data/collect_members.h

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,4 +852,122 @@ std::vector< Uint31_Index > relation_way_member_indices
852852
}
853853

854854

855+
std::vector< Uint31_Index > relation_relation_member_indices
856+
(const Statement& stmt, Resource_Manager& rman,
857+
std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator rels_begin,
858+
std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator rels_end);
859+
860+
861+
std::vector< Uint31_Index > relation_relation_member_indices
862+
(const Statement& stmt, Resource_Manager& rman,
863+
std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator rels_begin,
864+
std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator rels_end,
865+
std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >::const_iterator attic_rels_begin,
866+
std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >::const_iterator attic_rels_end);
867+
868+
869+
std::set< std::pair< Uint32_Index, Uint32_Index > > collect_node_req
870+
(const Statement* stmt, Resource_Manager& rman,
871+
const std::vector< Node::Id_Type >& map_ids, const std::vector< uint32 >& parents);
872+
873+
874+
template< typename Relation_Skeleton >
875+
std::set< std::pair< Uint32_Index, Uint32_Index > > relation_node_member_indices
876+
(const Statement* stmt, Resource_Manager& rman,
877+
typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator rels_begin,
878+
typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator rels_end)
879+
{
880+
std::vector< uint32 > parents;
881+
882+
for (typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator
883+
it = rels_begin; it != rels_end; ++it)
884+
{
885+
if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0))
886+
{
887+
// Treat relations with really large indices: get the node indexes from the segement indexes
888+
for (typename std::vector< Relation_Skeleton >::const_iterator it2 = it->second.begin();
889+
it2 != it->second.end(); ++it2)
890+
{
891+
for (std::vector< Uint31_Index >::const_iterator it3 = it2->node_idxs.begin();
892+
it3 != it2->node_idxs.end(); ++it3)
893+
parents.push_back(it3->val());
894+
}
895+
}
896+
else
897+
parents.push_back(it->first.val());
898+
}
899+
if (stmt)
900+
rman.health_check(*stmt);
901+
902+
return collect_node_req(stmt, rman, std::vector< Node::Id_Type >(), parents);
903+
}
904+
905+
906+
template< typename Relation_Skeleton >
907+
std::set< std::pair< Uint32_Index, Uint32_Index > > relation_node_member_indices
908+
(const Statement* stmt, Resource_Manager& rman,
909+
typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator rels_begin,
910+
typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator rels_end,
911+
typename std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >::const_iterator
912+
attic_rels_begin,
913+
typename std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >::const_iterator
914+
attic_rels_end)
915+
{
916+
std::vector< uint32 > parents;
917+
918+
for (typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::const_iterator
919+
it = rels_begin; it != rels_end; ++it)
920+
{
921+
if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0))
922+
{
923+
// Treat relations with really large indices: get the node indexes from the segement indexes
924+
for (typename std::vector< Relation_Skeleton >::const_iterator it2 = it->second.begin();
925+
it2 != it->second.end(); ++it2)
926+
{
927+
for (std::vector< Uint31_Index >::const_iterator it3 = it2->node_idxs.begin();
928+
it3 != it2->node_idxs.end(); ++it3)
929+
parents.push_back(it3->val());
930+
}
931+
}
932+
else
933+
parents.push_back(it->first.val());
934+
}
935+
for (typename std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >::const_iterator
936+
it = attic_rels_begin; it != attic_rels_end; ++it)
937+
{
938+
if ((it->first.val() & 0x80000000) && ((it->first.val() & 0x3) == 0))
939+
{
940+
// Treat relations with really large indices: get the node indexes from the segement indexes
941+
for (typename std::vector< Attic< Relation_Skeleton > >::const_iterator it2 = it->second.begin();
942+
it2 != it->second.end(); ++it2)
943+
{
944+
for (std::vector< Uint31_Index >::const_iterator it3 = it2->node_idxs.begin();
945+
it3 != it2->node_idxs.end(); ++it3)
946+
parents.push_back(it3->val());
947+
}
948+
}
949+
else
950+
parents.push_back(it->first.val());
951+
}
952+
if (stmt)
953+
rman.health_check(*stmt);
954+
955+
return collect_node_req(stmt, rman, std::vector< Node::Id_Type >(), parents);
956+
}
957+
958+
959+
std::set< std::pair< Uint32_Index, Uint32_Index > > way_nd_indices
960+
(const Statement* stmt, Resource_Manager& rman,
961+
std::map< Uint31_Index, std::vector< Way_Skeleton > >::const_iterator ways_begin,
962+
std::map< Uint31_Index, std::vector< Way_Skeleton > >::const_iterator ways_end);
963+
964+
965+
std::set< std::pair< Uint32_Index, Uint32_Index > > way_nd_indices
966+
(const Statement* stmt, Resource_Manager& rman,
967+
std::map< Uint31_Index, std::vector< Way_Skeleton > >::const_iterator ways_begin,
968+
std::map< Uint31_Index, std::vector< Way_Skeleton > >::const_iterator ways_end,
969+
std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >::const_iterator attic_ways_begin,
970+
std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >::const_iterator attic_ways_end);
971+
972+
855973
#endif

src/overpass_api/statements/recurse.cc

Lines changed: 98 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,8 +1158,7 @@ class Recurse_Constraint : public Query_Constraint
11581158
virtual bool get_ranges
11591159
(Resource_Manager& rman, set< pair< Uint31_Index, Uint31_Index > >& ranges);
11601160
virtual bool get_ranges
1161-
(Resource_Manager& rman, set< pair< Uint32_Index, Uint32_Index > >& ranges)
1162-
{ return false; }
1161+
(Resource_Manager& rman, set< pair< Uint32_Index, Uint32_Index > >& ranges);
11631162

11641163
bool delivers_data(Resource_Manager& rman) { return true; }
11651164

@@ -1181,6 +1180,67 @@ class Recurse_Constraint : public Query_Constraint
11811180
};
11821181

11831182

1183+
bool Recurse_Constraint::get_ranges(Resource_Manager& rman, set< pair< Uint32_Index, Uint32_Index > >& ranges)
1184+
{
1185+
ranges.clear();
1186+
1187+
map< string, Set >::const_iterator mit = rman.sets().find(stmt->get_input());
1188+
if (mit == rman.sets().end())
1189+
{
1190+
return true;
1191+
}
1192+
1193+
uint64 timestamp = rman.get_desired_timestamp();
1194+
if (timestamp == 0)
1195+
timestamp = NOW;
1196+
1197+
if (timestamp == NOW)
1198+
{
1199+
if (stmt->get_type() == RECURSE_RELATION_NODE)
1200+
{
1201+
relation_node_member_indices< Relation_Skeleton >(
1202+
stmt, rman, mit->second.relations.begin(), mit->second.relations.end()).swap(ranges);
1203+
1204+
return true;
1205+
}
1206+
else if (stmt->get_type() == RECURSE_WAY_NODE)
1207+
{
1208+
way_nd_indices(stmt, rman, mit->second.ways.begin(), mit->second.ways.end()).swap(ranges);
1209+
1210+
return true;
1211+
}
1212+
else if (stmt->get_type() == RECURSE_DOWN)
1213+
return false;
1214+
else if (stmt->get_type() == RECURSE_DOWN_REL)
1215+
return false;
1216+
}
1217+
else
1218+
{
1219+
if (stmt->get_type() == RECURSE_RELATION_NODE)
1220+
{
1221+
relation_node_member_indices< Relation_Skeleton >(
1222+
stmt, rman, mit->second.relations.begin(), mit->second.relations.end(),
1223+
mit->second.attic_relations.begin(), mit->second.attic_relations.end()).swap(ranges);
1224+
1225+
return true;
1226+
}
1227+
else if (stmt->get_type() == RECURSE_WAY_NODE)
1228+
{
1229+
way_nd_indices(stmt, rman, mit->second.ways.begin(), mit->second.ways.end(),
1230+
mit->second.attic_ways.begin(), mit->second.attic_ways.end()).swap(ranges);
1231+
1232+
return true;
1233+
}
1234+
else if (stmt->get_type() == RECURSE_DOWN)
1235+
return false;
1236+
else if (stmt->get_type() == RECURSE_DOWN_REL)
1237+
return false;
1238+
}
1239+
1240+
return false;
1241+
}
1242+
1243+
11841244
bool Recurse_Constraint::get_ranges(Resource_Manager& rman, set< pair< Uint31_Index, Uint31_Index > >& ranges)
11851245
{
11861246
ranges.clear();
@@ -1212,12 +1272,22 @@ bool Recurse_Constraint::get_ranges(Resource_Manager& rman, set< pair< Uint31_In
12121272
return false;
12131273
else if (stmt->get_type() == RECURSE_DOWN_REL)
12141274
return false;
1215-
else if (stmt->get_type() == RECURSE_NODE_WAY)
1216-
return false;
1217-
else if (stmt->get_type() == RECURSE_NODE_RELATION)
1218-
return false;
1275+
else if (stmt->get_type() == RECURSE_NODE_WAY || stmt->get_type() == RECURSE_NODE_RELATION)
1276+
{
1277+
std::set< Uint31_Index > req = extract_parent_indices(mit->second.nodes);
1278+
for (std::set< Uint31_Index >::const_iterator it = req.begin(); it != req.end(); ++it)
1279+
ranges.insert(std::make_pair(*it, inc(*it)));
1280+
1281+
return true;
1282+
}
12191283
else if (stmt->get_type() == RECURSE_WAY_RELATION)
1220-
return false;
1284+
{
1285+
std::set< Uint31_Index > req = extract_parent_indices(mit->second.ways);
1286+
for (std::set< Uint31_Index >::const_iterator it = req.begin(); it != req.end(); ++it)
1287+
ranges.insert(std::make_pair(*it, inc(*it)));
1288+
1289+
return true;
1290+
}
12211291
else if (stmt->get_type() == RECURSE_RELATION_BACKWARDS)
12221292
return false;
12231293
else if (stmt->get_type() == RECURSE_UP)
@@ -1245,12 +1315,28 @@ bool Recurse_Constraint::get_ranges(Resource_Manager& rman, set< pair< Uint31_In
12451315
return false;
12461316
else if (stmt->get_type() == RECURSE_DOWN_REL)
12471317
return false;
1248-
else if (stmt->get_type() == RECURSE_NODE_WAY)
1249-
return false;
1250-
else if (stmt->get_type() == RECURSE_NODE_RELATION)
1251-
return false;
1318+
else if (stmt->get_type() == RECURSE_NODE_WAY || stmt->get_type() == RECURSE_NODE_RELATION)
1319+
{
1320+
std::set< Uint31_Index > req = extract_parent_indices(mit->second.nodes);
1321+
for (std::set< Uint31_Index >::const_iterator it = req.begin(); it != req.end(); ++it)
1322+
ranges.insert(std::make_pair(*it, inc(*it)));
1323+
std::set< Uint31_Index > attic_req = extract_parent_indices(mit->second.attic_nodes);
1324+
for (std::set< Uint31_Index >::const_iterator it = attic_req.begin(); it != attic_req.end(); ++it)
1325+
ranges.insert(std::make_pair(*it, inc(*it)));
1326+
1327+
return true;
1328+
}
12521329
else if (stmt->get_type() == RECURSE_WAY_RELATION)
1253-
return false;
1330+
{
1331+
std::set< Uint31_Index > req = extract_parent_indices(mit->second.ways);
1332+
for (std::set< Uint31_Index >::const_iterator it = req.begin(); it != req.end(); ++it)
1333+
ranges.insert(std::make_pair(*it, inc(*it)));
1334+
std::set< Uint31_Index > attic_req = extract_parent_indices(mit->second.attic_ways);
1335+
for (std::set< Uint31_Index >::const_iterator it = attic_req.begin(); it != attic_req.end(); ++it)
1336+
ranges.insert(std::make_pair(*it, inc(*it)));
1337+
1338+
return true;
1339+
}
12541340
else if (stmt->get_type() == RECURSE_RELATION_BACKWARDS)
12551341
return false;
12561342
else if (stmt->get_type() == RECURSE_UP)

0 commit comments

Comments
 (0)