Make HilbertCode a free standing function

This commit is contained in:
Daniel J. Hofmann 2016-01-25 15:32:41 +01:00 committed by Patrick Niklaus
parent 7a115e93c0
commit 38e8a90f4e
3 changed files with 18 additions and 27 deletions

View File

@ -10,18 +10,8 @@ namespace osrm
namespace util
{
// computes a 64 bit value that corresponds to the hilbert space filling curve
class HilbertCode
{
public:
std::uint64_t operator()(const FixedPointCoordinate current_coordinate) const;
HilbertCode() {}
HilbertCode(const HilbertCode &) = delete;
private:
inline std::uint64_t BitInterleaving(const std::uint32_t a, const std::uint32_t b) const;
inline void TransposeCoordinate(std::uint32_t *x) const;
};
// Computes a 64 bit value that corresponds to the hilbert space filling curve
std::uint64_t hilbertCode(const FixedPointCoordinate coordinate);
}
}

View File

@ -119,12 +119,10 @@ class StaticRTree
{
std::vector<WrappedInputElement> input_wrapper_vector(m_element_count);
HilbertCode get_hilbert_number;
// generate auxiliary vector of hilbert-values
tbb::parallel_for(
tbb::blocked_range<uint64_t>(0, m_element_count),
[&input_data_vector, &input_wrapper_vector, &get_hilbert_number, &coordinate_list](
[&input_data_vector, &input_wrapper_vector, &coordinate_list](
const tbb::blocked_range<uint64_t> &range)
{
for (uint64_t element_counter = range.begin(), end = range.end();
@ -145,7 +143,7 @@ class StaticRTree
COORDINATE_PRECISION *
mercator::latToY(current_centroid.lat / COORDINATE_PRECISION);
current_wrapper.m_hilbert_value = get_hilbert_number(current_centroid);
current_wrapper.m_hilbert_value = hilbertCode(current_centroid);
}
});

View File

@ -5,18 +5,10 @@ namespace osrm
namespace util
{
std::uint64_t HilbertCode::operator()(const FixedPointCoordinate current_coordinate) const
namespace
{
unsigned location[2];
location[0] = current_coordinate.lat + static_cast<int>(90 * COORDINATE_PRECISION);
location[1] = current_coordinate.lon + static_cast<int>(180 * COORDINATE_PRECISION);
TransposeCoordinate(location);
return BitInterleaving(location[0], location[1]);
}
std::uint64_t HilbertCode::BitInterleaving(const std::uint32_t latitude,
const std::uint32_t longitude) const
std::uint64_t bitInterleaving(const std::uint32_t latitude, const std::uint32_t longitude)
{
std::uint64_t result = 0;
for (std::int8_t index = 31; index >= 0; --index)
@ -32,7 +24,7 @@ std::uint64_t HilbertCode::BitInterleaving(const std::uint32_t latitude,
return result;
}
void HilbertCode::TransposeCoordinate(std::uint32_t *x) const
void transposeCoordinate(std::uint32_t *x)
{
std::uint32_t M = 1u << (32 - 1), P, Q, t;
int i;
@ -75,5 +67,16 @@ void HilbertCode::TransposeCoordinate(std::uint32_t *x) const
x[i] ^= t;
}
}
} // anonymous ns
std::uint64_t hilbertCode(const FixedPointCoordinate coordinate)
{
unsigned location[2];
location[0] = coordinate.lat + static_cast<int>(90 * COORDINATE_PRECISION);
location[1] = coordinate.lon + static_cast<int>(180 * COORDINATE_PRECISION);
transposeCoordinate(location);
return bitInterleaving(location[0], location[1]);
}
}
}