migrate HilbertValue class to C++11, use fwd decl, remove boost/integer

This commit is contained in:
Dennis Luxen 2014-05-07 14:47:23 +02:00
parent 859502c504
commit 0ff7ac6aad
2 changed files with 48 additions and 37 deletions

View File

@ -27,9 +27,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "HilbertValue.h" #include "HilbertValue.h"
uint64_t HilbertCode::operator() ( #include <osrm/Coordinate.h>
const FixedPointCoordinate & current_coordinate
) const { uint64_t HilbertCode::operator()(const FixedPointCoordinate &current_coordinate) const
{
unsigned location[2]; unsigned location[2];
location[0] = current_coordinate.lat + (90 * COORDINATE_PRECISION); location[0] = current_coordinate.lat + (90 * COORDINATE_PRECISION);
location[1] = current_coordinate.lon + (180 * COORDINATE_PRECISION); location[1] = current_coordinate.lon + (180 * COORDINATE_PRECISION);
@ -41,11 +42,13 @@ uint64_t HilbertCode::operator() (
uint64_t HilbertCode::BitInterleaving(const uint32_t latitude, const uint32_t longitude) const uint64_t HilbertCode::BitInterleaving(const uint32_t latitude, const uint32_t longitude) const
{ {
uint64_t result = 0; uint64_t result = 0;
for(int8_t index = 31; index >= 0; --index){ for (int8_t index = 31; index >= 0; --index)
{
result |= (latitude >> index) & 1; result |= (latitude >> index) & 1;
result <<= 1; result <<= 1;
result |= (longitude >> index) & 1; result |= (longitude >> index) & 1;
if(0 != index){ if (0 != index)
{
result <<= 1; result <<= 1;
} }
} }
@ -57,14 +60,19 @@ void HilbertCode::TransposeCoordinate( uint32_t * X) const
uint32_t M = 1 << (32 - 1), P, Q, t; uint32_t M = 1 << (32 - 1), P, Q, t;
int i; int i;
// Inverse undo // Inverse undo
for( Q = M; Q > 1; Q >>= 1 ) { for (Q = M; Q > 1; Q >>= 1)
{
P = Q - 1; P = Q - 1;
for( i = 0; i < 2; ++i ) { for (i = 0; i < 2; ++i)
{
const bool condition = (X[i] & Q); const bool condition = (X[i] & Q);
if( condition ) { if (condition)
{
X[0] ^= P; // invert X[0] ^= P; // invert
} else { }
else
{
t = (X[0] ^ X[i]) & P; t = (X[0] ^ X[i]) & P;
X[0] ^= t; X[0] ^= t;
X[i] ^= t; X[i] ^= t;
@ -72,17 +80,21 @@ void HilbertCode::TransposeCoordinate( uint32_t * X) const
} // exchange } // exchange
} }
// Gray encode // Gray encode
for( i = 1; i < 2; ++i ) { for (i = 1; i < 2; ++i)
{
X[i] ^= X[i - 1]; X[i] ^= X[i - 1];
} }
t = 0; t = 0;
for( Q = M; Q > 1; Q >>= 1 ) { for (Q = M; Q > 1; Q >>= 1)
{
const bool condition = (X[2 - 1] & Q); const bool condition = (X[2 - 1] & Q);
if( condition ) { if (condition)
{
t ^= Q - 1; t ^= Q - 1;
} }
} // check if this for loop is wrong } // check if this for loop is wrong
for( i = 0; i < 2; ++i ) { for (i = 0; i < 2; ++i)
{
X[i] ^= t; X[i] ^= t;
} }
} }

View File

@ -28,20 +28,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef HILBERTVALUE_H_ #ifndef HILBERTVALUE_H_
#define HILBERTVALUE_H_ #define HILBERTVALUE_H_
#include <osrm/Coordinate.h> #include <cstdint>
#include <boost/integer.hpp>
#include <boost/noncopyable.hpp>
// computes a 64 bit value that corresponds to the hilbert space filling curve // computes a 64 bit value that corresponds to the hilbert space filling curve
class HilbertCode : boost::noncopyable struct FixedPointCoordinate;
class HilbertCode
{ {
public: public:
uint64_t operator() uint64_t operator()(const FixedPointCoordinate &current_coordinate) const;
( HilbertCode() {}
const FixedPointCoordinate & current_coordinate HilbertCode(const HilbertCode &) = delete;
) const;
private: private:
inline uint64_t BitInterleaving(const uint32_t a, const uint32_t b) const; inline uint64_t BitInterleaving(const uint32_t a, const uint32_t b) const;
inline void TransposeCoordinate(uint32_t *X) const; inline void TransposeCoordinate(uint32_t *X) const;