Skip to content

Commit

Permalink
exactly half the id space for points, the other half for the rest
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbr committed Oct 14, 2024
1 parent 616440b commit 575a649
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
28 changes: 27 additions & 1 deletion src/qlever-petrimaps/GeomCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -908,6 +908,11 @@ size_t GeomCache::parseMultiPoint(const std::string &str, size_t p, size_t end,
_pointsF.write(reinterpret_cast<const char *>(&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<const char *>(&idm), sizeof(IdMapping));
Expand All @@ -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<ID_TYPE>::max() - I_OFFSET) {
std::stringstream ss;
ss << "Maximum number of non-point objects ("
<< std::numeric_limits<ID_TYPE>::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<const char *>(&idm), sizeof(IdMapping));
Expand All @@ -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<ID_TYPE>::max() - I_OFFSET) {
std::stringstream ss;
ss << "Maximum number of non-point objects ("
<< std::numeric_limits<ID_TYPE>::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<const char *>(&idm), sizeof(IdMapping));
Expand All @@ -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<ID_TYPE>::max() - I_OFFSET) {
std::stringstream ss;
ss << "Maximum number of non-point objects ("
<< std::numeric_limits<ID_TYPE>::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<const char *>(&idm), sizeof(IdMapping));
Expand Down
4 changes: 2 additions & 2 deletions src/qlever-petrimaps/Misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down

0 comments on commit 575a649

Please sign in to comment.