From 575a649c805fb1b73fb6a81ad76370d6412b6494 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Mon, 14 Oct 2024 12:07:28 +0200 Subject: [PATCH] exactly half the id space for points, the other half for the rest --- src/qlever-petrimaps/GeomCache.cpp | 28 +++++++++++++++++++++++++++- src/qlever-petrimaps/Misc.h | 4 ++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/qlever-petrimaps/GeomCache.cpp b/src/qlever-petrimaps/GeomCache.cpp index 77aece5..e7c6068 100644 --- a/src/qlever-petrimaps/GeomCache.cpp +++ b/src/qlever-petrimaps/GeomCache.cpp @@ -542,7 +542,7 @@ void GeomCache::requestPart(size_t offset) { char errbuf[CURL_ERROR_SIZE]; if (_curl) { - auto qUrl = queryUrl(getQuery(_backendUrl), offset, 100000000); + auto qUrl = queryUrl(getQuery(_backendUrl), offset, 1000000); curl_easy_setopt(_curl, CURLOPT_URL, qUrl.c_str()); curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, GeomCache::writeCb); curl_easy_setopt(_curl, CURLOPT_WRITEDATA, this); @@ -908,6 +908,11 @@ size_t GeomCache::parseMultiPoint(const std::string &str, size_t p, size_t end, _pointsF.write(reinterpret_cast(&point), sizeof(util::geo::FPoint)); _pointsFSize++; + if (_pointsFSize >= I_OFFSET) { + std::stringstream ss; + ss << "Maximum number of points (" << I_OFFSET << ") exceeded."; + throw std::runtime_error(ss.str()); + } IdMapping idm{*i == 0 ? 0 : 1, _pointsFSize - 1}; _lastQidToId = idm; _qidToIdF.write(reinterpret_cast(&idm), sizeof(IdMapping)); @@ -931,6 +936,13 @@ size_t GeomCache::parseMultiPolygon(const std::string &str, size_t p, _linesFSize++; insertLine(line, true); + if (_linesFSize - 1 >= std::numeric_limits::max() - I_OFFSET) { + std::stringstream ss; + ss << "Maximum number of non-point objects (" + << std::numeric_limits::max() - I_OFFSET << ") exceeded."; + throw std::runtime_error(ss.str()); + } + IdMapping idm{*i == 0 ? 0 : 1, I_OFFSET + _linesFSize - 1}; _lastQidToId = idm; _qidToIdF.write(reinterpret_cast(&idm), sizeof(IdMapping)); @@ -953,6 +965,13 @@ size_t GeomCache::parseMultiLineString(const std::string &str, size_t p, _linesFSize++; insertLine(line, false); + if (_linesFSize - 1 >= std::numeric_limits::max() - I_OFFSET) { + std::stringstream ss; + ss << "Maximum number of non-point objects (" + << std::numeric_limits::max() - I_OFFSET << ") exceeded."; + throw std::runtime_error(ss.str()); + } + IdMapping idm{*i == 0 ? 0 : 1, I_OFFSET + _linesFSize - 1}; _lastQidToId = idm; _qidToIdF.write(reinterpret_cast(&idm), sizeof(IdMapping)); @@ -975,6 +994,13 @@ size_t GeomCache::parsePolygon(const std::string &str, size_t p, size_t end, _linesFSize++; insertLine(line, true); + if (_linesFSize - 1 >= std::numeric_limits::max() - I_OFFSET) { + std::stringstream ss; + ss << "Maximum number of non-point objects (" + << std::numeric_limits::max() - I_OFFSET << ") exceeded."; + throw std::runtime_error(ss.str()); + } + IdMapping idm{*i == 0 ? 0 : 1, I_OFFSET + _linesFSize - 1}; _lastQidToId = idm; _qidToIdF.write(reinterpret_cast(&idm), sizeof(IdMapping)); diff --git a/src/qlever-petrimaps/Misc.h b/src/qlever-petrimaps/Misc.h index 3782280..674751f 100644 --- a/src/qlever-petrimaps/Misc.h +++ b/src/qlever-petrimaps/Misc.h @@ -18,7 +18,8 @@ #define ID_TYPE uint32_t #define QLEVER_ID_TYPE size_t -const static ID_TYPE I_OFFSET = 500000000; +// half of the ID space for points, half for the rest +const static ID_TYPE I_OFFSET = 2147483648; const static size_t MAXROWS = 18446744073709551615u; // major coordinates will fit into 2^15, as coordinates go from @@ -42,7 +43,6 @@ union ID { inline bool operator<(const IdMapping& lh, const IdMapping& rh) { if (lh.qid < rh.qid) return true; - // if (lh.qid == rh.qid && lh.id < rh.id) return true; return false; }