pub fn convert_2d_to_1d (x: usize, y: usize, n: usize) -> usize {
    assert!((n & (n - 1)) == 0, "n must be a power of 2");
    let mut d = 0;
    let mut s = n / 2;
    let (mut x, mut y) = (x, y);
    let (mut rx, mut ry);

    while s > 0 {
        rx = if (x & s) > 0 { 1 } else { 0 };
        ry = if (y & s) > 0 { 1 } else { 0 };
        d += s * s * ((3 * rx) ^ ry);
        rotate(s, &mut x, &mut y, rx, ry);
        s /= 2
    }

    d
}
/// Convert a pair of (x, y) coordinates to a one-dimensional distance.
Convert a pair of (x, y) coordinates to a one-dimensional distance.
Convert a pair of ( x y ) coordinates to a one - dimensional distance .
pub fn convert_2d_to_1d (x: usize, y: usize, n: usize) -> usize {
    assert!((n & (n - 1)) == 0, "n must be a power of 2");
    let mut d = 0;
    let mut s = n / 2;
    let (mut x, mut y) = (x, y);
    let (mut rx, mut ry);
    while s > 0 {
        rx = if (x & s) > 0 { 1 } else { 0 };
        ry = if (y & s) > 0 { 1 } else { 0 };
        d += s * s * ((3 * rx) ^ ry);
        rotate(s, &mut x, &mut y, rx, ry);
        s /= 2
    }
    d
}
pub fn convert_2d_to_1d ( x : usize , y : usize , n : usize ) -> usize { assert ! ( ( n ( n 1 ) ) 0 " " ) ; let mut d = 0 ; let mut s = n / 2 ; let ( mut x , mut y ) = ( x , y ) ; let ( mut rx , mut ry ) ; while s > 0 { rx = if ( x & s ) > 0 { 1 } else { 0 } ; ry = if ( y & s ) > 0 { 1 } else { 0 } ; d += s * s * ( ( 3 * rx ) ^ ry ) ; rotate ( s , & mut x , & mut y , rx , ry ) ; s /= 2 } d }
Convert a pair of (x, y) coordinates to a one-dimensional distance.
Convert a pair of ( x y ) coordinates to a one - dimensional distance .
x
usize
y
usize
n
usize
x
usize
y
usize
n
usize