Skip to content

Commit

Permalink
Improvement: Update crates and code according to clippy standards
Browse files Browse the repository at this point in the history
  • Loading branch information
joshleaves committed Oct 21, 2024
1 parent 84c8c5e commit 2ff8e13
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Of note:
- The changelog 2015.5.2 has been rewritten from each commit content.
- This file may be amended entirely in the future to adhere to the [GNU Changelog style](https://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html#Style-of-Change-Logs)

## [2018.6.2]
### Changed
- Updated dependencies, changed all `ToString` implementations to `fmt::Display`, and other clippy improvements

## [2018.6.1]
### Added
- Solved [exercice for 2018, day 06](src/year_2018/06.rs).
Expand Down
20 changes: 12 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[package]
name = "advent-rs"
version = "2018.6.1"
version = "2018.6.2"
edition = "2021"
authors = ["Arnaud 'red' Rouyer"]
readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]]
name = "advent-rs"
path = "src/main.rs"
Expand All @@ -26,17 +26,21 @@ opt-level = 2

[profile.release]
opt-level = 3
strip = true # Strip symbols
panic = "abort" # Abort on panic
# lto = true # Enable Link Time Optimization
# codegen-units = 1 # Reduce number of codegen units to increase optimizations.

[dependencies]
clap = { version = "4.5.1", features = ["derive"] }
itertools = "0.12.1"
clap = { version = "4.5.20", features = ["derive"] }
itertools = "0.13.0"
md-5 = "0.10.6"
mutants = "0.0.3"

[dev-dependencies]
assert_cmd = "2.0.13"
predicates = "3.1.0"
assert_cmd = "2.0.16"
predicates = "3.1.2"
criterion = { version = "0.5.1", features = ["html_reports"] }
mutants = "0.0.3"

[[bench]]
name = "year_2015"
Expand Down
2 changes: 1 addition & 1 deletion benches/year_2017_day_04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn day_04_v1_naive(input: impl Into<String>) -> u16 {
line
.split_whitespace()
.sorted()
.group_by(|word| *word)
.chunk_by(|word| *word)
.into_iter()
.all(|(_word, group)| group.count() == 1)
})
Expand Down
2 changes: 1 addition & 1 deletion src/year_2015/day_04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn find_hash(input: &str, stop_value: u8) -> u32 {
(0..=u32::MAX)
.find(|counter| {
let mut hasher = md5.clone();
hasher.update(&counter.to_string());
hasher.update(counter.to_string());
let hash = hasher.finalize();
hash[0] == 0 && hash[1] == 0 && hash[2] < stop_value
})
Expand Down
23 changes: 11 additions & 12 deletions src/year_2015/day_18.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Advent of Code 2015: Day 18: Like a GIF For Your Yard
use std::fmt;

type Light = bool;
const LIGHT_ON: Light = true;
Expand Down Expand Up @@ -127,20 +128,18 @@ impl GameOfLifeGrid {
}
}

impl ToString for GameOfLifeGrid {
fn to_string(&self) -> String {
let mut data: String = String::new();
impl fmt::Display for GameOfLifeGrid {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for row in 0..self.size {
let row_str = self.data[row]
.iter()
.map(|c| if *c == LIGHT_ON { "#" } else { "." })
.collect::<Vec<&str>>()
.join("");
data.push_str(&row_str);
data.push('\n');
for col in 0..self.size {
match self.data[row][col] {
LIGHT_ON => write!(f, "#")?,
LIGHT_OFF => write!(f, ".")?,
}
}
writeln!(f)?;
}

data
Ok(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/year_2016/day_06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
let (next_char, _) = row
.iter()
.sorted()
.group_by(|&x| x)
.chunk_by(|&x| x)
.into_iter()
.map(|(key, group)| (key, group.count()))
.max_by(&sort_closure)
Expand Down
4 changes: 2 additions & 2 deletions src/year_2016/day_14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn fill_hashes_v2(md5: &CoreWrapper<Md5Core>, start: usize, end: usize) -> VecDe
let mut hashes: VecDeque<String> = VecDeque::new();
for idx in start..=end {
let mut md5_num = md5.clone();
md5_num.update(&idx.to_string());
md5_num.update(idx.to_string());
let md5_str = Md5::new();
hashes.push_back(multi_hash(&md5_str, &format!("{:x}", md5_num.finalize())));
}
Expand Down Expand Up @@ -86,7 +86,7 @@ fn fill_hashes(md5: &CoreWrapper<Md5Core>, counter: usize, hashes: usize) -> Vec
let mut hashes: VecDeque<Vec<u8>> = VecDeque::new();
for idx in start..=end {
let mut md5_num = md5.clone();
md5_num.update(&idx.to_string());
md5_num.update(idx.to_string());
hashes.push_back(md5_num.finalize().to_vec());
}

Expand Down
2 changes: 1 addition & 1 deletion src/year_2017/day_07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn day_07_v2(input: impl Into<String>) -> String {
.iter()
.map(|n| tower.size_of(n))
.sorted()
.group_by(|v| *v)
.chunk_by(|v| *v)
.into_iter()
.map(|(key, group)| (key, group.count()))
.sorted_by_key(|elt| elt.1)
Expand Down
7 changes: 4 additions & 3 deletions src/year_2017/day_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ impl DanceFloor {
}
}

impl ToString for DanceFloor {
fn to_string(&self) -> String {
self.input.iter().collect::<String>()
impl std::fmt::Display for DanceFloor {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let string = self.input.iter().collect::<String>();
write!(f, "{}", string)
}
}

Expand Down
21 changes: 13 additions & 8 deletions src/year_2017/day_21.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use itertools::Itertools;
use std::collections::HashMap;
use std::fmt;
use std::hash::Hash;

#[derive(Clone, Eq, Hash, PartialEq)]
Expand Down Expand Up @@ -114,14 +115,18 @@ impl Default for Pattern {
}
}

impl ToString for Pattern {
fn to_string(&self) -> String {
self
.data
.iter()
.map(|row| row.iter().map(|chr| if *chr { "#" } else { "." }).join(""))
.join("\n")
.to_string()
impl fmt::Display for Pattern {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for row in self.data.iter() {
for chr in row.iter() {
match chr {
true => write!(f, "#")?,
false => write!(f, ".")?,
}
}
writeln!(f)?
}
Ok(())
}
}

Expand Down
18 changes: 10 additions & 8 deletions src/year_2017/day_25.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::fmt;
use std::collections::HashMap;

use itertools::Itertools;
Expand Down Expand Up @@ -121,14 +122,15 @@ impl StateMachine {
}
}

impl ToString for StateMachine {
fn to_string(&self) -> String {
self
.tape
.iter()
.sorted()
.map(|(_idx, value)| if *value { "1" } else { "0" })
.join(" ")
impl fmt::Display for StateMachine {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for (_idx, value) in self.tape.iter().sorted() {
match value {
true => write!(f, "1 ")?,
false => write!(f, "0 ")?,
}
}
Ok(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/year_2018/day_02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn day_02_v1(input: impl Into<String>) -> String {
.map(|input| {
let mut two = false;
let mut tre = false;
for (_chr, cnt) in &input.bytes().sorted().group_by(|chr| *chr) {
for (_chr, cnt) in &input.bytes().sorted().chunk_by(|chr| *chr) {
match cnt.count() {
2 => two = true,
3 => tre = true,
Expand Down
10 changes: 5 additions & 5 deletions src/year_2018/day_06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ struct ChronalCoordinates {

impl ChronalCoordinates {
fn new(input: &str) -> Self {
let mut left = std::i32::MAX;
let mut top = std::i32::MAX;
let mut right = std::i32::MIN;
let mut bottom = std::i32::MIN;
let mut left = i32::MAX;
let mut top = i32::MAX;
let mut right = i32::MIN;
let mut bottom = i32::MIN;

let points = input
.lines()
Expand Down Expand Up @@ -54,7 +54,7 @@ impl ChronalCoordinates {

for x in self.left..=self.right {
for y in self.top..=self.bottom {
let mut closest_distance = std::i32::MAX;
let mut closest_distance = i32::MAX;
let mut closest_id = 0;

for (id, point) in self.points.iter() {
Expand Down

0 comments on commit 2ff8e13

Please sign in to comment.