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
55 changes: 55 additions & 0 deletions src/overpass_api/core/type_tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,61 @@ void generate_ids_by_coarse
}


// As generate_ids_by_coarse, but only for the elements with ids in [lower_id_bound, upper_id_bound),
// so that a chunk of output needs the ids of that chunk only.
template< class TIndex, class TObject >
void generate_ids_by_coarse
(std::map< uint32, std::vector< typename TObject::Id_Type > >& ids_by_coarse,
const std::map< TIndex, std::vector< TObject > >& items,
typename TObject::Id_Type lower_id_bound, typename TObject::Id_Type upper_id_bound)
{
for (typename std::map< TIndex, std::vector< TObject > >::const_iterator
it(items.begin()); it != items.end(); ++it)
{
for (typename std::vector< TObject >::const_iterator it2(it->second.begin());
it2 != it->second.end(); ++it2)
{
if (!(it2->id < lower_id_bound) && it2->id < upper_id_bound)
ids_by_coarse[it->first.val() & 0x7fffff00].push_back(it2->id);
}
}

for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator
it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
{
std::sort(it->second.begin(), it->second.end());
it->second.erase(std::unique(it->second.begin(), it->second.end()), it->second.end());
}
}


template< class TIndex, class TObject >
void generate_ids_by_coarse
(std::map< uint32, std::vector< Attic< typename TObject::Id_Type > > >& ids_by_coarse,
const std::map< TIndex, std::vector< TObject > >& items,
typename TObject::Id_Type lower_id_bound, typename TObject::Id_Type upper_id_bound)
{
for (typename std::map< TIndex, std::vector< TObject > >::const_iterator
it(items.begin()); it != items.end(); ++it)
{
for (typename std::vector< TObject >::const_iterator it2(it->second.begin());
it2 != it->second.end(); ++it2)
{
if (!(it2->id < lower_id_bound) && it2->id < upper_id_bound)
ids_by_coarse[it->first.val() & 0x7fffff00].push_back
(Attic< typename TObject::Id_Type >(it2->id, it2->timestamp));
}
}

for (typename std::map< uint32, std::vector< Attic< typename TObject::Id_Type > > >::iterator
it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
{
std::sort(it->second.begin(), it->second.end());
it->second.erase(std::unique(it->second.begin(), it->second.end()), it->second.end());
}
}


struct Tag_Index_Global_Until756
{
std::string key;
Expand Down
14 changes: 6 additions & 8 deletions src/overpass_api/data/tag_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,9 @@ void Tag_Store< Index, Object >::prefetch_chunk(const std::map< Index, std::vect
{
tags_by_id.clear();

// The coarse indices and ids of the whole set, needed for every chunk. elems is the same set on
// every call, so they are generated once: generating them again appended every id a second
// time before deduplicating, which cost time and twice their memory on each chunk.
if (ids_by_coarse.empty())
generate_ids_by_coarse(ids_by_coarse, elems);
// The coarse indices and ids of this chunk's elements only: no other tags are collected.
ids_by_coarse.clear();
generate_ids_by_coarse(ids_by_coarse, elems, lower_id_bound, upper_id_bound);

Block_Backend< Tag_Index_Local, typename Object::Id_Type > items_db
(transaction->data_index(current_local_tags_file_properties< Object >()));
Expand Down Expand Up @@ -356,10 +354,10 @@ template< typename Index, typename Object >
void Tag_Store< Index, Object >::prefetch_chunk(const std::map< Index, std::vector< Attic< Object > > >& attic_items,
typename Object::Id_Type lower_id_bound, typename Object::Id_Type upper_id_bound)
{
// As for current elements: only this chunk's tags are needed, and the ids once.
// As for current elements: only this chunk's tags and ids are needed.
tags_by_id.clear();
if (attic_ids_by_coarse.empty())
generate_ids_by_coarse(attic_ids_by_coarse, attic_items);
attic_ids_by_coarse.clear();
generate_ids_by_coarse(attic_ids_by_coarse, attic_items, lower_id_bound, upper_id_bound);

Block_Backend< Tag_Index_Local, typename Object::Id_Type > current_tags_db
(transaction->data_index(current_local_tags_file_properties< Object >()));
Expand Down