Run cargo clippy --fix

This commit is contained in:
Christopher Berner 2023-07-03 10:36:03 -07:00
parent 5fbea3a8a4
commit eafdc58d0a
9 changed files with 33 additions and 45 deletions

@ -7,7 +7,7 @@ const SYMBOL_COUNTS: [usize; 10] = [10, 100, 250, 500, 1000, 2000, 5000, 10000,
fn black_box(value: u64) { fn black_box(value: u64) {
if value == rand::thread_rng().gen() { if value == rand::thread_rng().gen() {
println!("{}", value); println!("{value}");
} }
} }
@ -24,8 +24,7 @@ fn benchmark(symbol_size: u16, overhead: f64) -> u64 {
let config = ObjectTransmissionInformation::new(0, symbol_size, 0, 1, 1); let config = ObjectTransmissionInformation::new(0, symbol_size, 0, 1, 1);
let encoder = SourceBlockEncoder::new2(1, &config, &data); let encoder = SourceBlockEncoder::new2(1, &config, &data);
let elements_and_overhead = (symbol_count as f64 * (1.0 + overhead)) as u32; let elements_and_overhead = (symbol_count as f64 * (1.0 + overhead)) as u32;
let mut packets = let mut packets = encoder.repair_packets(0, (iterations as u32 * elements_and_overhead));
encoder.repair_packets(0, (iterations as u32 * elements_and_overhead) as u32);
let now = Instant::now(); let now = Instant::now();
for _ in 0..iterations { for _ in 0..iterations {
let mut decoder = SourceBlockDecoder::new2(1, &config, elements as u64); let mut decoder = SourceBlockDecoder::new2(1, &config, elements as u64);
@ -45,12 +44,12 @@ fn benchmark(symbol_size: u16, overhead: f64) -> u64 {
throughput); throughput);
} }
return black_box_value; black_box_value
} }
fn main() { fn main() {
let symbol_size = 1280; let symbol_size = 1280;
println!("Symbol size: {} bytes", symbol_size); println!("Symbol size: {symbol_size} bytes");
black_box(benchmark(symbol_size, 0.0)); black_box(benchmark(symbol_size, 0.0));
println!(); println!();
black_box(benchmark(symbol_size, 0.05)); black_box(benchmark(symbol_size, 0.05));

@ -7,7 +7,7 @@ const SYMBOL_COUNTS: [usize; 10] = [10, 100, 250, 500, 1000, 2000, 5000, 10000,
fn black_box(value: u64) { fn black_box(value: u64) {
if value == rand::thread_rng().gen() { if value == rand::thread_rng().gen() {
println!("{}", value); println!("{value}");
} }
} }
@ -49,17 +49,14 @@ fn benchmark(symbol_size: u16, pre_plan: bool) -> u64 {
throughput throughput
); );
} }
return black_box_value; black_box_value
} }
fn main() { fn main() {
let symbol_size = 1280; let symbol_size = 1280;
println!( println!("Symbol size: {symbol_size} bytes (without pre-built plan)");
"Symbol size: {} bytes (without pre-built plan)",
symbol_size
);
black_box(benchmark(symbol_size, false)); black_box(benchmark(symbol_size, false));
println!(); println!();
println!("Symbol size: {} bytes (with pre-built plan)", symbol_size); println!("Symbol size: {symbol_size} bytes (with pre-built plan)");
black_box(benchmark(symbol_size, true)); black_box(benchmark(symbol_size, true));
} }

@ -41,7 +41,7 @@ fn main() {
let mut result = None; let mut result = None;
while !packets.is_empty() { while !packets.is_empty() {
result = decoder.decode(EncodingPacket::deserialize(&packets.pop().unwrap())); result = decoder.decode(EncodingPacket::deserialize(&packets.pop().unwrap()));
if result != None { if result.is_some() {
break; break;
} }
} }

@ -105,7 +105,7 @@ fn generate_hdpc_rows(Kprime: usize, S: usize, H: usize) -> DenseOctetMatrix {
// I_H // I_H
for i in 0..H { for i in 0..H {
matrix.set(i, i + (Kprime + S) as usize, Octet::one()); matrix.set(i, i + (Kprime + S), Octet::one());
} }
matrix matrix
@ -147,7 +147,7 @@ pub fn generate_constraint_matrix<T: BinaryMatrix>(
// I_S // I_S
for i in 0..S { for i in 0..S {
matrix.set(i as usize, i + B as usize, Octet::one()); matrix.set(i, i + B, Octet::one());
} }
// G_LDPC,2 // G_LDPC,2
@ -167,7 +167,7 @@ pub fn generate_constraint_matrix<T: BinaryMatrix>(
let tuple = intermediate_tuple(i, lt_symbols, sys_index, p1); let tuple = intermediate_tuple(i, lt_symbols, sys_index, p1);
for j in enc_indices(tuple, lt_symbols, pi_symbols, p1) { for j in enc_indices(tuple, lt_symbols, pi_symbols, p1) {
matrix.set(row as usize + S + H, j, Octet::one()); matrix.set(row + S + H, j, Octet::one());
} }
} }
@ -251,7 +251,7 @@ mod tests {
// I_H // I_H
for i in 0..H { for i in 0..H {
matrix.set(i, i + (Kprime + S) as usize, Octet::one()); matrix.set(i, i + (Kprime + S), Octet::one());
} }
matrix matrix
@ -265,9 +265,7 @@ mod tests {
assert_eq!( assert_eq!(
matrix1.get(i, j), matrix1.get(i, j),
matrix2.get(i, j), matrix2.get(i, j),
"Matrices are not equal at row={} col={}", "Matrices are not equal at row={i} col={j}"
i,
j
); );
} }
} }

@ -190,7 +190,7 @@ impl SourceBlockDecoder {
let mut symbol_offset = 0; let mut symbol_offset = 0;
let mut sub_block_offset = 0; let mut sub_block_offset = 0;
for sub_block in 0..(nl + ns) as u32 { for sub_block in 0..(nl + ns) {
let bytes = if sub_block < nl { let bytes = if sub_block < nl {
tl as usize * self.symbol_alignment as usize tl as usize * self.symbol_alignment as usize
} else { } else {
@ -405,7 +405,7 @@ mod codec_tests {
let mut result = None; let mut result = None;
while !packets.is_empty() { while !packets.is_empty() {
result = decoder.decode(packets.pop().unwrap()); result = decoder.decode(packets.pop().unwrap());
if result != None { if result.is_some() {
break; break;
} }
} }
@ -449,7 +449,7 @@ mod codec_tests {
let mut result = None; let mut result = None;
while !packets.is_empty() { while !packets.is_empty() {
result = decoder.decode(packets.pop().unwrap()); result = decoder.decode(packets.pop().unwrap());
if result != None { if result.is_some() {
break; break;
} }
} }
@ -489,7 +489,7 @@ mod codec_tests {
} }
if progress && symbol_count % 100 == 0 { if progress && symbol_count % 100 == 0 {
println!("Completed {} symbols", symbol_count) println!("Completed {symbol_count} symbols")
} }
let config = ObjectTransmissionInformation::new(0, symbol_size as u16, 0, 1, 1); let config = ObjectTransmissionInformation::new(0, symbol_size as u16, 0, 1, 1);
@ -556,8 +556,7 @@ mod codec_tests {
let config = ObjectTransmissionInformation::new(0, symbol_size, 0, 1, 1); let config = ObjectTransmissionInformation::new(0, symbol_size, 0, 1, 1);
let encoder = SourceBlockEncoder::new2(1, &config, &data); let encoder = SourceBlockEncoder::new2(1, &config, &data);
let elements_and_overhead = (symbol_count as f64 * (1.0 + overhead)) as u32; let elements_and_overhead = (symbol_count as f64 * (1.0 + overhead)) as u32;
let mut packets = let mut packets = encoder.repair_packets(0, (iterations as u32 * elements_and_overhead));
encoder.repair_packets(0, (iterations as u32 * elements_and_overhead) as u32);
for _ in 0..iterations { for _ in 0..iterations {
let mut decoder = SourceBlockDecoder::new2(1, &config, elements as u64); let mut decoder = SourceBlockDecoder::new2(1, &config, elements as u64);
let start = packets.len() - elements_and_overhead as usize; let start = packets.len() - elements_and_overhead as usize;
@ -580,7 +579,7 @@ mod codec_tests {
} }
if progress && symbol_count % 100 == 0 { if progress && symbol_count % 100 == 0 {
println!("[repair] Completed {} symbols", symbol_count) println!("[repair] Completed {symbol_count} symbols")
} }
}) })
} }

@ -217,7 +217,7 @@ impl SourceBlockEncoder {
// Divide the block into sub-blocks and then concatenate the sub-symbols into symbols // Divide the block into sub-blocks and then concatenate the sub-symbols into symbols
// See second to last paragraph in section 4.4.1.2. // See second to last paragraph in section 4.4.1.2.
let mut offset = 0; let mut offset = 0;
for sub_block in 0..(nl + ns) as u32 { for sub_block in 0..(nl + ns) {
let bytes = if sub_block < nl { let bytes = if sub_block < nl {
tl as usize * config.symbol_alignment() as usize tl as usize * config.symbol_alignment() as usize
} else { } else {
@ -352,7 +352,7 @@ fn create_d(
D.push(symbol.clone()); D.push(symbol.clone());
} }
// Extend the source block with padding. See section 5.3.2 // Extend the source block with padding. See section 5.3.2
for _ in 0..(extended_source_symbols as usize - source_block.len()) { for _ in 0..(extended_source_symbols - source_block.len()) {
D.push(Symbol::zero(symbol_size)); D.push(Symbol::zero(symbol_size));
} }
assert_eq!(D.len(), L as usize); assert_eq!(D.len(), L as usize);
@ -589,7 +589,7 @@ mod tests {
let encoder = Encoder::with_defaults(&data, packet_size); let encoder = Encoder::with_defaults(&data, packet_size);
fn accumulate_data(acc: Vec<u8>, packet: EncodingPacket) -> Vec<u8> { fn accumulate_data(acc: Vec<u8>, packet: EncodingPacket) -> Vec<u8> {
let mut updated_acc = acc.clone(); let mut updated_acc = acc;
updated_acc.extend_from_slice(packet.data()); updated_acc.extend_from_slice(packet.data());
updated_acc updated_acc
} }

@ -72,8 +72,7 @@ impl ConnectedComponentGraph {
if connected_component == NO_CONNECTED_COMPONENT as usize { if connected_component == NO_CONNECTED_COMPONENT as usize {
return; return;
} }
self.connected_component_size self.connected_component_size.decrement(connected_component);
.decrement(connected_component as usize);
self.node_connected_component self.node_connected_component
.insert(node, NO_CONNECTED_COMPONENT); .insert(node, NO_CONNECTED_COMPONENT);
} }
@ -86,7 +85,7 @@ impl ConnectedComponentGraph {
let mut max_size = 0; let mut max_size = 0;
let mut largest_connected_component = NO_CONNECTED_COMPONENT as usize; let mut largest_connected_component = NO_CONNECTED_COMPONENT as usize;
for i in 1..=self.num_connected_components { for i in 1..=self.num_connected_components {
let size = self.connected_component_size.get(i as usize); let size = self.connected_component_size.get(i);
if size > max_size { if size > max_size {
max_size = size; max_size = size;
largest_connected_component = i; largest_connected_component = i;
@ -135,11 +134,11 @@ impl ConnectedComponentGraph {
// Merge into the lowest to keep chains short // Merge into the lowest to keep chains short
let merge_to = min(connected_component1, connected_component2); let merge_to = min(connected_component1, connected_component2);
let merge_from = max(connected_component1, connected_component2); let merge_from = max(connected_component1, connected_component2);
let to_size = self.connected_component_size.get(merge_to as usize); let to_size = self.connected_component_size.get(merge_to);
let from_size = self.connected_component_size.get(merge_from as usize); let from_size = self.connected_component_size.get(merge_from);
self.connected_component_size.insert(merge_from as usize, 0); self.connected_component_size.insert(merge_from, 0);
self.connected_component_size self.connected_component_size
.insert(merge_to as usize, to_size + from_size); .insert(merge_to, to_size + from_size);
self.merged_connected_components self.merged_connected_components
.insert(merge_from, merge_to as u16); .insert(merge_from, merge_to as u16);
} }

@ -347,9 +347,7 @@ mod tests {
assert_eq!( assert_eq!(
matrix1.get(i, j), matrix1.get(i, j),
matrix2.get(i, j), matrix2.get(i, j),
"Matrices are not equal at row={} col={}", "Matrices are not equal at row={i} col={j}"
i,
j
); );
} }
} }

@ -328,7 +328,7 @@ impl FirstPhaseRowSelectionStats {
.get_node_in_largest_connected_component(self.start_col, self.end_col); .get_node_in_largest_connected_component(self.start_col, self.end_col);
// Find a row with two ones in the given column // Find a row with two ones in the given column
for row in matrix.get_ones_in_column(node as usize, start_row, end_row) { for row in matrix.get_ones_in_column(node, start_row, end_row) {
let row = row as usize; let row = row as usize;
if self.ones_per_row.get(row) == 2 { if self.ones_per_row.get(row) == 2 {
return row; return row;
@ -400,7 +400,7 @@ impl FirstPhaseRowSelectionStats {
} }
} }
if r == None { if r.is_none() {
return (None, None); return (None, None);
} }
@ -688,9 +688,7 @@ impl<T: BinaryMatrix> IntermediateSymbolDecoder<T> {
&self.A, &self.A,
); );
if r == None { r?;
return None;
}
let r = r.unwrap(); let r = r.unwrap();
let chosen_row = chosen_row.unwrap(); let chosen_row = chosen_row.unwrap();
assert!(chosen_row >= self.i); assert!(chosen_row >= self.i);