@@ -174,12 +174,6 @@ where
174174 memcpy ( & source. as_bytes ( ) [ ..num_bytes] , target)
175175}
176176
177- /// Returns the ceil of value/divisor
178- #[ inline]
179- pub fn ceil ( value : usize , divisor : usize ) -> usize {
180- value / divisor + ( ( value % divisor != 0 ) as usize )
181- }
182-
183177/// Returns ceil(log2(x))
184178#[ inline]
185179pub fn log2 ( mut x : u64 ) -> u32 {
@@ -354,7 +348,7 @@ impl BitWriter {
354348 /// Flushes the internal buffered bits and the align the buffer to the next byte.
355349 #[ inline]
356350 pub fn flush ( & mut self ) {
357- let num_bytes = ceil ( self . bit_offset , 8 ) ;
351+ let num_bytes = self . bit_offset . div_ceil ( 8 ) ;
358352 debug_assert ! ( self . byte_offset + num_bytes <= self . max_bytes) ;
359353 memcpy_value (
360354 & self . buffered_values ,
@@ -401,7 +395,7 @@ impl BitWriter {
401395
402396 #[ inline]
403397 pub fn bytes_written ( & self ) -> usize {
404- self . byte_offset - self . start + ceil ( self . bit_offset , 8 )
398+ self . byte_offset - self . start + self . bit_offset . div_ceil ( 8 )
405399 }
406400
407401 #[ inline]
@@ -598,7 +592,7 @@ impl BitReader {
598592 /// Gets the current byte offset
599593 #[ inline]
600594 pub fn get_byte_offset ( & self ) -> usize {
601- self . byte_offset + ceil ( self . bit_offset , 8 )
595+ self . byte_offset + self . bit_offset . div_ceil ( 8 )
602596 }
603597
604598 /// Reads a value of type `T` and of size `num_bits`.
@@ -724,7 +718,7 @@ impl BitReader {
724718 v >>= 8 - offset_r;
725719
726720 // Read the rest of the bytes
727- ( ( offset_i + 1 ) ..( offset_i + ceil ( n + offset_r, 8 ) ) ) . for_each ( |i| {
721+ ( ( offset_i + 1 ) ..( offset_i + usize :: div_ceil ( n + offset_r, 8 ) ) ) . for_each ( |i| {
728722 dst[ i] |= v as u8 ;
729723 v >>= 8 ;
730724 } ) ;
@@ -907,7 +901,7 @@ impl BitReader {
907901 debug_assert ! ( 8 >= size_of:: <T >( ) ) ;
908902 debug_assert ! ( num_bytes <= size_of:: <T >( ) ) ;
909903
910- let bytes_read = ceil ( self . bit_offset , 8 ) ;
904+ let bytes_read = self . bit_offset . div_ceil ( 8 ) ;
911905 if unlikely ( self . byte_offset + bytes_read + num_bytes > self . total_bytes ) {
912906 return None ;
913907 }
@@ -1052,21 +1046,6 @@ mod tests {
10521046 assert_eq ! ( read_u32( & buffer) , read_num_bytes!( u32 , 4 , & buffer) , ) ;
10531047 }
10541048
1055- #[ test]
1056- fn test_ceil ( ) {
1057- assert_eq ! ( ceil( 0 , 1 ) , 0 ) ;
1058- assert_eq ! ( ceil( 1 , 1 ) , 1 ) ;
1059- assert_eq ! ( ceil( 1 , 2 ) , 1 ) ;
1060- assert_eq ! ( ceil( 1 , 8 ) , 1 ) ;
1061- assert_eq ! ( ceil( 7 , 8 ) , 1 ) ;
1062- assert_eq ! ( ceil( 8 , 8 ) , 1 ) ;
1063- assert_eq ! ( ceil( 9 , 8 ) , 2 ) ;
1064- assert_eq ! ( ceil( 9 , 9 ) , 1 ) ;
1065- assert_eq ! ( ceil( 10000000000 , 10 ) , 1000000000 ) ;
1066- assert_eq ! ( ceil( 10 , 10000000000 ) , 1 ) ;
1067- assert_eq ! ( ceil( 10000000000 , 1000000000 ) , 10 ) ;
1068- }
1069-
10701049 #[ test]
10711050 fn test_bit_reader_get_byte_offset ( ) {
10721051 let buffer = vec ! [ 255 ; 10 ] ;
@@ -1316,7 +1295,7 @@ mod tests {
13161295
13171296 fn test_put_value_rand_numbers ( total : usize , num_bits : usize ) {
13181297 assert ! ( num_bits < 64 ) ;
1319- let num_bytes = ceil ( num_bits, 8 ) ;
1298+ let num_bytes = num_bits. div_ceil ( 8 ) ;
13201299 let mut writer = BitWriter :: new ( num_bytes * total) ;
13211300 let values: Vec < u64 > = random_numbers :: < u64 > ( total)
13221301 . iter ( )
@@ -1454,7 +1433,7 @@ mod tests {
14541433 T : FromBytes + Default + Clone + Debug + Eq ,
14551434 {
14561435 assert ! ( num_bits <= 32 ) ;
1457- let num_bytes = ceil ( num_bits, 8 ) ;
1436+ let num_bytes = num_bits. div_ceil ( 8 ) ;
14581437 let mut writer = BitWriter :: new ( num_bytes * total) ;
14591438
14601439 let values: Vec < u32 > = random_numbers :: < u32 > ( total)
@@ -1487,7 +1466,7 @@ mod tests {
14871466 const SIZE : & [ usize ] = & [ 1 , 31 , 32 , 33 , 128 , 129 ] ;
14881467 for total in SIZE {
14891468 for num_bits in 1 ..33 {
1490- let num_bytes = ceil ( num_bits, 8 ) ;
1469+ let num_bytes = usize :: div_ceil ( num_bits, 8 ) ;
14911470 let mut writer = BitWriter :: new ( num_bytes * total) ;
14921471
14931472 let values: Vec < u32 > = random_numbers :: < u32 > ( * total)
@@ -1533,7 +1512,7 @@ mod tests {
15331512 assert_eq ! ( total % 2 , 0 ) ;
15341513
15351514 let aligned_value_byte_width = std:: mem:: size_of :: < T > ( ) ;
1536- let value_byte_width = ceil ( num_bits, 8 ) ;
1515+ let value_byte_width = num_bits. div_ceil ( 8 ) ;
15371516 let mut writer =
15381517 BitWriter :: new ( ( total / 2 ) * ( aligned_value_byte_width + value_byte_width) ) ;
15391518 let values: Vec < u32 > = random_numbers :: < u32 > ( total / 2 )
0 commit comments