fn zigzag_encode(n: i64) -> u64 {
    // the right shift has to be arithmetic
    // negative numbers become all binary 1s
    // positive numbers become all binary 0s
    // effectively inverting bits of the result in
    // case of negative number
    // let tmp = (n << 1) ^ (n >> 63);

    let tmp = n.overflowing_shl(1).0 ^ n.overflowing_shr(63).0;
    u64::from_le_bytes(tmp.to_le_bytes())
}
/** Encodes signed integer as unsigned,
 * with positive values even and negative values odd
 * starting around zero.
 * This saves transfer space and unifies integer encoding.
 * 0 -> 0
 * -1 -> 1
 * 1 -> 2
 * -2 -> 3
 * 2 -> 4
 * ...
 */
Encodes signed integer as unsigned,
with positive values even and negative values odd
starting around zero.
This saves transfer space and unifies integer encoding.
Encodes signed integer as unsigned with positive values even and negative values odd starting around zero . This saves transfer space and unifies integer encoding .
fn zigzag_encode(n: i64) -> u64 {
    // the right shift has to be arithmetic
    // negative numbers become all binary 1s
    // positive numbers become all binary 0s
    // effectively inverting bits of the result in
    // case of negative number
    // let tmp = (n << 1) ^ (n >> 63);
    let tmp = n.overflowing_shl(1).0 ^ n.overflowing_shr(63).0;
    u64::from_le_bytes(tmp.to_le_bytes())
}
fn zigzag_encode ( n : i64 ) -> u64 { // the right shift has to be arithmetic // negative numbers become all binary 1s // positive numbers become all binary 0s // effectively inverting bits of the result in // case of negative number // let tmp = (n << 1) ^ (n >> 63); let tmp = n . overflowing_shl ( 1 ) . 0 ^ n . overflowing_shr ( 63 ) . 0 ; u64 :: from_le_bytes ( tmp . to_le_bytes ( ) ) }
Encodes signed integer as unsigned,
 with positive values even and negative values odd
 starting around zero.
Encodes signed integer as unsigned with positive values even and negative values odd starting around zero .
n
i64
n
i64