pub fn encode(src: &[u64], dst: &mut Vec<u8>) -> Result<(), Box<dyn Error>> {
    let mut i = 0;
    'next_value: while i < src.len() {
        // try to pack a run of 240 or 120 1s
        let remain = src.len() - i;
        if remain >= 120 {
            let a = if remain >= 240 {
                &src[i..i + 240]
            } else {
                &src[i..i + 120]
            };

            // search for the longest sequence of 1s in a
            let k = a.iter().take_while(|x| **x == 1).count();
            if k == 240 {
                i += 240;
                dst.resize(dst.len() + 8, 0);
                continue;
            } else if k >= 120 {
                i += 120;
                dst.extend_from_slice(&(1u64 << 60).to_be_bytes());
                continue;
            }
        }

        'codes: for (idx, code) in NUM_BITS.iter().enumerate() {
            let (int_n, bit_n) = (code[0] as usize, code[1] as usize);
            if int_n > remain {
                continue;
            }

            let max_val = 1u64 << (bit_n & 0x3f) as u64;
            let mut val = ((idx as u64) + 2) << S8B_BIT_SIZE;
            for (k, in_v) in src[i..].iter().enumerate() {
                if k < int_n {
                    if *in_v >= max_val {
                        continue 'codes;
                    }
                    val |= in_v << ((k * bit_n) as u8 & 0x3f)
                } else {
                    break;
                }
            }
            dst.extend_from_slice(&val.to_be_bytes());
            i += int_n;
            continue 'next_value;
        }
        return Err(From::from("value out of bounds"));
    }
    Ok(())
}
/// encode packs and binary encodes the provides slice of u64 values using
/// simple8b into the provided vector.
encode packs and binary encodes the provides slice of u64 values using
simple8b into the provided vector.
encode packs and binary encodes the provides slice of u64 values using simple8b into the provided vector .
pub fn encode(src: &[u64], dst: &mut Vec<u8>) -> Result<(), Box<dyn Error>> {
    let mut i = 0;
    'next_value: while i < src.len() {
        // try to pack a run of 240 or 120 1s
        let remain = src.len() - i;
        if remain >= 120 {
            let a = if remain >= 240 {
                &src[i..i + 240]
            } else {
                &src[i..i + 120]
            };
            // search for the longest sequence of 1s in a
            let k = a.iter().take_while(|x| **x == 1).count();
            if k == 240 {
                i += 240;
                dst.resize(dst.len() + 8, 0);
                continue;
            } else if k >= 120 {
                i += 120;
                dst.extend_from_slice(&(1u64 << 60).to_be_bytes());
                continue;
            }
        }
        'codes: for (idx, code) in NUM_BITS.iter().enumerate() {
            let (int_n, bit_n) = (code[0] as usize, code[1] as usize);
            if int_n > remain {
                continue;
            }
            let max_val = 1u64 << (bit_n & 0x3f) as u64;
            let mut val = ((idx as u64) + 2) << S8B_BIT_SIZE;
            for (k, in_v) in src[i..].iter().enumerate() {
                if k < int_n {
                    if *in_v >= max_val {
                        continue 'codes;
                    }
                    val |= in_v << ((k * bit_n) as u8 & 0x3f)
                } else {
                    break;
                }
            }
            dst.extend_from_slice(&val.to_be_bytes());
            i += int_n;
            continue 'next_value;
        }
        return Err(From::from("value out of bounds"));
    }
    Ok(())
}
pub fn encode ( src : & [ u64 ] , dst : & mut Vec < u8 > ) -> Result < ( ) , Box < dyn Error > > { let mut i = 0 ; ' next_value : while i < src . len ( ) { // try to pack a run of 240 or 120 1s let remain = src . len ( ) - i ; if remain >= 120 { let a = if remain >= 240 { & src [ i .. i + 240 ] } else { & src [ i .. i + 120 ] } ; // search for the longest sequence of 1s in a let k = a . iter ( ) . take_while ( | x | * * x == 1 ) . count ( ) ; if k == 240 { i += 240 ; dst . resize ( dst . len ( ) + 8 , 0 ) ; continue ; } else if k >= 120 { i += 120 ; dst . extend_from_slice ( & ( 1u64 << 60 ) . to_be_bytes ( ) ) ; continue ; } } ' codes : for ( idx , code ) in NUM_BITS . iter ( ) . enumerate ( ) { let ( int_n , bit_n ) = ( code [ 0 ] as usize , code [ 1 ] as usize ) ; if int_n > remain { continue ; } let max_val = 1u64 << ( bit_n & 0x3f ) as u64 ; let mut val = ( ( idx as u64 ) + 2 ) << S8B_BIT_SIZE ; for ( k , in_v ) in src [ i .. ] . iter ( ) . enumerate ( ) { if k < int_n { if * in_v >= max_val { continue ' codes ; } val |= in_v << ( ( k * bit_n ) as u8 & 0x3f ) } else { break ; } } dst . extend_from_slice ( & val . to_be_bytes ( ) ) ; i += int_n ; continue ' next_value ; } return Err ( From :: from ( " " ) ) ; } Ok ( ( ) ) }
encode packs and binary encodes the provides slice of u64 values using
simple8b into the provided vector.
encode packs and binary encodes the provides slice of u64 values using simple8b into the provided vector .
src
&[u64]
dst
&mut Vec<u8>
src
&[u64]
dst
&mut Vec<u8>