Skip to content

Commit

Permalink
Fix 32-bit and old PDAL compilation issues (#44)
Browse files Browse the repository at this point in the history
* Create a dumb VoxelKey hash function for 32-bit systems.

* Add include for old PDAL.
  • Loading branch information
abellgithub authored Jan 6, 2021
1 parent 154e7f7 commit 9066dda
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
3 changes: 3 additions & 0 deletions epf/Reprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
****************************************************************************/


// This include is necessary for released PDAL 2.0 and earlier, as it wasn't included in
// FileUtils.hpp.
#include <vector>
#include <pdal/util/FileUtils.hpp>

#include "Reprocessor.hpp"
Expand Down
31 changes: 23 additions & 8 deletions untwine/VoxelKey.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,30 @@ namespace std
{
template<> struct hash<untwine::VoxelKey>
{
std::size_t operator()(const untwine::VoxelKey& k) const noexcept
size_t operator()(const untwine::VoxelKey& k) const noexcept
{
static_assert(sizeof(size_t) > sizeof(int), "wrong assumption that size_t is 64 bits");

// For this to work well we just assume that the values are no more than than 16 bits.
size_t t = size_t(k.x()) << 48;
t |= size_t(k.y()) << 32;
t |= size_t(k.z()) << 16;
t |= size_t(k.level());
size_t t;

static_assert(sizeof(size_t) == sizeof(uint64_t) ||
sizeof(size_t) == sizeof(uint32_t),
"Only systems with 32 and 64 bit size_t are currently supported.");

// Counting on the compiler to optimize away the wrong branch.
if (sizeof(size_t) == sizeof(uint64_t))
{
// For this to work well we just assume that the values are no more than 16 bits.
t = size_t(k.x()) << 48;
t |= size_t(k.y()) << 32;
t |= size_t(k.z()) << 16;
t |= size_t(k.level());
}
else if (sizeof(size_t) == sizeof(uint32_t))
{
t = size_t((k.x() << 24) | 0xFF000000);
t |= size_t((k.y() << 16) | 0xFF0000);
t |= size_t((k.z() << 8) | 0xFF00);
t |= size_t(k.level() | 0xFF);
}
return t;
}
};
Expand Down

0 comments on commit 9066dda

Please sign in to comment.