21 namespace Geospatial {
28 throw std::runtime_error(
"Invalid compression");
38 return *
reinterpret_cast<uint64_t*
>(may_alias_ptr(&coord));
47 auto u = *
reinterpret_cast<uint64_t*
>(may_alias_ptr(&n));
54 CHECK(!coords.empty()) <<
"Coord compression received no data";
63 size_t coord_data_size = (is_geoint32) ? (ti.
get_comp_param() / 8) :
sizeof(
double);
64 std::vector<uint8_t> compressed_coords;
65 compressed_coords.reserve(coords.size() * coord_data_size);
66 for (
auto coord : coords) {
73 if (coord < -180.0 || coord > 180.0) {
78 if (coord < -90.0 || coord > 90.0) {
87 auto coord_data_ptr =
reinterpret_cast<uint64_t*
>(&
coord);
88 coord_data = *coord_data_ptr;
91 for (
size_t i = 0; i < coord_data_size; i++) {
92 compressed_coords.push_back(coord_data & 0xFF);
97 return compressed_coords;
100 template <
typename T>
105 auto elems =
reinterpret_cast<const T*
>(input_ptr);
107 const size_t num_elems = sz /
sizeof(
T);
108 output.resize(num_elems);
109 for (
size_t i = 0; i < num_elems; i++) {
110 output[i] = elems[i];
116 const int8_t* input_ptr,
121 auto elems =
reinterpret_cast<const int32_t*
>(input_ptr);
122 CHECK_EQ(
size_t(0), sz %
sizeof(int32_t));
123 const size_t num_elems = sz /
sizeof(int32_t);
124 output.resize(num_elems);
125 for (
size_t i = 0; i < num_elems; i++) {
126 output[i] = elems[i];
130 template <
typename T>
137 const auto compressed_coords =
reinterpret_cast<const int32_t*
>(enc);
138 const auto num_coords = sz /
sizeof(int32_t);
139 dec.resize(num_coords);
140 for (
size_t i = 0; i < num_coords; i += 2) {
149 const int8_t* coords,
150 const size_t coords_sz) {
151 auto decompressed_coords_ptr = std::make_shared<std::vector<double>>();
153 if (geo_ti.get_comp_param() == 32) {
160 return decompressed_coords_ptr;
166 const int8_t* coords,
167 const size_t coords_sz) {
168 auto decompressed_coords_ptr = std::make_shared<std::vector<double>>();
175 return decompressed_coords_ptr;
179 const int8_t* coords,
180 const size_t coords_sz) {
188 auto coords_ptr = (
double*)coords;
DEVICE double decompress_latitude_coord_geoint32(const int32_t compressed)
void decompress_geo_coords_geoint32(std::vector< T > &dec, const int8_t *enc, const size_t sz)
DEVICE uint64_t compress_longitude_coord_geoint32(const double coord)
int32_t get_compression_scheme(const SQLTypeInfo &ti)
bool is_null_point(const SQLTypeInfo &geo_ti, const int8_t *coords, const size_t coords_sz)
HOST DEVICE SQLTypes get_type() const
DEVICE ALWAYS_INLINE Point2D coord(const int8_t *data, const int32_t x_index, const int32_t ic, const int32_t isr, const int32_t osr)
DEVICE bool is_null_point_longitude_geoint32(const int32_t compressed)
std::shared_ptr< std::vector< double > > decompress_coords< double, SQLTypeInfo >(const SQLTypeInfo &geo_ti, const int8_t *coords, const size_t coords_sz)
std::vector< uint8_t > compress_coords(const std::vector< double > &coords, const SQLTypeInfo &ti)
DEVICE uint64_t compress_latitude_coord_geoint32(const double coord)
DEVICE constexpr uint64_t compress_null_point_latitude_geoint32()
HOST DEVICE EncodingType get_compression() const
DEVICE double decompress_longitude_coord_geoint32(const int32_t compressed)
std::shared_ptr< std::vector< double > > decompress_coords< double, int32_t >(const int32_t &ic, const int8_t *coords, const size_t coords_sz)
HOST DEVICE int get_comp_param() const
#define NULL_ARRAY_DOUBLE
void unpack_geo_vector< int32_t >(std::vector< int32_t > &output, const int8_t *input_ptr, const size_t sz)
#define COMPRESSION_GEOINT32
HOST DEVICE bool get_notnull() const
DEVICE constexpr uint64_t compress_null_point_longitude_geoint32()
HOST DEVICE int get_output_srid() const
uint64_t compress_coord(double coord, const SQLTypeInfo &ti, bool x)
uint64_t compress_null_point(const SQLTypeInfo &ti, bool x)
void unpack_geo_vector(std::vector< T > &output, const int8_t *input_ptr, const size_t sz)