Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions navmap_core/include/navmap_core/NavMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,39 @@ struct LayerView : LayerViewBase
///@}
};

/** @cond INTERNAL */
namespace detail
{
inline std::uint64_t fnv1a64_bytes(
const void * data, std::size_t n,
std::uint64_t seed = 1469598103934665603ULL)
{
const auto * p = static_cast<const std::uint8_t *>(data);
std::uint64_t h = seed;
for (std::size_t i = 0; i < n; ++i) {
h ^= p[i]; h *= 1099511628211ULL;
}
return h;
}
} // namespace detail
/** @endcond */

template<typename T>
std::uint64_t LayerView<T>::content_hash() const
{
if (!hash_dirty_) {return hash_cache_;}
const std::size_t n = data_.size();
std::uint64_t h = navmap::detail::fnv1a64_bytes(&n, sizeof(n));
if (n) {
static_assert(std::is_trivially_copyable<T>::value,
"LayerView<T> requires trivially copyable T.");
h = navmap::detail::fnv1a64_bytes(data_.data(), n * sizeof(T), h);
}
hash_cache_ = h;
hash_dirty_ = false;
return hash_cache_;
}

/**
* \brief Registry of named layers (per-NavCel).
*
Expand Down
35 changes: 1 addition & 34 deletions navmap_core/src/navmap_core/NavMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,6 @@
namespace navmap
{

/** @cond INTERNAL */
namespace navmap
{namespace detail
{
inline std::uint64_t fnv1a64_bytes(
const void * data, std::size_t n,
std::uint64_t seed = 1469598103934665603ULL)
{
const auto * p = static_cast<const std::uint8_t *>(data);
std::uint64_t h = seed;
for (std::size_t i = 0; i < n; ++i) {
h ^= p[i]; h *= 1099511628211ULL;
}
return h;
}
}} // namespaces
/** @endcond */

template<typename T>
std::uint64_t LayerView<T>::content_hash() const
{
if (!hash_dirty_) {return hash_cache_;}
const std::size_t n = data_.size();
std::uint64_t h = navmap::detail::fnv1a64_bytes(&n, sizeof(n));
if (n) {
static_assert(std::is_trivially_copyable<T>::value,
"LayerView<T> requires trivially copyable T.");
h = navmap::detail::fnv1a64_bytes(data_.data(), n * sizeof(T), h);
}
hash_cache_ = h;
hash_dirty_ = false;
return hash_cache_;
}

namespace
{
Expand Down Expand Up @@ -472,7 +439,7 @@ bool NavMap::raycast(
{
bool any = false;
float best_t = std::numeric_limits<float>::infinity();
Vec3 best_p;
Vec3 best_p = Vec3::Zero();
NavCelId best_cid = 0;

for (const auto & s : surfaces) {
Expand Down
Loading