OmniSciDB  2e3a973ef4
CompressionRuntime.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
25 #pragma once
26 
27 #include "Shared/funcannotations.h"
28 
29 #define COMPRESSION_NONE 0
30 #define COMPRESSION_GEOINT32 1
31 #define COMPRESSION_GEOBBINT32 2
32 #define COMPRESSION_GEOBBINT16 3
33 #define COMPRESSION_GEOBBINT8 4
34 
35 #define TOLERANCE_DEFAULT 0.000000001
36 #define TOLERANCE_GEOINT32 0.0000001
37 
38 namespace Geospatial {
39 
40 DEVICE inline double decompress_longitude_coord_geoint32(const int32_t compressed) {
41  // decompress longitude: -2,147,483,647..2,147,483,647 ---> -180..180
42  return static_cast<double>(compressed) *
43  8.3819031754424345e-08; // (180.0 / 2147483647.0)
44 }
45 
46 DEVICE inline double decompress_lattitude_coord_geoint32(const int32_t compressed) {
47  // decompress latitude: -2,147,483,647..2,147,483,647 ---> -90..90
48  return static_cast<double>(compressed) *
49  4.1909515877212172e-08; // // (90.0 / 2147483647.0)
50 }
51 
52 DEVICE inline bool is_null_point_longitude_geoint32(const int32_t compressed) {
53  // check compressed null point longitude: -2,147,483,648 ---> NULL
54  return (*reinterpret_cast<const uint32_t*>(&compressed) == 0x80000000U);
55 }
56 
57 DEVICE inline bool is_null_point_lattitude_geoint32(const int32_t compressed) {
58  // check compressed null point latitude: -2,147,483,648 ---> NULL
59  return (*reinterpret_cast<const uint32_t*>(&compressed) == 0x80000000U);
60 }
61 
62 DEVICE inline uint64_t compress_longitude_coord_geoint32(const double coord) {
63  // compress longitude: -180..180 ---> -2,147,483,647..2,147,483,647
64  int32_t compressed_coord = static_cast<int32_t>(coord * (2147483647.0 / 180.0));
65  return static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&compressed_coord));
66 }
67 
68 DEVICE inline uint64_t compress_lattitude_coord_geoint32(const double coord) {
69  // compress latitude: -90..90 ---> -2,147,483,647..2,147,483,647
70  int32_t compressed_coord = static_cast<int32_t>(coord * (2147483647.0 / 90.0));
71  return static_cast<uint64_t>(*reinterpret_cast<uint32_t*>(&compressed_coord));
72 }
73 
75  // compress null point longitude: NULL ---> -2,147,483,648
76  return 0x0000000080000000ULL;
77 }
78 
80  // compress null point latitude: NULL ---> -2,147,483,648
81  return 0x0000000080000000ULL;
82 }
83 
84 }; // namespace Geospatial
DEVICE uint64_t compress_longitude_coord_geoint32(const double coord)
DEVICE double decompress_lattitude_coord_geoint32(const int32_t compressed)
#define DEVICE
DEVICE bool is_null_point_longitude_geoint32(const int32_t compressed)
DEVICE bool is_null_point_lattitude_geoint32(const int32_t compressed)
DEVICE constexpr uint64_t compress_null_point_lattitude_geoint32()
DEVICE double decompress_longitude_coord_geoint32(const int32_t compressed)
DEVICE constexpr uint64_t compress_null_point_longitude_geoint32()
DEVICE uint64_t compress_lattitude_coord_geoint32(const double coord)