Skip to content

Commit

Permalink
Further integration after request.
Browse files Browse the repository at this point in the history
  • Loading branch information
drolbr committed Apr 5, 2017
1 parent cd594e0 commit 00e1c01
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 128 deletions.
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,5 @@ EXTRA_DIST = \
rules/areas_delta.osm3s

# Put test-bin here and test-bin/Makefile in configure.ac to activate test-bin
#SUBDIRS = test-bin
SUBDIRS =
SUBDIRS = test-bin
#SUBDIRS =
4 changes: 2 additions & 2 deletions src/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ fi

AC_SUBST(COMPRESS_LIBS, ["$COMPRESS_LIBS"])

#AC_CONFIG_FILES([Makefile test-bin/Makefile])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([Makefile test-bin/Makefile])
#AC_CONFIG_FILES([Makefile])
AC_OUTPUT
AC_SYS_LARGEFILE

Expand Down
11 changes: 4 additions & 7 deletions src/overpass_api/frontend/map_ql_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,21 @@ TStatement* create_has_kv_statement(typename TStatement::Factory& stmt_factory,

template< class TStatement >
TStatement* create_id_query_statement(typename TStatement::Factory& stmt_factory,
std::string type, std::vector< std::string > ref, std::string into, uint line_nr)
std::string type, const std::vector< std::string >& ref, std::string into, uint line_nr)
{
std::map< std::string, std::string > attr;
int i;
std::vector< std::string >::iterator it;

attr["type"] = type;
attr["into"] = into;

for(it = ref.begin(), i = 0; it != ref.end(); ++it, ++i)
for (uint i = 0; i < ref.size(); ++i)
{
std::stringstream id;
if (i == 0)
id << "ref";
else
id << "ref_" << i;
attr[id.str()] = *it;
attr[id.str()] = ref[i];
}

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

template< class TStatement >
TStatement* create_bbox_statement(typename TStatement::Factory& stmt_factory,
std::string south, std::string north, std::string west, std::string east,
std::string into, uint line_nr)
std::string south, std::string north, std::string west, std::string east, std::string into, uint line_nr)
{
std::map< std::string, std::string > attr;
attr["s"] = south;
Expand Down
136 changes: 42 additions & 94 deletions src/overpass_api/statements/id_query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,74 +32,23 @@ bool Id_Query_Statement::area_query_exists_ = false;
Generic_Statement_Maker< Id_Query_Statement > Id_Query_Statement::statement_maker("id-query");


template< class TIndex, class TObject >
void collect_elems(Resource_Manager& rman, const File_Properties& prop,
const std::set<Uint64::Id_Type> & ref_ids,
std::map< TIndex, std::vector< TObject > >& elems)
{
std::set< TIndex > req;
{
Random_File< uint64, TIndex > random(rman.get_transaction()->random_index(&prop));
for (std::set<Uint64::Id_Type>::iterator it_ref = ref_ids.begin(); it_ref != ref_ids.end(); it_ref++)
req.insert(random.get(*it_ref));
}
Block_Backend< TIndex, TObject > elems_db(rman.get_transaction()->data_index(&prop));
for (typename Block_Backend< TIndex, TObject >::Discrete_Iterator
it(elems_db.discrete_begin(req.begin(), req.end()));
!(it == elems_db.discrete_end()); ++it)
{
if (ref_ids.find(it.object().id.val()) != ref_ids.end())
elems[it.index()].push_back(it.object());
}
}


template< class TIndex, class TObject >
void collect_elems(Resource_Manager& rman, const File_Properties& prop,
const std::set<Uint64::Id_Type> & ref_ids,
const std::vector< typename TObject::Id_Type >& ids, bool invert_ids,
std::map< TIndex, std::vector< TObject > >& elems)
{
std::set< TIndex > req;
{
Random_File< uint64, TIndex > random(rman.get_transaction()->random_index(&prop));
for (std::set<Uint64::Id_Type>::iterator it_ref = ref_ids.begin(); it_ref != ref_ids.end(); it_ref++)
{
if (binary_search(ids.begin(), ids.end(), *it_ref) ^ invert_ids)
req.insert(random.get(*it_ref));
}
}
Block_Backend< TIndex, TObject > elems_db(rman.get_transaction()->data_index(&prop));
for (typename Block_Backend< TIndex, TObject >::Discrete_Iterator
it(elems_db.discrete_begin(req.begin(), req.end()));
!(it == elems_db.discrete_end()); ++it)
{
if ((ref_ids.find(it.object().id.val()) != ref_ids.end())
&& (binary_search(ids.begin(), ids.end(), it.object().id) ^ invert_ids))
elems[it.index()].push_back(it.object());
}
}


void collect_elems_flat(Resource_Manager& rman,
const std::set<Uint64::Id_Type> & ref_ids,
const std::vector< Area_Skeleton::Id_Type >& ids, bool invert_ids,
const std::vector< uint64 >& ids,
std::map< Uint31_Index, std::vector< Area_Skeleton > >& elems)
{
Block_Backend< Uint31_Index, Area_Skeleton > elems_db
(rman.get_transaction()->data_index(area_settings().AREAS));
for (Block_Backend< Uint31_Index, Area_Skeleton >::Flat_Iterator
it = elems_db.flat_begin(); !(it == elems_db.flat_end()); ++it)
{
if ((ref_ids.find(it.object().id.val()) != ref_ids.end())
&& (binary_search(ids.begin(), ids.end(), it.object().id) ^ invert_ids))
if (std::binary_search(ids.begin(), ids.end(), it.object().id.val()))
elems[it.index()].push_back(it.object());
}
}


template< class TIndex, class TObject >
void filter_elems(const std::set<Uint64::Id_Type> & ref_ids,
void filter_elems(const std::vector< uint64 > & ids,
std::map< TIndex, std::vector< TObject > >& elems)
{
for (typename std::map< TIndex, std::vector< TObject > >::iterator it = elems.begin();
Expand All @@ -109,7 +58,7 @@ void filter_elems(const std::set<Uint64::Id_Type> & ref_ids,
for (typename std::vector< TObject >::const_iterator iit = it->second.begin();
iit != it->second.end(); ++iit)
{
if (ref_ids.find(iit->id.val()) != ref_ids.end())
if (std::binary_search(ids.begin(), ids.end(), iit->id.val()))
local_into.push_back(*iit);
}
it->second.swap(local_into);
Expand Down Expand Up @@ -150,9 +99,8 @@ bool Id_Query_Constraint::get_node_ids(Resource_Manager& rman, std::vector< Node
{
ids.clear();
if (stmt->get_type() == Statement::NODE)
{
ids.assign(stmt->get_ref_ids().begin(), stmt->get_ref_ids().end());
}
ids.assign(stmt->get_refs().begin(), stmt->get_refs().end());

return true;
}

Expand All @@ -161,9 +109,8 @@ bool Id_Query_Constraint::get_way_ids(Resource_Manager& rman, std::vector< Way_S
{
ids.clear();
if (stmt->get_type() == Statement::WAY)
{
ids.assign(stmt->get_ref_ids().begin(), stmt->get_ref_ids().end());
}
ids.assign(stmt->get_refs().begin(), stmt->get_refs().end());

return true;
}

Expand All @@ -172,18 +119,17 @@ bool Id_Query_Constraint::get_relation_ids(Resource_Manager& rman, std::vector<
{
ids.clear();
if (stmt->get_type() == Statement::RELATION)
{
ids.assign(stmt->get_ref_ids().begin(), stmt->get_ref_ids().end());
}
ids.assign(stmt->get_refs().begin(), stmt->get_refs().end());

return true;
}


bool Id_Query_Constraint::get_ranges(Resource_Manager& rman, std::set< std::pair< Uint32_Index, Uint32_Index > >& ranges)
{
std::vector< Node_Skeleton::Id_Type > ids;

ids.assign(stmt->get_ref_ids().begin(), stmt->get_ref_ids().end());
ids.assign(stmt->get_refs().begin(), stmt->get_refs().end());

std::vector< Uint32_Index > req = get_indexes_< Uint32_Index, Node_Skeleton >(ids, rman);

ranges.clear();
Expand All @@ -200,13 +146,13 @@ bool Id_Query_Constraint::get_ranges(Resource_Manager& rman, std::set< std::pair
if (stmt->get_type() == Statement::WAY)
{
std::vector< Way_Skeleton::Id_Type > ids;
ids.assign(stmt->get_ref_ids().begin(), stmt->get_ref_ids().end());
ids.assign(stmt->get_refs().begin(), stmt->get_refs().end());
get_indexes_< Uint31_Index, Way_Skeleton >(ids, rman).swap(req);
}
else
{
std::vector< Relation_Skeleton::Id_Type > ids;
ids.assign(stmt->get_ref_ids().begin(), stmt->get_ref_ids().end());
ids.assign(stmt->get_refs().begin(), stmt->get_refs().end());
get_indexes_< Uint31_Index, Relation_Skeleton >(ids, rman).swap(req);
}

Expand All @@ -222,30 +168,30 @@ void Id_Query_Constraint::filter(Resource_Manager& rman, Set& into, uint64 times
{
if (stmt->get_type() == Statement::NODE)
{
filter_elems(stmt->get_ref_ids(), into.nodes);
filter_elems(stmt->get_ref_ids(), into.attic_nodes);
filter_elems(stmt->get_refs(), into.nodes);
filter_elems(stmt->get_refs(), into.attic_nodes);
}
else
into.nodes.clear();

if (stmt->get_type() == Statement::WAY)
{
filter_elems(stmt->get_ref_ids(), into.ways);
filter_elems(stmt->get_ref_ids(), into.attic_ways);
filter_elems(stmt->get_refs(), into.ways);
filter_elems(stmt->get_refs(), into.attic_ways);
}
else
into.ways.clear();

if (stmt->get_type() == Statement::RELATION)
{
filter_elems(stmt->get_ref_ids(), into.relations);
filter_elems(stmt->get_ref_ids(), into.attic_relations);
filter_elems(stmt->get_refs(), into.relations);
filter_elems(stmt->get_refs(), into.attic_relations);
}
else
into.relations.clear();

if (stmt->get_type() == Statement::AREA)
filter_elems(stmt->get_ref_ids(), into.areas);
filter_elems(stmt->get_refs(), into.areas);
else
into.areas.clear();
}
Expand Down Expand Up @@ -295,28 +241,30 @@ Id_Query_Statement::Id_Query_Statement
add_static_error(temp.str());
}

ref = atoll(attributes["ref"].c_str());
uint64 ref = atoll(attributes["ref"].c_str());

if (ref.val() > 0)
ref_ids.insert(ref.val());
if (ref > 0)
refs.push_back(ref);

for (std::map<std::string, std::string>::iterator it = attributes.begin();
for (std::map< std::string, std::string >::iterator it = attributes.begin();
it != attributes.end(); ++it)
{
if (it->first.find("ref_") == 0)
{
ref = atoll(it->second.c_str());
if (ref.val() > 0)
ref_ids.insert(ref.val());
if (ref > 0)
refs.push_back(ref);
}
}
std::sort(refs.begin(), refs.end());
refs.erase(std::unique(refs.begin(), refs.end()), refs.end());

lower = atoll(attributes["lower"].c_str());
upper = atoll(attributes["upper"].c_str());
uint64 lower = atoll(attributes["lower"].c_str());
uint64 upper = atoll(attributes["upper"].c_str());

if (ref.val() <= 0)
if (ref <= 0)
{
if (lower.val() == 0 || upper.val() == 0)
if (lower == 0 || upper == 0)
{
std::ostringstream temp;
temp<<"For the attribute \"ref\" of the element \"id-query\""
Expand All @@ -331,10 +279,10 @@ Id_Query_Statement::Id_Query_Statement
upper = ++ref;
}

if (lower.val() > 0 && upper.val() > 0)
if (lower > 0 && upper > 0)
{
for (Uint64::Id_Type i = lower.val(); i < upper.val(); ++i)
ref_ids.insert(i);
for (uint64 i = lower; i < upper; ++i)
refs.push_back(i);
}
}

Expand Down Expand Up @@ -393,12 +341,12 @@ struct Attic_Skeleton_By_Id


template< typename Index, typename Skeleton >
void get_elements(const std::set<Uint64::Id_Type> & ref_ids, Statement* stmt, Resource_Manager& rman,
void get_elements(const std::vector< uint64 >& refs, Statement* stmt, Resource_Manager& rman,
std::map< Index, std::vector< Skeleton > >& current_result,
std::map< Index, std::vector< Attic< Skeleton > > >& attic_result)
{
std::vector< typename Skeleton::Id_Type > ids;
ids.assign(ref_ids.begin(), ref_ids.end());
ids.assign(refs.begin(), refs.end());
std::vector< Index > req = get_indexes_< Index, Skeleton >(ids, rman);

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

if (type == NODE)
get_elements(ref_ids, this, rman, into.nodes, into.attic_nodes);
get_elements(refs, this, rman, into.nodes, into.attic_nodes);
else if (type == WAY)
get_elements(ref_ids, this, rman, into.ways, into.attic_ways);
get_elements(refs, this, rman, into.ways, into.attic_ways);
else if (type == RELATION)
get_elements(ref_ids, this, rman, into.relations, into.attic_relations);
get_elements(refs, this, rman, into.relations, into.attic_relations);
else if (type == AREA)
collect_elems_flat(rman, ref_ids, std::vector< Area_Skeleton::Id_Type >(), true, into.areas);
collect_elems_flat(rman, refs, into.areas);

transfer_output(rman, into);
rman.health_check(*this);
Expand Down
Loading

0 comments on commit 00e1c01

Please sign in to comment.