JuliaHEP / UnROOT.jl

Native Julia I/O package to work with CERN ROOT files objects (TTree and RNTuple)
https://juliahep.github.io/UnROOT.jl/
MIT License
102 stars 17 forks source link

[RNTuple] Missing zigzag encoding support #262

Closed Moelf closed 1 year ago

Moelf commented 1 year ago

The encoding maps x -> 2x if x is positive and to -2x-1 otherwise.

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)