| 129 | |
| 130 | template <typename IntegerType> |
| 131 | IntegerType zigzagEncode (IntegerType n) |
| 132 | { |
| 133 | auto un = static_cast<typename std::make_unsigned<IntegerType>::type> (n); |
| 134 | auto sn = static_cast<typename std::make_signed<IntegerType>::type> (n); |
| 135 | return static_cast<IntegerType> ((sn >> (sizeof (IntegerType) * 8 - 1)) ^ static_cast<IntegerType> (un << 1)); |
| 136 | } |
| 137 | |
| 138 | template <typename IntegerType> |
| 139 | IntegerType zigzagDecode (IntegerType n) |