dongjoon-hyun commented on code in PR #2269:
URL: https://github.com/apache/orc/pull/2269#discussion_r2152526269


##########
c++/src/Geospatial.cc:
##########
@@ -0,0 +1,298 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "orc/Geospatial.hh"
+
+#include <algorithm>
+#include <cstring>
+#include <optional>
+#include <sstream>
+
+#include "orc/Exceptions.hh"
+
+namespace orc::geospatial {
+
+  template <typename T>
+  inline std::enable_if_t<std::is_trivially_copyable_v<T>, T> SafeLoadAs(const 
uint8_t* unaligned) {
+    std::remove_const_t<T> ret;
+    std::memcpy(&ret, unaligned, sizeof(T));
+    return ret;
+  }
+
+  template <typename U, typename T>
+  inline std::enable_if_t<std::is_trivially_copyable_v<T> && 
std::is_trivially_copyable_v<U> &&
+                              sizeof(T) == sizeof(U),
+                          U>
+  SafeCopy(T value) {
+    std::remove_const_t<U> ret;
+    std::memcpy(&ret, static_cast<const void*>(&value), sizeof(T));
+    return ret;
+  }
+
+  static bool isLittleEndian() {
+    static union {
+      uint32_t i;
+      char c[4];
+    } num = {0x01020304};
+    return num.c[0] == 4;
+  }
+
+#if defined(_MSC_VER)
+#include <intrin.h>  // IWYU pragma: keep
+#define ORC_BYTE_SWAP64 _byteswap_uint64
+#define ORC_BYTE_SWAP32 _byteswap_ulong
+#else
+#define ORC_BYTE_SWAP64 __builtin_bswap64
+#define ORC_BYTE_SWAP32 __builtin_bswap32
+#endif
+
+  // Swap the byte order (i.e. endianness)
+  static inline uint32_t ByteSwap(uint32_t value) {
+    return static_cast<uint32_t>(ORC_BYTE_SWAP32(value));
+  }
+  static inline double ByteSwap(double value) {
+    const uint64_t swapped = ORC_BYTE_SWAP64(SafeCopy<uint64_t>(value));
+    return SafeCopy<double>(swapped);
+  }
+
+  std::string BoundingBox::ToString() const {
+    std::stringstream ss;
+    ss << "BoundingBox" << std::endl;
+    ss << "  x: [" << min[0] << ", " << max[0] << "]" << std::endl;
+    ss << "  y: [" << min[1] << ", " << max[1] << "]" << std::endl;
+    ss << "  z: [" << min[2] << ", " << max[2] << "]" << std::endl;
+    ss << "  m: [" << min[3] << ", " << max[3] << "]" << std::endl;

Review Comment:
   Why this is different from Java? Let's have the same format for Java and 
C++. To move forward, you can update this C++ implementation or you can update 
the merged Java implementation first before this PR.
   
   
https://github.com/apache/orc/blob/1e5c16192a8df92e29ec9c0913f987178d3ad034/java/core/src/java/org/apache/orc/geospatial/BoundingBox.java#L336-L351



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@orc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to