OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
h3Index.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2018 Uber Technologies, 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  */
20 #ifndef H3INDEX_H
21 #define H3INDEX_H
22 
25 
26 // define's of constants and macros for bitwise manipulation of H3Index's.
27 
29 #define H3_NUM_BITS 64
30 
32 #define H3_MAX_OFFSET 63
33 
35 #define H3_MODE_OFFSET 59
36 
38 #define H3_BC_OFFSET 45
39 
40 // /** The bit offset of the resolution in an H3 index. */
41 #define H3_RES_OFFSET 52
42 
44 #define H3_RESERVED_OFFSET 56
45 
47 #define H3_PER_DIGIT_OFFSET 3
48 
50 #define H3_HIGH_BIT_MASK ((uint64_t)(1) << H3_MAX_OFFSET)
51 
53 #define H3_HIGH_BIT_MASK_NEGATIVE (~H3_HIGH_BIT_MASK)
54 
56 #define H3_MODE_MASK ((uint64_t)(15) << H3_MODE_OFFSET)
57 
59 #define H3_MODE_MASK_NEGATIVE (~H3_MODE_MASK)
60 
62 #define H3_BC_MASK ((uint64_t)(127) << H3_BC_OFFSET)
63 
65 #define H3_BC_MASK_NEGATIVE (~H3_BC_MASK)
66 
68 #define H3_RES_MASK (UINT64_C(15) << H3_RES_OFFSET)
69 
71 #define H3_RES_MASK_NEGATIVE (~H3_RES_MASK)
72 
74 #define H3_RESERVED_MASK ((uint64_t)(7) << H3_RESERVED_OFFSET)
75 
77 #define H3_RESERVED_MASK_NEGATIVE (~H3_RESERVED_MASK)
78 
80 #define H3_DIGIT_MASK ((uint64_t)(7))
81 
83 #define H3_DIGIT_MASK_NEGATIVE (~H3_DIGIT_MASK)
84 
90 #define H3_INIT (UINT64_C(35184372088831))
91 
95 #define H3_GET_HIGH_BIT(h3) ((int)((((h3)&H3_HIGH_BIT_MASK) >> H3_MAX_OFFSET)))
96 
100 #define H3_SET_HIGH_BIT(h3, v) \
101  (h3) = (((h3)&H3_HIGH_BIT_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MAX_OFFSET))
102 
106 #define H3_GET_MODE(h3) ((int)((((h3)&H3_MODE_MASK) >> H3_MODE_OFFSET)))
107 
111 #define H3_SET_MODE(h3, v) \
112  (h3) = (((h3)&H3_MODE_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_MODE_OFFSET))
113 
117 #define H3_GET_BASE_CELL(h3) ((int)((((h3)&H3_BC_MASK) >> H3_BC_OFFSET)))
118 
122 #define H3_SET_BASE_CELL(h3, bc) \
123  (h3) = (((h3)&H3_BC_MASK_NEGATIVE) | (((uint64_t)(bc)) << H3_BC_OFFSET))
124 
128 #define H3_GET_RESOLUTION(h3) ((int)((((h3)&H3_RES_MASK) >> H3_RES_OFFSET)))
129 
133 #define H3_SET_RESOLUTION(h3, res) \
134  (h3) = (((h3)&H3_RES_MASK_NEGATIVE) | (((uint64_t)(res)) << H3_RES_OFFSET))
135 
139 #define H3_GET_INDEX_DIGIT(h3, res) \
140  ((Direction)((((h3) >> ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)) & H3_DIGIT_MASK)))
141 
146 #define H3_SET_RESERVED_BITS(h3, v) \
147  (h3) = (((h3)&H3_RESERVED_MASK_NEGATIVE) | (((uint64_t)(v)) << H3_RESERVED_OFFSET))
148 
152 #define H3_GET_RESERVED_BITS(h3) ((int)((((h3)&H3_RESERVED_MASK) >> H3_RESERVED_OFFSET)))
153 
157 #define H3_SET_INDEX_DIGIT(h3, res, digit) \
158  (h3) = (((h3) & ~((H3_DIGIT_MASK << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))) | \
159  (((uint64_t)(digit)) << ((MAX_H3_RES - (res)) * H3_PER_DIGIT_OFFSET)))
160 
165 #define H3_NULL 0
166 
167 /*
168  * Return codes for compact
169  */
170 
171 #define COMPACT_SUCCESS 0
172 #define COMPACT_LOOP_EXCEEDED -1
173 #define COMPACT_DUPLICATE -2
174 #define COMPACT_ALLOC_FAILED -3
175 
176 // void setH3Index(H3Index* h, int res, int baseCell, Direction initDigit);
177 
178 // Internal functions
179 
180 // int _h3ToFaceIjkWithInitializedFijk(H3Index h, FaceIJK* fijk);
181 // void _h3ToFaceIjk(H3Index h, FaceIJK* fijk);
191 
193 
194 #endif
EXTENSION_NOINLINE bool _h3ToGeo(H3Index h3, GeoCoord(g))
Definition: h3Index.hpp:834
EXTENSION_INLINE int _h3LeadingNonZeroDigit(H3Index h)
Definition: h3Index.hpp:551
EXTENSION_NOINLINE int _h3ToFaceIjkWithInitializedFijk(H3Index h, FaceIJK(fijk))
Definition: h3Index.hpp:753
#define GeoCoord(variable_name)
Definition: h3api.h:94
EXTENSION_NOINLINE H3Index _h3RotatePent60cw(H3Index h)
Definition: h3Index.hpp:590
#define EXTENSION_NOINLINE
Definition: heavydbTypes.h:58
#define FaceIJK(variable_name)
Definition: faceijk.h:36
EXTENSION_NOINLINE H3Index _faceIjkToH3(const FaceIJK(fijk), int res)
Definition: h3Index.hpp:643
#define H3Index
the H3Index fits within a 64-bit unsigned integer
Definition: h3api.h:75
#define EXTENSION_INLINE
Definition: heavydbTypes.h:57
EXTENSION_NOINLINE H3Index _h3RotatePent60ccw(H3Index h)
Definition: h3Index.hpp:564
EXTENSION_NOINLINE bool _h3ToFaceIjk(H3Index h, FaceIJK(fijk))
Definition: h3Index.hpp:783
FaceIJK functions including conversion to/from lat/lon.
Primary H3 core library entry points.
EXTENSION_NOINLINE H3Index _h3Rotate60cw(H3Index h)
Definition: h3Index.hpp:629
EXTENSION_NOINLINE H3Index _h3Rotate60ccw(H3Index h)
Definition: h3Index.hpp:616