template struct mola::index3d_hash

Overview

Hash functor and comparator for index3d_t, usable with both std::unordered_map / tsl::robin_map (hash) and std::map (comparator).

The hash function is the optimized spatial hash from: Teschner et al., “Optimized spatial hashing for collision detection of

deformable objects”, VMV 2003. It mixes the three integer coordinates with large prime multipliers and truncates to 20 bits, giving good distribution for typical voxel grids.

The operator()(k1,k2) overload provides a strict weak ordering on index3d_t (X-primary, Y-secondary, Z-tertiary) for std::map.

#include <index3d_t.h>

template <typename cell_coord_t = int32_t>
struct index3d_hash
{
    // methods

    std::size_t operator () (const index3d_t<cell_coord_t>& k) const;
    bool operator () (const index3d_t<cell_coord_t>& k1, const index3d_t<cell_coord_t>& k2) const;
};

Methods

std::size_t operator () (const index3d_t<cell_coord_t>& k) const

Hash operator for unordered maps:

bool operator () (const index3d_t<cell_coord_t>& k1, const index3d_t<cell_coord_t>& k2) const

k1 < k2? for std::map containers