fn zigzag_decode(s: &[u8]) -> i64 {
    let unsigned_shr = |n: i64| {
        let n = u64::from_le_bytes(n.to_le_bytes()) >> 1;
        i64::from_le_bytes(n.to_le_bytes())
    };

    let s = read_i64(s);
    unsigned_shr(s) ^ (-(s & 1))
}
/*
   Decodes signed integer from unsigned,
   with positive values even and negative values odd
   starting around zero.
   This saves transfer space and unifies integer encoding.
   * -1 -> -9223372036854775808
   *  0 -> 0
   *  1 -> -1
   *  2 -> 1
   *  3 -> -2
   *  4 -> 2
   * ...
   a = -9223372036854775808 Min i64
   1000000000000000000000000000000000000000000000000000000000000000
   a << 1
   0000000000000000000000000000000000000000000000000000000000000000
   a >> 63
   1111111111111111111111111111111111111111111111111111111111111111
   b = encoded(a)
   1111111111111111111111111111111111111111111111111111111111111111
   signed(b) >> 1
   1111111111111111111111111111111111111111111111111111111111111111
   unsigned(b) >> 1
   0111111111111111111111111111111111111111111111111111111111111111
   -(b & 1))
   1111111111111111111111111111111111111111111111111111111111111111
   c = decoded(b)
   1000000000000000000000000000000000000000000000000000000000000000

   a = -1
   1111111111111111111111111111111111111111111111111111111111111111
   a << 1
   1111111111111111111111111111111111111111111111111111111111111110
   a >> 63
   1111111111111111111111111111111111111111111111111111111111111111
   b = encoded(a)
   0000000000000000000000000000000000000000000000000000000000000001
   signed(b) >> 1
   0000000000000000000000000000000000000000000000000000000000000000
   unsigned(b) >> 1
   0000000000000000000000000000000000000000000000000000000000000000
   -(b & 1))
   1111111111111111111111111111111111111111111111111111111111111111
   c = decoded(b)
   1111111111111111111111111111111111111111111111111111111111111111

   a = 1
   0000000000000000000000000000000000000000000000000000000000000001
   a << 1
   0000000000000000000000000000000000000000000000000000000000000010
   a >> 63
   0000000000000000000000000000000000000000000000000000000000000000
   b = encoded(a)
   0000000000000000000000000000000000000000000000000000000000000010
   signed(b) >> 1
   0000000000000000000000000000000000000000000000000000000000000001
   unsigned(b) >> 1
   0000000000000000000000000000000000000000000000000000000000000001
   -(b & 1))
   0000000000000000000000000000000000000000000000000000000000000000
   c = decoded(b)
   0000000000000000000000000000000000000000000000000000000000000001

   a = 9223372036854775807 - Max i64
   0111111111111111111111111111111111111111111111111111111111111111
   a << 1
   1111111111111111111111111111111111111111111111111111111111111110
   a >> 63
   0000000000000000000000000000000000000000000000000000000000000000
   b = encoded(a)
   1111111111111111111111111111111111111111111111111111111111111110
   signed(b) >> 1
   1111111111111111111111111111111111111111111111111111111111111111
   unsigned(b) >> 1
   0111111111111111111111111111111111111111111111111111111111111111
   -(b & 1))
   0000000000000000000000000000000000000000000000000000000000000000
   c = decoded(b)
   0111111111111111111111111111111111111111111111111111111111111111

   int64_t encode(int64_t n) {
       return ((n << 1) ^ (n >> 63));
   }
   static int64_t decode(int64_t s) {
       uint64_t n = static_cast<uint64_t>(s);
       return static_cast<int64_t>((n >> 1) ^ (-(s & 1)));
   }
*/
Decodes signed integer from unsigned,
with positive values even and negative values odd
starting around zero.
This saves transfer space and unifies integer encoding.








Decodes signed integer from unsigned with positive values even and negative values odd starting around zero . This saves transfer space and unifies integer encoding .
fn zigzag_decode(s: &[u8]) -> i64 {
    let unsigned_shr = |n: i64| {
        let n = u64::from_le_bytes(n.to_le_bytes()) >> 1;
        i64::from_le_bytes(n.to_le_bytes())
    };
    let s = read_i64(s);
    unsigned_shr(s) ^ (-(s & 1))
}
fn zigzag_decode ( s : & [ u8 ] ) -> i64 { let unsigned_shr = | n : i64 | { let n = u64 :: from_le_bytes ( n . to_le_bytes ( ) ) >> 1 ; i64 :: from_le_bytes ( n . to_le_bytes ( ) ) } ; let s = read_i64 ( s ) ; unsigned_shr ( s ) ^ ( - ( s & 1 ) ) }
Decodes signed integer from unsigned,
with positive values even and negative values odd
starting around zero.
Decodes signed integer from unsigned with positive values even and negative values odd starting around zero .
s
&[u8]
s
&[u8]