pub fn count_bytes<E, I : IntoIterator<Item=Result<u8, E>>>(bytes: I) -> Result<Self, E> {
        let mut acc: Vec<u64> = vec![0;256];
        for maybe_byte in bytes {
            let b = maybe_byte?;
            // Always fine since the byte is in the index
            acc[b as usize] += 1;
        }
        // There will always be at least one byte
        let max = acc.iter().max().unwrap();
        let mut pairs = Vec::with_capacity(acc.len());
        // This guarantees a consistent ordering of pairs, and thus of the H Tree
        let mut byte = 0;
        for &count in &acc {
            if count != 0 {
                pairs.push(((count * 255 / max) as u8, byte as u8));
            }
            byte += 1
        }
        // Sort pairs in reverse order by count
        pairs.sort_by(|(count1, _), (count2, _)| count2.cmp(count1));
        Ok(Frequencies { pairs })
    }
/// Count the number of occurrences of each byte in order to build
/// up a struct of Frequencies
Count the number of occurrences of each byte in order to build
up a struct of Frequencies
Count the number of occurrences of each byte in order to build up a struct of Frequencies
pub fn count_bytes<E, I : IntoIterator<Item=Result<u8, E>>>(bytes: I) -> Result<Self, E> {
        let mut acc: Vec<u64> = vec![0;256];
        for maybe_byte in bytes {
            let b = maybe_byte?;
            // Always fine since the byte is in the index
            acc[b as usize] += 1;
        }
        // There will always be at least one byte
        let max = acc.iter().max().unwrap();
        let mut pairs = Vec::with_capacity(acc.len());
        // This guarantees a consistent ordering of pairs, and thus of the H Tree
        let mut byte = 0;
        for &count in &acc {
            if count != 0 {
                pairs.push(((count * 255 / max) as u8, byte as u8));
            }
            byte += 1
        }
        // Sort pairs in reverse order by count
        pairs.sort_by(|(count1, _), (count2, _)| count2.cmp(count1));
        Ok(Frequencies { pairs })
    }
pub fn count_bytes < E , I : IntoIterator < Item = Result < u8 , E > > > ( bytes : I ) -> Result < Self , E > { let mut acc : Vec < u64 > = vec ! [ 0 256 ] ; for maybe_byte in bytes { let b = maybe_byte ? ; // Always fine since the byte is in the index acc [ b as usize ] += 1 ; } // There will always be at least one byte let max = acc . iter ( ) . max ( ) . unwrap ( ) ; let mut pairs = Vec :: with_capacity ( acc . len ( ) ) ; // This guarantees a consistent ordering of pairs, and thus of the H Tree let mut byte = 0 ; for & count in & acc { if count != 0 { pairs . push ( ( ( count * 255 / max ) as u8 , byte as u8 ) ) ; } byte += 1 } // Sort pairs in reverse order by count pairs . sort_by ( | ( count1 , _ ) , ( count2 , _ ) | count2 . cmp ( count1 ) ) ; Ok ( Frequencies { pairs } ) }
Count the number of occurrences of each byte in order to build
up a struct of Frequencies
Count the number of occurrences of each byte in order to build up a struct of Frequencies
bytes
I
bytes
I