fn compute_chunk_status(lengths: &Lengths, needed_pieces: &BF) -> BF {
    let required_size = lengths.chunk_bitfield_bytes();
    let vec = vec![0u8; required_size];
    let mut chunk_bf = BF::from_vec(vec);
    for piece_index in needed_pieces
        .get(0..lengths.total_pieces() as usize)
        .unwrap()
        .iter_zeros()
    {
        let offset = piece_index * lengths.default_chunks_per_piece() as usize;
        let chunks_per_piece = lengths
            .chunks_per_piece(lengths.validate_piece_index(piece_index as u32).unwrap())
            as usize;
        chunk_bf
            .get_mut(offset..offset + chunks_per_piece)
            .unwrap()
            .set_all(true);
    }
    chunk_bf
}
// TODO: this should be redone from "have" pieces, not from "needed" pieces.
// Needed pieces are the ones we need to download, not necessarily the ones we have.
// E.g. we might have more pieces, but the client asks to download only some files
// partially.
this should be redone from "have" pieces, not from "needed" pieces.
Needed pieces are the ones we need to download, not necessarily the ones we have.
this should be redone from " have " pieces not from " needed " pieces . Needed pieces are the ones we need to download not necessarily the ones we have .
fn compute_chunk_status(lengths: &Lengths, needed_pieces: &BF) -> BF {
    let required_size = lengths.chunk_bitfield_bytes();
    let vec = vec![0u8; required_size];
    let mut chunk_bf = BF::from_vec(vec);
    for piece_index in needed_pieces
        .get(0..lengths.total_pieces() as usize)
        .unwrap()
        .iter_zeros()
    {
        let offset = piece_index * lengths.default_chunks_per_piece() as usize;
        let chunks_per_piece = lengths
            .chunks_per_piece(lengths.validate_piece_index(piece_index as u32).unwrap())
            as usize;
        chunk_bf
            .get_mut(offset..offset + chunks_per_piece)
            .unwrap()
            .set_all(true);
    }
    chunk_bf
}
fn compute_chunk_status ( lengths : & Lengths , needed_pieces : & BF ) -> BF { let required_size = lengths . chunk_bitfield_bytes ( ) ; let vec = vec ! [ 0u8 required_size ] ; let mut chunk_bf = BF :: from_vec ( vec ) ; for piece_index in needed_pieces . get ( 0 .. lengths . total_pieces ( ) as usize ) . unwrap ( ) . iter_zeros ( ) { let offset = piece_index * lengths . default_chunks_per_piece ( ) as usize ; let chunks_per_piece = lengths . chunks_per_piece ( lengths . validate_piece_index ( piece_index as u32 ) . unwrap ( ) ) as usize ; chunk_bf . get_mut ( offset .. offset + chunks_per_piece ) . unwrap ( ) . set_all ( true ) ; } chunk_bf }
TODO: this should be redone from "have" pieces, not from "needed" pieces.
TODO : this should be redone from " have " pieces not from " needed " pieces .
lengths
&Lengths
needed_pieces
&BF
lengths
&Lengths
needed_pieces
&BF