-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from Maxxen/dev
Cardinality estimation, replacement scans, misc fixes and breaking changes to `GEOMETRY` format.
- Loading branch information
Showing
21 changed files
with
694 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#pragma once | ||
#include "spatial/common.hpp" | ||
|
||
namespace spatial { | ||
|
||
namespace core { | ||
|
||
class Cursor { | ||
private: | ||
data_ptr_t start; | ||
data_ptr_t ptr; | ||
data_ptr_t end; | ||
|
||
public: | ||
enum class Offset { START, CURRENT, END }; | ||
|
||
explicit Cursor(data_ptr_t start, data_ptr_t end) : start(start), ptr(start), end(end) { | ||
} | ||
|
||
explicit Cursor(string_t blob) : start((data_ptr_t)blob.GetDataUnsafe()), ptr(start), end(start + blob.GetSize()) { | ||
} | ||
|
||
data_ptr_t GetPtr() { | ||
return ptr; | ||
} | ||
|
||
void SetPtr(data_ptr_t ptr_p) { | ||
if (ptr_p < start || ptr_p > end) { | ||
throw SerializationException("Trying to set ptr outside of buffer"); | ||
} | ||
ptr = ptr_p; | ||
} | ||
|
||
template <class T> | ||
T Read() { | ||
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable"); | ||
if (ptr + sizeof(T) > end) { | ||
throw SerializationException("Trying to read past end of buffer"); | ||
} | ||
auto result = Load<T>(ptr); | ||
ptr += sizeof(T); | ||
return result; | ||
} | ||
|
||
template <class T> | ||
void Write(T value) { | ||
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable"); | ||
if (ptr + sizeof(T) > end) { | ||
throw SerializationException("Trying to write past end of buffer"); | ||
} | ||
Store<T>(value, ptr); | ||
ptr += sizeof(T); | ||
} | ||
|
||
template <class T> | ||
T Peek() { | ||
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable"); | ||
if (ptr + sizeof(T) > end) { | ||
throw SerializationException("Trying to read past end of buffer"); | ||
} | ||
return Load<T>(ptr); | ||
} | ||
|
||
void Skip(uint32_t bytes) { | ||
if (ptr + bytes > end) { | ||
throw SerializationException("Trying to read past end of buffer"); | ||
} | ||
ptr += bytes; | ||
} | ||
|
||
void Seek(Offset offset, int32_t bytes) { | ||
switch (offset) { | ||
case Offset::START: | ||
ptr = start + bytes; | ||
break; | ||
case Offset::CURRENT: | ||
ptr += bytes; | ||
break; | ||
case Offset::END: | ||
ptr = end + bytes; | ||
break; | ||
} | ||
if (ptr < start || ptr > end) { | ||
throw SerializationException("Trying to set ptr outside of buffer"); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace core | ||
|
||
} // namespace spatial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
spatial/include/spatial/core/geometry/geometry_properties.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#pragma once | ||
#include "spatial/common.hpp" | ||
|
||
namespace spatial { | ||
|
||
namespace core { | ||
|
||
struct GeometryProperties { | ||
private: | ||
static constexpr const uint8_t Z = 0x01; | ||
static constexpr const uint8_t M = 0x02; | ||
static constexpr const uint8_t BBOX = 0x04; | ||
static constexpr const uint8_t GEODETIC = 0x08; | ||
static constexpr const uint8_t READONLY = 0x10; | ||
static constexpr const uint8_t SOLID = 0x20; | ||
uint8_t flags = 0; | ||
|
||
public: | ||
explicit GeometryProperties(uint8_t flags = 0) : flags(flags) { | ||
} | ||
|
||
inline bool HasZ() const { | ||
return (flags & Z) != 0; | ||
} | ||
inline bool HasM() const { | ||
return (flags & M) != 0; | ||
} | ||
inline bool HasBBox() const { | ||
return (flags & BBOX) != 0; | ||
} | ||
inline bool IsGeodetic() const { | ||
return (flags & GEODETIC) != 0; | ||
} | ||
inline bool IsReadOnly() const { | ||
return (flags & READONLY) != 0; | ||
} | ||
|
||
inline void SetZ(bool value) { | ||
flags = value ? (flags | Z) : (flags & ~Z); | ||
} | ||
inline void SetM(bool value) { | ||
flags = value ? (flags | M) : (flags & ~M); | ||
} | ||
inline void SetBBox(bool value) { | ||
flags = value ? (flags | BBOX) : (flags & ~BBOX); | ||
} | ||
inline void SetGeodetic(bool value) { | ||
flags = value ? (flags | GEODETIC) : (flags & ~GEODETIC); | ||
} | ||
inline void SetReadOnly(bool value) { | ||
flags = value ? (flags | READONLY) : (flags & ~READONLY); | ||
} | ||
}; | ||
|
||
} // namespace core | ||
|
||
} // namespace spatial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
#include "spatial/common.hpp" | ||
|
||
namespace spatial { | ||
|
||
namespace core { | ||
|
||
enum class GeometryType : uint8_t { | ||
POINT = 0, | ||
LINESTRING, | ||
POLYGON, | ||
MULTIPOINT, | ||
MULTILINESTRING, | ||
MULTIPOLYGON, | ||
GEOMETRYCOLLECTION | ||
}; | ||
|
||
} // namespace core | ||
|
||
} // namespace spatial |
Oops, something went wrong.