Skip to content

Commit b01b8e0

Browse files
committed
clippy
1 parent 80f5f1e commit b01b8e0

File tree

11 files changed

+36
-36
lines changed

11 files changed

+36
-36
lines changed

bitpacker/src/bitpacker.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl BitPacker {
4848

4949
pub fn flush<TWrite: io::Write + ?Sized>(&mut self, output: &mut TWrite) -> io::Result<()> {
5050
if self.mini_buffer_written > 0 {
51-
let num_bytes = (self.mini_buffer_written + 7) / 8;
51+
let num_bytes = self.mini_buffer_written.div_ceil(8);
5252
let bytes = self.mini_buffer.to_le_bytes();
5353
output.write_all(&bytes[..num_bytes])?;
5454
self.mini_buffer_written = 0;
@@ -65,7 +65,7 @@ impl BitPacker {
6565

6666
#[derive(Clone, Debug, Default, Copy)]
6767
pub struct BitUnpacker {
68-
num_bits: usize,
68+
num_bits: u32,
6969
mask: u64,
7070
}
7171

@@ -83,7 +83,7 @@ impl BitUnpacker {
8383
(1u64 << num_bits) - 1u64
8484
};
8585
BitUnpacker {
86-
num_bits: usize::from(num_bits),
86+
num_bits: u32::from(num_bits),
8787
mask,
8888
}
8989
}
@@ -94,7 +94,7 @@ impl BitUnpacker {
9494

9595
#[inline]
9696
pub fn get(&self, idx: u32, data: &[u8]) -> u64 {
97-
let addr_in_bits = idx as usize * self.num_bits;
97+
let addr_in_bits = idx as usize * self.num_bits as usize;
9898
let addr = addr_in_bits >> 3;
9999
if addr + 8 > data.len() {
100100
if self.num_bits == 0 {
@@ -134,13 +134,12 @@ impl BitUnpacker {
134134
"Bitwidth must be <= 32 to use this method."
135135
);
136136

137-
let end_idx: u32 = start_idx + output.len() as u32;
137+
let end_idx = start_idx + output.len() as u32;
138138

139-
// We use `usize` here to avoid overflow issues.
140-
let end_bit_read = (end_idx as usize) * self.num_bits;
141-
let end_byte_read = (end_bit_read + 7) / 8;
139+
let end_bit_read = end_idx * self.num_bits;
140+
let end_byte_read = end_bit_read.div_ceil(8);
142141
assert!(
143-
end_byte_read <= data.len(),
142+
end_byte_read as usize <= data.len(),
144143
"Requested index is out of bounds."
145144
);
146145

@@ -164,20 +163,20 @@ impl BitUnpacker {
164163

165164
let highway_start: u32 = start_idx + entrance_ramp_len;
166165

167-
if highway_start + (BitPacker1x::BLOCK_LEN as u32) > end_idx {
166+
if highway_start + BitPacker1x::BLOCK_LEN as u32 > end_idx {
168167
// We don't have enough values to have even a single block of highway.
169168
// Let's just supply the values the simple way.
170169
get_batch_ramp(start_idx, output);
171170
return;
172171
}
173172

174-
let num_blocks: usize = (end_idx - highway_start) as usize / BitPacker1x::BLOCK_LEN;
173+
let num_blocks: u32 = (end_idx - highway_start) / BitPacker1x::BLOCK_LEN as u32;
175174

176175
// Entrance ramp
177176
get_batch_ramp(start_idx, &mut output[..entrance_ramp_len as usize]);
178177

179178
// Highway
180-
let mut offset = (highway_start as usize * self.num_bits) / 8;
179+
let mut offset = (highway_start * self.num_bits) as usize / 8;
181180
let mut output_cursor = (highway_start - start_idx) as usize;
182181
for _ in 0..num_blocks {
183182
offset += BitPacker1x.decompress(
@@ -189,7 +188,7 @@ impl BitUnpacker {
189188
}
190189

191190
// Exit ramp
192-
let highway_end: u32 = highway_start + (num_blocks * BitPacker1x::BLOCK_LEN) as u32;
191+
let highway_end: u32 = highway_start + num_blocks * BitPacker1x::BLOCK_LEN as u32;
193192
get_batch_ramp(highway_end, &mut output[output_cursor..]);
194193
}
195194

@@ -258,7 +257,7 @@ mod test {
258257
bitpacker.write(val, num_bits, &mut data).unwrap();
259258
}
260259
bitpacker.close(&mut data).unwrap();
261-
assert_eq!(data.len(), ((num_bits as usize) * len + 7) / 8);
260+
assert_eq!(data.len(), ((num_bits as usize) * len).div_ceil(8));
262261
let bitunpacker = BitUnpacker::new(num_bits);
263262
(bitunpacker, vals, data)
264263
}
@@ -304,7 +303,7 @@ mod test {
304303
bitpacker.write(val, num_bits, &mut buffer).unwrap();
305304
}
306305
bitpacker.flush(&mut buffer).unwrap();
307-
assert_eq!(buffer.len(), (vals.len() * num_bits as usize + 7) / 8);
306+
assert_eq!(buffer.len(), (vals.len() * num_bits as usize).div_ceil(8));
308307
let bitunpacker = BitUnpacker::new(num_bits);
309308
let max_val = if num_bits == 64 {
310309
u64::MAX

bitpacker/src/blocked_bitpacker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct BlockedBitpackerEntryMetaData {
3434

3535
impl BlockedBitpackerEntryMetaData {
3636
fn new(offset: u64, num_bits: u8, base_value: u64) -> Self {
37-
let encoded = offset | (u64::from(num_bits) << (64 - 8));
37+
let encoded = offset | ((num_bits as u64) << (64 - 8));
3838
Self {
3939
encoded,
4040
base_value,

columnar/benches/bench_values_u64.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn bench_intfastfield_stride7_vec(b: &mut Bencher) {
141141
b.iter(|| {
142142
let mut a = 0u64;
143143
for i in (0..n / 7).map(|val| val * 7) {
144-
a += permutation[i as usize];
144+
a += permutation[i];
145145
}
146146
a
147147
});
@@ -196,7 +196,7 @@ fn bench_intfastfield_scan_all_vec(b: &mut Bencher) {
196196
b.iter(|| {
197197
let mut a = 0u64;
198198
for i in 0..permutation.len() {
199-
a += permutation[i as usize] as u64;
199+
a += permutation[i] as u64;
200200
}
201201
a
202202
});

columnar/src/column_index/merge/stacked.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ fn get_num_values_iterator<'a>(
105105
) -> Box<dyn Iterator<Item = u32> + 'a> {
106106
match column_index {
107107
ColumnIndex::Empty { .. } => Box::new(std::iter::empty()),
108-
ColumnIndex::Full => Box::new(std::iter::repeat(1u32).take(num_docs as usize)),
109-
ColumnIndex::Optional(optional_index) => {
110-
Box::new(std::iter::repeat(1u32).take(optional_index.num_non_nulls() as usize))
111-
}
108+
ColumnIndex::Full => Box::new(std::iter::repeat_n(1u32, num_docs as usize)),
109+
ColumnIndex::Optional(optional_index) => Box::new(std::iter::repeat_n(
110+
1u32,
111+
optional_index.num_non_nulls() as usize,
112+
)),
112113
ColumnIndex::Multivalued(multivalued_index) => Box::new(
113114
multivalued_index
114115
.get_start_index_column()

columnar/src/column_values/u64_based/bitpacked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl ColumnCodecEstimator for BitpackedCodecEstimator {
109109

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

115115
fn serialize(

columnar/src/column_values/u64_based/linear.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl ColumnCodecEstimator for LinearCodecEstimator {
117117
Some(
118118
stats.num_bytes()
119119
+ linear_params.num_bytes()
120-
+ (num_bits as u64 * stats.num_rows as u64 + 7) / 8,
120+
+ (num_bits as u64 * stats.num_rows as u64).div_ceil(8),
121121
)
122122
}
123123

columnar/src/columnar/writer/column_operation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl SymbolValue for UnorderedId {
244244

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

250250
fn encode_zig_zag(n: i64) -> u64 {

common/src/bitset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub struct BitSet {
183183
}
184184

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

189189
impl BitSet {

src/schema/document/default_document.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::schema::field_type::ValueParsingError;
1515
use crate::schema::{Facet, Field, NamedFieldDocument, OwnedValue, Schema};
1616
use crate::tokenizer::PreTokenizedString;
1717

18-
#[repr(C, packed)]
18+
#[repr(Rust, packed)]
1919
#[derive(Debug, Clone)]
2020
/// A field value pair in the compact tantivy document
2121
struct FieldValueAddr {
@@ -480,7 +480,7 @@ impl<'a> CompactDocValue<'a> {
480480
type Addr = u32;
481481

482482
#[derive(Clone, Copy, Default)]
483-
#[repr(C, packed)]
483+
#[repr(Rust, packed)]
484484
/// The value type and the address to its payload in the container.
485485
struct ValueAddr {
486486
type_id: ValueType,
@@ -734,7 +734,7 @@ mod tests {
734734

735735
#[test]
736736
fn test_json_value() {
737-
let json_str = r#"{
737+
let json_str = r#"{
738738
"toto": "titi",
739739
"float": -0.2,
740740
"bool": true,

sstable/src/dictionary.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,18 +1059,18 @@ mod tests {
10591059
fn test_prefix_edge() {
10601060
let dict = {
10611061
let mut builder = Dictionary::<MonotonicU64SSTable>::builder(Vec::new()).unwrap();
1062-
builder.insert(&[0, 254], &0).unwrap();
1063-
builder.insert(&[0, 255], &1).unwrap();
1064-
builder.insert(&[0, 255, 12], &2).unwrap();
1065-
builder.insert(&[1], &2).unwrap();
1066-
builder.insert(&[1, 0], &2).unwrap();
1062+
builder.insert([0, 254], &0).unwrap();
1063+
builder.insert([0, 255], &1).unwrap();
1064+
builder.insert([0, 255, 12], &2).unwrap();
1065+
builder.insert([1], &2).unwrap();
1066+
builder.insert([1, 0], &2).unwrap();
10671067
let table = builder.finish().unwrap();
10681068
let table = Arc::new(PermissionedHandle::new(table));
10691069
let slice = common::file_slice::FileSlice::new(table.clone());
10701070
Dictionary::<MonotonicU64SSTable>::open(slice).unwrap()
10711071
};
10721072

1073-
let mut stream = dict.prefix_range(&[0, 255]).into_stream().unwrap();
1073+
let mut stream = dict.prefix_range([0, 255]).into_stream().unwrap();
10741074
assert!(stream.advance());
10751075
assert_eq!(stream.key(), &[0, 255]);
10761076
assert!(stream.advance());

sstable/src/sstable_index_v3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ impl BlockAddrBlockMetadata {
438438
let ordinal_addr = range_start_addr + self.range_start_nbits as usize;
439439
let range_end_addr = range_start_addr + num_bits;
440440

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

0 commit comments

Comments
 (0)