Skip to content

Commit

Permalink
Reverted datastructure in SPARQLCache for _lines
Browse files Browse the repository at this point in the history
and _points because it handles multi-geometries
differently than GeoJSONCache.
  • Loading branch information
Grandro committed Jun 27, 2024
1 parent d289341 commit 4d8e817
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
12 changes: 12 additions & 0 deletions src/qlever-petrimaps/GeoJSONCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class GeoJSONCache : public GeomCache {
return *this;
};

const util::geo::FPoint& getPoint(ID_TYPE id) const {
return std::get<0>(_points[id]);
}
size_t getLine(ID_TYPE id) const {
return std::get<0>(_lines[id]);
}
size_t getLineEnd(ID_TYPE id) const {
return id + 1 < _lines.size() ? getLine(id + 1) : _linePoints.size();
}

void load();
void setContent(const std::string& content);
std::vector<std::pair<ID_TYPE, ID_TYPE>> getRelObjects() const;
Expand All @@ -36,6 +46,8 @@ class GeoJSONCache : public GeomCache {
// Map geomID to map<key, value>
std::map<size_t, std::map<std::string, std::string>> _attr;
// ------------------------
std::vector<std::tuple<util::geo::FPoint, bool>> _points;
std::vector<std::tuple<size_t, bool>> _lines;

protected:

Expand Down
15 changes: 4 additions & 11 deletions src/qlever-petrimaps/GeomCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,13 @@ class GeomCache {
return ready;
}

const util::geo::FPoint& getPoint(ID_TYPE id) const {
return std::get<0>(_points[id]);
}
const virtual util::geo::FPoint& getPoint(ID_TYPE id) const = 0;
virtual size_t getLine(ID_TYPE id) const = 0;
virtual size_t getLineEnd(ID_TYPE id) const = 0;

const std::vector<util::geo::Point<int16_t>>& getLinePoints() const {
return _linePoints;
}
size_t getLine(ID_TYPE id) const {
return std::get<0>(_lines[id]);
}
size_t getLineEnd(ID_TYPE id) const {
return id + 1 < _lines.size() ? getLine(id + 1) : _linePoints.size();
}

util::geo::DBox getLineBBox(size_t id) const;

Expand All @@ -74,8 +69,6 @@ class GeomCache {
mutable std::mutex _m;
bool _ready = false;

std::vector<std::tuple<util::geo::FPoint, bool>> _points;
std::vector<std::tuple<size_t, bool>> _lines;
std::vector<util::geo::Point<int16_t>> _linePoints;

static bool pointValid(const util::geo::FPoint& p);
Expand Down
12 changes: 6 additions & 6 deletions src/qlever-petrimaps/SPARQLCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ void SPARQLCache::request() {
_points.resize(_pointsFSize);
_pointsF.seekg(0);
_pointsF.read(reinterpret_cast<char*>(&_points[0]),
sizeof(std::tuple<util::geo::FPoint, bool>) * _pointsFSize);
sizeof(util::geo::FPoint) * _pointsFSize);
_pointsF.close();

_linePoints.resize(_linePointsFSize);
Expand All @@ -641,7 +641,7 @@ void SPARQLCache::request() {
_lines.resize(_linesFSize);
_linesF.seekg(0);
_linesF.read(reinterpret_cast<char*>(&_lines[0]),
sizeof(std::tuple<size_t, bool>) * _linesFSize);
sizeof(size_t) * _linesFSize);
_linesF.close();

_qidToId.resize(_qidToIdFSize);
Expand Down Expand Up @@ -950,7 +950,7 @@ void SPARQLCache::fromDisk(const std::string& fname) {
f.read(reinterpret_cast<char*>(&numPoints), sizeof(size_t));
_points.resize(numPoints);
posPoints = f.tellg();
f.seekg(sizeof(std::tuple<util::geo::FPoint, bool>) * numPoints, f.cur);
f.seekg(sizeof(util::geo::FPoint) * numPoints, f.cur);

// linePoints
f.read(reinterpret_cast<char*>(&numLinePoints), sizeof(size_t));
Expand All @@ -962,7 +962,7 @@ void SPARQLCache::fromDisk(const std::string& fname) {
f.read(reinterpret_cast<char*>(&numLines), sizeof(size_t));
_lines.resize(numLines);
posLines = f.tellg();
f.seekg(sizeof(std::tuple<size_t, bool>) * numLines, f.cur);
f.seekg(sizeof(size_t) * numLines, f.cur);

// qidToId
f.read(reinterpret_cast<char*>(&numQidToId), sizeof(size_t));
Expand Down Expand Up @@ -1020,7 +1020,7 @@ void SPARQLCache::serializeToDisk(const std::string& fname) const {
size_t num = _points.size();
f.write(reinterpret_cast<const char*>(&num), sizeof(size_t));
f.write(reinterpret_cast<const char*>(&_points[0]),
sizeof(std::tuple<util::geo::FPoint, bool>) * num);
sizeof(util::geo::FPoint) * num);

num = _linePoints.size();
f.write(reinterpret_cast<const char*>(&num), sizeof(size_t));
Expand All @@ -1029,7 +1029,7 @@ void SPARQLCache::serializeToDisk(const std::string& fname) const {

num = _lines.size();
f.write(reinterpret_cast<const char*>(&num), sizeof(size_t));
f.write(reinterpret_cast<const char*>(&_lines[0]), sizeof(std::tuple<size_t, bool>) * num);
f.write(reinterpret_cast<const char*>(&_lines[0]), sizeof(size_t) * num);

num = _qidToId.size();
f.write(reinterpret_cast<const char*>(&num), sizeof(size_t));
Expand Down
12 changes: 12 additions & 0 deletions src/qlever-petrimaps/SPARQLCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ class SPARQLCache : public GeomCache {
return *this;
};

const util::geo::FPoint& getPoint(ID_TYPE id) const {
return _points[id];
}
size_t getLine(ID_TYPE id) const {
return _lines[id];
}
size_t getLineEnd(ID_TYPE id) const {
return id + 1 < _lines.size() ? getLine(id + 1) : _linePoints.size();
}

std::string load(const std::string& cacheFile);
void request();
size_t requestSize();
Expand Down Expand Up @@ -83,6 +93,8 @@ class SPARQLCache : public GeomCache {
IdMapping _lastQidToId;

std::vector<IdMapping> _qidToId;
std::vector<util::geo::FPoint> _points;
std::vector<size_t> _lines;

std::string _dangling, _prev, _raw;
ParseState _state;
Expand Down

0 comments on commit 4d8e817

Please sign in to comment.