Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bitpacker/src/bitpacker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl BitPacker {

pub fn flush<TWrite: io::Write + ?Sized>(&mut self, output: &mut TWrite) -> io::Result<()> {
if self.mini_buffer_written > 0 {
let num_bytes = (self.mini_buffer_written + 7) / 8;
let num_bytes = self.mini_buffer_written.div_ceil(8);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it does not matter, but this has a small micro impact on performance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good to know, I thought it would lead to the same instruction

let bytes = self.mini_buffer.to_le_bytes();
output.write_all(&bytes[..num_bytes])?;
self.mini_buffer_written = 0;
Expand Down Expand Up @@ -138,7 +138,7 @@ impl BitUnpacker {

// We use `usize` here to avoid overflow issues.
let end_bit_read = (end_idx as usize) * self.num_bits;
let end_byte_read = (end_bit_read + 7) / 8;
let end_byte_read = end_bit_read.div_ceil(8);
assert!(
end_byte_read <= data.len(),
"Requested index is out of bounds."
Expand Down Expand Up @@ -258,7 +258,7 @@ mod test {
bitpacker.write(val, num_bits, &mut data).unwrap();
}
bitpacker.close(&mut data).unwrap();
assert_eq!(data.len(), ((num_bits as usize) * len + 7) / 8);
assert_eq!(data.len(), ((num_bits as usize) * len).div_ceil(8));
let bitunpacker = BitUnpacker::new(num_bits);
(bitunpacker, vals, data)
}
Expand Down Expand Up @@ -304,7 +304,7 @@ mod test {
bitpacker.write(val, num_bits, &mut buffer).unwrap();
}
bitpacker.flush(&mut buffer).unwrap();
assert_eq!(buffer.len(), (vals.len() * num_bits as usize + 7) / 8);
assert_eq!(buffer.len(), (vals.len() * num_bits as usize).div_ceil(8));
let bitunpacker = BitUnpacker::new(num_bits);
let max_val = if num_bits == 64 {
u64::MAX
Expand Down
4 changes: 2 additions & 2 deletions columnar/benches/bench_values_u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn bench_intfastfield_stride7_vec(b: &mut Bencher) {
b.iter(|| {
let mut a = 0u64;
for i in (0..n / 7).map(|val| val * 7) {
a += permutation[i as usize];
a += permutation[i];
}
a
});
Expand Down Expand Up @@ -196,7 +196,7 @@ fn bench_intfastfield_scan_all_vec(b: &mut Bencher) {
b.iter(|| {
let mut a = 0u64;
for i in 0..permutation.len() {
a += permutation[i as usize] as u64;
a += permutation[i] as u64;
}
a
});
Expand Down
9 changes: 5 additions & 4 deletions columnar/src/column_index/merge/stacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ fn get_num_values_iterator<'a>(
) -> Box<dyn Iterator<Item = u32> + 'a> {
match column_index {
ColumnIndex::Empty { .. } => Box::new(std::iter::empty()),
ColumnIndex::Full => Box::new(std::iter::repeat(1u32).take(num_docs as usize)),
ColumnIndex::Optional(optional_index) => {
Box::new(std::iter::repeat(1u32).take(optional_index.num_non_nulls() as usize))
}
ColumnIndex::Full => Box::new(std::iter::repeat_n(1u32, num_docs as usize)),
ColumnIndex::Optional(optional_index) => Box::new(std::iter::repeat_n(
1u32,
optional_index.num_non_nulls() as usize,
)),
ColumnIndex::Multivalued(multivalued_index) => Box::new(
multivalued_index
.get_start_index_column()
Expand Down
2 changes: 1 addition & 1 deletion columnar/src/column_values/u64_based/bitpacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl ColumnCodecEstimator for BitpackedCodecEstimator {

fn estimate(&self, stats: &ColumnStats) -> Option<u64> {
let num_bits_per_value = num_bits(stats);
Some(stats.num_bytes() + (stats.num_rows as u64 * (num_bits_per_value as u64) + 7) / 8)
Some(stats.num_bytes() + (stats.num_rows as u64 * (num_bits_per_value as u64)).div_ceil(8))
}

fn serialize(
Expand Down
2 changes: 1 addition & 1 deletion columnar/src/column_values/u64_based/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl ColumnCodecEstimator for LinearCodecEstimator {
Some(
stats.num_bytes()
+ linear_params.num_bytes()
+ (num_bits as u64 * stats.num_rows as u64 + 7) / 8,
+ (num_bits as u64 * stats.num_rows as u64).div_ceil(8),
)
}

Expand Down
2 changes: 1 addition & 1 deletion columnar/src/columnar/writer/column_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl SymbolValue for UnorderedId {

fn compute_num_bytes_for_u64(val: u64) -> usize {
let msb = (64u32 - val.leading_zeros()) as usize;
(msb + 7) / 8
msb.div_ceil(8)
}

fn encode_zig_zag(n: i64) -> u64 {
Expand Down
2 changes: 1 addition & 1 deletion common/src/bitset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub struct BitSet {
}

fn num_buckets(max_val: u32) -> u32 {
(max_val + 63u32) / 64u32
max_val.div_ceil(64u32)
}

impl BitSet {
Expand Down
2 changes: 1 addition & 1 deletion sstable/src/sstable_index_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl BlockAddrBlockMetadata {
let ordinal_addr = range_start_addr + self.range_start_nbits as usize;
let range_end_addr = range_start_addr + num_bits;

if (range_end_addr + self.range_start_nbits as usize + 7) / 8 > data.len() {
if (range_end_addr + self.range_start_nbits as usize).div_ceil(8) > data.len() {
return None;
}

Expand Down
Loading