mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-21 05:43:37 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
68
indexer/scale_index.hpp
Normal file
68
indexer/scale_index.hpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include "indexer/data_factory.hpp"
|
||||
#include "indexer/interval_index.hpp"
|
||||
|
||||
#include "coding/var_serial_vector.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
|
||||
/// Index bucket <--> Draw scale range.
|
||||
/// Using default one-to-one mapping.
|
||||
class ScaleIndexBase
|
||||
{
|
||||
public:
|
||||
static uint32_t GetBucketsCount() { return 18; }
|
||||
static uint32_t BucketByScale(int scale) { return static_cast<uint32_t>(scale); }
|
||||
/// @return Range like [x, y).
|
||||
static std::pair<uint32_t, uint32_t> ScaleRangeForBucket(uint32_t bucket)
|
||||
{
|
||||
return {bucket, bucket + 1};
|
||||
}
|
||||
};
|
||||
|
||||
template <class Reader>
|
||||
class ScaleIndex : public ScaleIndexBase
|
||||
{
|
||||
public:
|
||||
ScaleIndex() = default;
|
||||
|
||||
ScaleIndex(Reader const & reader, IndexFactory const & factory) { Attach(reader, factory); }
|
||||
|
||||
~ScaleIndex()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
m_IndexForScale.clear();
|
||||
}
|
||||
|
||||
void Attach(Reader const & reader, IndexFactory const & factory)
|
||||
{
|
||||
Clear();
|
||||
|
||||
ReaderSource<Reader> source(reader);
|
||||
VarSerialVectorReader<Reader> treesReader(source);
|
||||
for (uint32_t i = 0; i < treesReader.Size(); ++i)
|
||||
m_IndexForScale.push_back(factory.CreateIndex(treesReader.SubReader(i)));
|
||||
}
|
||||
|
||||
void ForEachInIntervalAndScale(uint64_t beg, uint64_t end, int scale,
|
||||
std::function<void(uint64_t, uint32_t)> const & fn) const
|
||||
{
|
||||
auto const scaleBucket = BucketByScale(scale);
|
||||
if (scaleBucket < m_IndexForScale.size())
|
||||
{
|
||||
for (size_t i = 0; i <= scaleBucket; ++i)
|
||||
m_IndexForScale[i]->ForEach(fn, beg, end);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<IntervalIndex<Reader, uint32_t>>> m_IndexForScale;
|
||||
};
|
||||
Reference in New Issue
Block a user