fn p_insert(k: u64, a: &mut [u64], offset: u64) -> usize {
    let n = a.len();
    for pov in 0..n {
        let ii = ((k + pov as u64) % n as u64) as usize;
        let ki = a[ii] >> offset;
        let pov_ki = p_poverty(ki, ii, n);
        if a[ii] == 0 || ki == k {
            // println!("already got a spot");
            return ii;
        } else if pov_ki < pov {
            // println!("need to steal from {} < {} at spot {}", pov_ki, pov, ii);
            // need to steal
            let stolen = ii;
            let mut displaced = a[ii];
            // println!("displaced value is {}", displaced);
            let mut pov_displaced = pov_ki;
            a[stolen] = 0;

            for j in 1..n {
                pov_displaced += 1;
                let jj = (stolen + j) % n;
                let kj = a[jj] >> offset;
                let pov_kj = p_poverty(kj, jj, n);
                if a[jj] == 0 {
                    // We finally found an unoccupied spot!
                    // println!("put the displaced at {}", jj);
                    a[jj] = displaced;
                    return stolen;
                }
                if pov_kj < pov_displaced {
                    // need to steal again!
                    std::mem::swap(&mut a[jj], &mut displaced);
                    pov_displaced = pov_kj;
                }
            }
            panic!("p_insert was called when there was no room!")
        }
    }
    unreachable!()
}
/// This inserts k into the array, and requires that there be room for
/// one more element.  Otherwise, things will be sad.
This inserts k into the array, and requires that there be room for
one more element.  Otherwise, things will be sad.
This inserts k into the array and requires that there be room for one more element . Otherwise things will be sad .
fn p_insert(k: u64, a: &mut [u64], offset: u64) -> usize {
    let n = a.len();
    for pov in 0..n {
        let ii = ((k + pov as u64) % n as u64) as usize;
        let ki = a[ii] >> offset;
        let pov_ki = p_poverty(ki, ii, n);
        if a[ii] == 0 || ki == k {
            // println!("already got a spot");
            return ii;
        } else if pov_ki < pov {
            // println!("need to steal from {} < {} at spot {}", pov_ki, pov, ii);
            // need to steal
            let stolen = ii;
            let mut displaced = a[ii];
            // println!("displaced value is {}", displaced);
            let mut pov_displaced = pov_ki;
            a[stolen] = 0;
            for j in 1..n {
                pov_displaced += 1;
                let jj = (stolen + j) % n;
                let kj = a[jj] >> offset;
                let pov_kj = p_poverty(kj, jj, n);
                if a[jj] == 0 {
                    // We finally found an unoccupied spot!
                    // println!("put the displaced at {}", jj);
                    a[jj] = displaced;
                    return stolen;
                }
                if pov_kj < pov_displaced {
                    // need to steal again!
                    std::mem::swap(&mut a[jj], &mut displaced);
                    pov_displaced = pov_kj;
                }
            }
            panic!("p_insert was called when there was no room!")
        }
    }
    unreachable!()
}
fn p_insert ( k : u64 , a : & mut [ u64 ] , offset : u64 ) -> usize { let n = a . len ( ) ; for pov in 0 .. n { let ii = ( ( k + pov as u64 ) % n as u64 ) as usize ; let ki = a [ ii ] >> offset ; let pov_ki = p_poverty ( ki , ii , n ) ; if a [ ii ] == 0 || ki == k { // println!("already got a spot"); return ii ; } else if pov_ki < pov { // println!("need to steal from {} < {} at spot {}", pov_ki, pov, ii); // need to steal let stolen = ii ; let mut displaced = a [ ii ] ; // println!("displaced value is {}", displaced); let mut pov_displaced = pov_ki ; a [ stolen ] = 0 ; for j in 1 .. n { pov_displaced += 1 ; let jj = ( stolen + j ) % n ; let kj = a [ jj ] >> offset ; let pov_kj = p_poverty ( kj , jj , n ) ; if a [ jj ] == 0 { // We finally found an unoccupied spot! // println!("put the displaced at {}", jj); a [ jj ] = displaced ; return stolen ; } if pov_kj < pov_displaced { // need to steal again! std :: mem :: swap ( & mut a [ jj ] , & mut displaced ) ; pov_displaced = pov_kj ; } } panic ! ( " " ) } } unreachable ! ( ) }
This inserts k into the array, and requires that there be room for
one more element.
This inserts k into the array and requires that there be room for one more element .
k
u64
a
&mut [u64]
offset
u64
k
u64
a
&mut [u64]
offset
u64