1#ifndef OSMSCOUT_IMPORT_GENCOORDDATA_H
2#define OSMSCOUT_IMPORT_GENCOORDDATA_H
37 std::map<Id,uint8_t> idToSerialMap;
45 template<
typename I,
typename E>
49 std::map<I,std::vector<E>> pages;
50 uint32_t maximumEntriesInMemory;
52 uint32_t overallEntryCount;
53 std::function<void(
const I&,std::vector<E>&&)> processor;
56 uint32_t processedPagesCount;
57 uint32_t processedPagesEntryCount;
58 uint32_t handledPagesEntryCount;
63 uint32_t overallEntryCount,
64 std::function<
void(
const I&,std::vector<E>&&)> processor)
65 : maximumEntriesInMemory(maximumEntriesInMemory),
67 overallEntryCount(overallEntryCount),
69 minPageId(
std::numeric_limits<I>::min()/static_cast<I>(pageSize)),
70 maxPageId(
std::numeric_limits<I>::max()/static_cast<I>(pageSize)),
71 processedPagesCount(0u),
72 processedPagesEntryCount(0u),
73 handledPagesEntryCount(0u)
83 return processedPagesCount;
88 return processedPagesEntryCount;
95 return pageId>=minPageId && pageId<=maxPageId;
100 I pageId=
id/pageSize;
102 pages[pageId].push_back(entry);
103 handledPagesEntryCount++;
105 if (handledPagesEntryCount<maximumEntriesInMemory ||
110 [[maybe_unused]] I oldMaxPageId=maxPageId;
112 while (handledPagesEntryCount>maximumEntriesInMemory
114 auto pageEntry=pages.rbegin();
115 I currentMaxPageId=pageEntry->first;
117 handledPagesEntryCount-=(uint32_t)pageEntry->second.size();
118 pages.erase(currentMaxPageId);
119 maxPageId=currentMaxPageId-1;
122 assert(maxPageId<=oldMaxPageId);
127 return processedPagesEntryCount+handledPagesEntryCount==overallEntryCount;
132 processedPagesEntryCount+=handledPagesEntryCount;
134 for (
auto& pageEntry : pages) {
135 processor(pageEntry.first,std::move(pageEntry.second));
136 processedPagesCount++;
139 handledPagesEntryCount=0;
141 minPageId=maxPageId+1;
142 maxPageId=std::numeric_limits<OSMId>::max()/pageSize;
146 template<
typename I,
typename E>
153 size_t processedPagesCount;
155 std::function<void(
const I&,std::vector<E>&)> processor;
160 processor(currentPageId,page);
163 processedPagesCount++;
166 void InitializePage()
168 std::for_each(page.begin(),page.end(),[](E& entry) {
177 std::function<
void(
const I&,std::vector<E>&)> processor)
178 : pageSize(pageSize),
179 currentPageId(
std::numeric_limits<I>::min()),
181 processedPagesCount(0),
187 void Set(
const I&
id,
const E& value)
189 I relatedId=std::numeric_limits<I>::min()+id;
190 I pageId=relatedId/pageSize;
191 I index=relatedId%pageSize;
193 if (pageId!=currentPageId) {
198 currentPageId=pageId;
214 return processedPagesCount;
218 class CoordDataGenerator
CLASS_FINAL :
public ImportModule
221 bool FindDuplicateCoordinates(
const TypeConfig& typeConfig,
222 const ImportParameter& parameter,
224 SerialIdManager& serialIdManager)
const;
226 bool StoreCoordinates(
const TypeConfig& typeConfig,
227 const ImportParameter& parameter,
229 SerialIdManager& serialIdManager)
const;
233 ImportModuleDescription& description)
const override;
#define CLASS_FINAL
Definition Compiler.h:26
void GetDescription(const ImportParameter ¶meter, ImportModuleDescription &description) const override
void MarkIdAsDuplicate(Id id)
uint8_t GetNextSerialForId(Id id)
bool Import(const TypeConfigRef &typeConfig, const ImportParameter ¶meter, Progress &progress) override
bool AreAllEntriesLoaded() const
Definition GenCoordDat.h:125
bool IsACurrentlyHandledPage(const I &id) const
Definition GenCoordDat.h:91
uint32_t GetProcessedPagesCount() const
Definition GenCoordDat.h:81
PageManager(uint32_t maximumEntriesInMemory, uint32_t pageSize, uint32_t overallEntryCount, std::function< void(const I &, std::vector< E > &&)> processor)
Definition GenCoordDat.h:61
I GetMinPageId() const
Definition GenCoordDat.h:77
void AddEntry(const I &id, const E &entry)
Definition GenCoordDat.h:98
void FileCompletelyScanned()
Definition GenCoordDat.h:130
uint32_t GetProcessedPagesEntryCount() const
Definition GenCoordDat.h:86
size_t GetProcessedPagesCount() const
Definition GenCoordDat.h:212
PageSplitter(size_t pageSize, std::function< void(const I &, std::vector< E > &)> processor)
Definition GenCoordDat.h:176
void Set(const I &id, const E &value)
Definition GenCoordDat.h:187
void FileCompletelyScanned()
Definition GenCoordDat.h:205
uint64_t Id
Definition OSMScoutTypes.h:40
std::shared_ptr< TypeConfig > TypeConfigRef
Definition TypeConfig.h:1396