Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/overpass_api/data/abstract_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@
#include "../statements/statement.h"
#include "filenames.h"

#include <cstdint>

template< class Id_Type >
inline bool monobound_binary_search(const std::vector<Id_Type> & vec, Id_Type key)
{
if (vec.empty())
return false;

uint32_t lower = 0;
uint32_t upper = vec.size();

while (upper > 1)
{
uint32_t middle = upper / 2;

if (!(key < vec[lower + middle]))
{
lower += middle;
}
upper -= middle;
}

return (key == vec[lower]);
}

//-----------------------------------------------------------------------------

Expand Down
6 changes: 3 additions & 3 deletions src/overpass_api/data/filter_ids_by_tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ void filter_ids_by_tags
}
}

if (key_relevant && valid && std::binary_search(old_ids.begin(), old_ids.end(), tag_it.object()))
if (key_relevant && valid && monobound_binary_search(old_ids, tag_it.object()))
new_ids.push_back(tag_it.object());

if (!matched_by_both_regexes.empty() &&
(std::binary_search(old_ids.begin(), old_ids.end(), tag_it.object()) ||
std::binary_search(new_ids.begin(), new_ids.end(), tag_it.object())))
(monobound_binary_search(old_ids, tag_it.object()) ||
monobound_binary_search(new_ids, tag_it.object())))
{
for (std::vector< uint64 >::const_iterator reg_it = matched_by_both_regexes.begin();
reg_it != matched_by_both_regexes.end(); ++reg_it)
Expand Down
4 changes: 2 additions & 2 deletions src/overpass_api/data/set_comparison.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void Set_Comparison::tags_quadtile
for (typename std::vector< Object >::const_iterator it2(item_it->second.begin());
it2 != item_it->second.end(); ++it2)
{
if (std::binary_search(id_list.begin(), id_list.end(), it2->id))
if (monobound_binary_search(id_list, it2->id))
print_item(extra_data, item_it->first.val(), *it2, tag_store.get(item_it->first, *it2),
meta_printer.get(item_it->first, it2->id), extra_data.users);
}
Expand All @@ -325,7 +325,7 @@ void Set_Comparison::tags_quadtile_attic
for (typename std::vector< Attic< Object > >::const_iterator it2(item_it->second.begin());
it2 != item_it->second.end(); ++it2)
{
if (std::binary_search(id_list.begin(), id_list.end(), it2->id))
if (monobound_binary_search(id_list, it2->id))
print_item(extra_data, item_it->first.val(), *it2, tag_store.get(item_it->first, *it2),
meta_printer.get(item_it->first, it2->id, it2->timestamp), extra_data.users);
}
Expand Down
5 changes: 2 additions & 3 deletions src/overpass_api/data/tag_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void collect_tags
while ((!(tag_it == items_db.range_end())) &&
(((tag_it.index().index) & 0x7fffff00) == coarse_index))
{
if ((binary_search(ids.begin(), ids.end(), tag_it.object())))
if ((monobound_binary_search(ids, tag_it.object())))
tags_by_id[tag_it.object()].push_back
(std::make_pair(tag_it.index().key, tag_it.index().value));
++tag_it;
Expand All @@ -257,8 +257,7 @@ void collect_tags_framed
{
if (!(tag_it.object() < lower_id_bound) &&
(tag_it.object() < upper_id_bound) &&
(binary_search(ids_by_coarse[coarse_index].begin(),
ids_by_coarse[coarse_index].end(), tag_it.object())))
(monobound_binary_search(ids_by_coarse[coarse_index], tag_it.object())))
tags_by_id[tag_it.object()].push_back
(std::make_pair(tag_it.index().key, tag_it.index().value));
++tag_it;
Expand Down
12 changes: 6 additions & 6 deletions src/overpass_api/statements/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void filter_ids_by_ntags
((tag_it.index().index) & 0x7fffff00) == coarse_index &&
tag_it.index().key == key_it->first)
{
if (std::binary_search(new_ids.begin(), new_ids.end(), tag_it.object()))
if (monobound_binary_search(new_ids, tag_it.object()))
{
std::pair< uint64, uint64 >& timestamp_ref = timestamps[tag_it.object()];
timestamp_ref.second = NOW;
Expand Down Expand Up @@ -333,7 +333,7 @@ void filter_ids_by_ntags
((attic_tag_it.index().index) & 0x7fffff00) == coarse_index &&
attic_tag_it.index().key == key_it->first)
{
if (std::binary_search(new_ids.begin(), new_ids.end(), Id_Type(attic_tag_it.object())))
if (monobound_binary_search(new_ids, Id_Type(attic_tag_it.object())))
{
std::pair< uint64, uint64 >& timestamp_ref = timestamps[attic_tag_it.object()];
if (timestamp < attic_tag_it.object().timestamp &&
Expand Down Expand Up @@ -403,7 +403,7 @@ void filter_by_ids(
for (typename std::vector< TObject >::const_iterator eit = item_it->second.begin();
eit != item_it->second.end(); ++eit)
{
if (std::binary_search(it->second.begin(), it->second.end(), eit->id))
if (monobound_binary_search(it->second, eit->id))
result[item_it->first.val()].push_back(*eit);
}
++item_it;
Expand All @@ -424,7 +424,7 @@ void filter_by_ids(
for (typename std::vector< TObject >::const_iterator eit = item_it->second.begin();
eit != item_it->second.end(); ++eit)
{
if (std::binary_search(it->second.begin(), it->second.end(), eit->id))
if (monobound_binary_search(it->second, eit->id))
result[item_it->first.val()].push_back(*eit);
}
++item_it;
Expand All @@ -436,7 +436,7 @@ void filter_by_ids(
for (typename std::vector< Attic< TObject > >::const_iterator eit = attic_item_it->second.begin();
eit != attic_item_it->second.end(); ++eit)
{
if (std::binary_search(it->second.begin(), it->second.end(), eit->id))
if (monobound_binary_search(it->second, eit->id))
attic_result[attic_item_it->first.val()].push_back(*eit);
}
++attic_item_it;
Expand Down Expand Up @@ -640,7 +640,7 @@ void Query_Statement::filter_by_tags
for (typename std::vector< TObject >::const_iterator eit = item_it->second.begin();
eit != item_it->second.end(); ++eit)
{
if (std::binary_search(ids_by_coarse_.begin(), ids_by_coarse_.end(), eit->id))
if (monobound_binary_search(ids_by_coarse_, eit->id))
result[item_it->first.val()].push_back(*eit);
}
++item_it;
Expand Down
Loading