[Groonga-commit] groonga/grnxx at 9cf7d1f [master] Add grnxx::GeoPoint::interleave().

アーカイブの一覧に戻る

susumu.yata null+****@clear*****
Sat May 11 10:01:53 JST 2013


susumu.yata	2013-05-11 10:01:53 +0900 (Sat, 11 May 2013)

  New Revision: 9cf7d1f0edf20fa5797e444db62c108989f86182
  https://github.com/groonga/grnxx/commit/9cf7d1f0edf20fa5797e444db62c108989f86182

  Message:
    Add grnxx::GeoPoint::interleave().

  Modified files:
    lib/grnxx/geo_point.cpp
    lib/grnxx/geo_point.hpp

  Modified: lib/grnxx/geo_point.cpp (+17 -1)
===================================================================
--- lib/grnxx/geo_point.cpp    2013-05-09 18:45:09 +0900 (5ace2f4)
+++ lib/grnxx/geo_point.cpp    2013-05-11 10:01:53 +0900 (e2cb3e6)
@@ -21,9 +21,25 @@
 
 namespace grnxx {
 
+uint64_t GeoPoint::interleave() const {
+  uint64_t latitude = static_cast<uint32_t>(point_.latitude);
+  uint64_t longitude = static_cast<uint32_t>(point_.longitude);
+  latitude = (latitude | (latitude << 16)) & 0x0000FFFF0000FFFFULL;
+  latitude = (latitude | (latitude <<  8)) & 0x00FF00FF00FF00FFULL;
+  latitude = (latitude | (latitude <<  4)) & 0x0F0F0F0F0F0F0F0FULL;
+  latitude = (latitude | (latitude <<  2)) & 0x3333333333333333ULL;
+  latitude = (latitude | (latitude <<  1)) & 0x5555555555555555ULL;
+  longitude = (longitude | (longitude << 16)) & 0x0000FFFF0000FFFFULL;
+  longitude = (longitude | (longitude <<  8)) & 0x00FF00FF00FF00FFULL;
+  longitude = (longitude | (longitude <<  4)) & 0x0F0F0F0F0F0F0F0FULL;
+  longitude = (longitude | (longitude <<  2)) & 0x3333333333333333ULL;
+  longitude = (longitude | (longitude <<  1)) & 0x5555555555555555ULL;
+  return (latitude << 1) | longitude;
+}
+
 StringBuilder &operator<<(StringBuilder &builder, const GeoPoint &point) {
   return builder << "{ latitude = " << point.latitude()
                  << ", longitude = " << point.longitude() << " }";
 }
 
-}  // namespace grnxx
+}  // namespace

  Modified: lib/grnxx/geo_point.hpp (+13 -10)
===================================================================
--- lib/grnxx/geo_point.hpp    2013-05-09 18:45:09 +0900 (670ca0d)
+++ lib/grnxx/geo_point.hpp    2013-05-11 10:01:53 +0900 (2f6e6ed)
@@ -27,29 +27,32 @@ class StringBuilder;
 // Latitude and longitude (lat/long).
 union GeoPoint {
  public:
-  // The default constructor does not initialize lat/long.
+  // Trivial default constructor.
   GeoPoint() = default;
-  // Copy lat/long as uint64_t to force atomic copy.
+  // Copy the lat/long as uint64_t to force atomic copy.
   GeoPoint(const GeoPoint &x) : value_(x.value_) {}
-  // Copy lat/long.
+  // Copy the lat/long.
   GeoPoint(int32_t latitude, int32_t longitude)
       : point_{ latitude, longitude } {}
 
-  // Assign lat/long as uint64_t to force atomic assignment.
+  // Assign the lat/long as uint64_t to force atomic assignment.
   GeoPoint &operator=(const GeoPoint &x) {
     value_ = x.value_;
     return *this;
   }
 
-  // Get the latitude.
+  // Interleave the lat/long.
+  uint64_t interleave() const;
+
+  // Return the latitude.
   int32_t latitude() const {
     return point_.latitude;
   }
-  // Get the longitude.
+  // Return the longitude.
   int32_t longitude() const {
     return point_.longitude;
   }
-  // Get lat/long as uint64_t.
+  // Return the lat/long as uint64_t.
   uint64_t value() const {
     return value_;
   }
@@ -62,7 +65,7 @@ union GeoPoint {
   void set_longitude(int32_t x) {
     point_.longitude = x;
   }
-  // Set lat/long as uint64_t.
+  // Set the lat/long as uint64_t.
   void set_value(uint64_t x) {
     value_ = x;
   }
@@ -82,8 +85,8 @@ inline bool operator!=(const GeoPoint &lhs, const GeoPoint &rhs) {
   return lhs.value() != rhs.value();
 }
 
-StringBuilder &operator<<(StringBuilder &builder, const GeoPoint &x);
+StringBuilder &operator<<(StringBuilder &builder, const GeoPoint &point);
 
-}  // namespace grnxx
+}  // namespace
 
 #endif  // GRNXX_GEO_POINT_HPP
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る