MCPcopy Create free account
hub / github.com/comaps/comaps / EncodeZigZagDelta

Function EncodeZigZagDelta

libs/routing/coding.hpp:83–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81// Encodes current as delta compared with prev.
82template <typename T, typename UnsignedT = std::make_unsigned_t<T>>
83UnsignedT EncodeZigZagDelta(T prev, T current)
84{
85 static_assert(std::is_integral<T>::value, "T should be an integral type");
86
87 auto const unsignedPrev = static_cast<UnsignedT>(prev);
88 auto const unsignedCurrent = static_cast<UnsignedT>(current);
89 auto originalDelta = ModularCast(static_cast<UnsignedT>(unsignedCurrent - unsignedPrev));
90 static_assert(std::is_same<decltype(originalDelta), std::make_signed_t<T>>::value,
91 "It's expected that ModuleCast returns SignedT");
92
93 auto encodedDelta = bits::ZigZagEncode(originalDelta);
94 static_assert(std::is_same<decltype(encodedDelta), UnsignedT>::value,
95 "It's expected that bits::ZigZagEncode returns UnsignedT");
96 return encodedDelta;
97}
98
99// Reverse function for EncodeZigZagDelta.
100template <typename T, typename UnsignedT = std::make_unsigned_t<T>>

Callers 1

TestZigZagFunction · 0.85

Calls 2

ModularCastFunction · 0.85
ZigZagEncodeFunction · 0.85

Tested by 1

TestZigZagFunction · 0.68