Closed Moelf closed 1 year ago
The encoding maps x -> 2x if x is positive and to -2x-1 otherwise.
x -> 2x
x
-2x-1
The most canonical implementation seems to be exactly the same, in the ROOT PR:
UDestT val = (static_cast<DestT>(src[i]) << 1) ^ (static_cast<DestT>(src[i]) >> (kNBitsDestT - 1));
in other project
def int64_t zigzag_long(uint64_t n): return (n >> 1) ^ -(n & 1) def uint64_t long_zigzag(int64_t n): return (n << 1) ^ (n >> 63)
The most canonical implementation seems to be exactly the same, in the ROOT PR:
in other project