You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You mentioned in TODO that a better naming system is required. I solved the issue by using a combination of tag dispatch, function overloading, and partial specialization of template classes. Please see the implementation in shohirose/morton for details.
A brief overview of my idea is the following:
namespacetag {
// Tags representing each implementationstructbmi {};
structpreshifted_lookup_table {};
structlookup_table {};
} // namespace tagnamespacedetail {
template <typename MortonCode, typename Coordinate, typename Tag>
classmorton2d {};
// Partial specialization of morton2d for tag::bmitemplate <typename MortonCode, typename Coordinate>
classmorton2d<MortonCode, Coordinate, tag::bmi> {
public:static MortonCode encode(const Coordinate x, const Coordinate y) noexcept {
// ...
}
staticvoiddecode(const MortonCode m, Coordinate& x, Coordinate& y) noexcept {
// ...
}
};
// Partial specialization of morton2d for tag::preshifted_lookup_tabletemplate <typename MortonCode, typename Coordinate>
classmorton2d<MortonCode, Coordinate, tag::preshifted_lookup_table> {
// ...
};
// Partial specialization of morton2d for tag::lookup_tabletemplate <typename MortonCode, typename Coordinate>
classmorton2d<MortonCode, Coordinate, tag::lookup_table> {
// ...
};
} // namespace detail// Switch implementation by using a tag dispatch technique.template <typename Tag>
inlineuint_fast32_tencode(constuint_fast16_t x, constuint_fast16_t y, Tag) noexcept {
return detail::morton2d<uint_fast32_t, uint_fast16_t, Tag>::encode(x, y);
}
template <typename Tag>
inlinevoiddecode(constuint_fast32_t m, uint_fast16_t& x, uint_fast16_t& y, Tag) noexcept {
detail::morton2d<uint_fast32_t, uint_fast16_t, Tag>::decode(x, y);
}
Then, we can specify an implementation through a uniform API:
uint_fast16_t x = // ...uint_fast16_t y = // ...// Encode using BMI instruction set (if available)constauto m1 = encode(x, y, tag::bmi{});
// Encode using preshifted lookup tableconstauto m2 = encode(x, y, tag::preshifted_lookup_table{});
// Encode using lookup tableconstauto m3 = encode(x, y, tag::lookup_table{});
I hope this might help you.
The text was updated successfully, but these errors were encountered:
Hi,
You mentioned in TODO that a better naming system is required. I solved the issue by using a combination of tag dispatch, function overloading, and partial specialization of template classes. Please see the implementation in shohirose/morton for details.
A brief overview of my idea is the following:
Then, we can specify an implementation through a uniform API:
I hope this might help you.
The text was updated successfully, but these errors were encountered: