ran cargo clippy

This commit is contained in:
Fabian Schmidt 2024-08-30 10:09:39 +02:00
parent 212e595a7e
commit dfcc8562e6
5 changed files with 16 additions and 18 deletions

View File

@ -105,7 +105,7 @@ impl Citymap {
}
}
pub fn into_key_values(self) -> Vec<(String, City)> {
self.map.into_iter().map(|(_, s)| s).collect()
self.map.into_values().collect()
}
pub fn merge_with(&mut self, rhs: Self) {
for (k, v) in rhs.map.into_iter() {
@ -125,7 +125,7 @@ pub fn run() {
let start = Instant::now();
let input = "../../../measurements.txt";
let results = if args.find(|e| e == "st").is_some() {
let results = if args.any(|e| e == "st") {
citymap_single_thread(input)
} else {
citymap_multi_threaded(input)
@ -159,7 +159,6 @@ fn citymap_multi_threaded(path: &str) -> Citymap {
threads.push(citymap_thread(path.to_owned(), range, i, sender.clone()));
}
let mut ranges = (0..cpus)
.into_iter()
.map(|_| receiver.recv().unwrap())
.collect::<Vec<_>>();
ranges.sort_unstable_by_key(|e| e.start);
@ -171,7 +170,7 @@ fn citymap_multi_threaded(path: &str) -> Citymap {
}),
"Ranges overlap or have gaps: {ranges:?}"
);
let results = threads
threads
.into_iter()
.map(|e| e.join().unwrap())
//.map(|e|dbg!(e))
@ -179,8 +178,7 @@ fn citymap_multi_threaded(path: &str) -> Citymap {
left.merge_with(right);
left
})
.unwrap();
results
.unwrap()
}
fn citymap_thread(
@ -204,7 +202,7 @@ fn citymap_thread(
head.truncate(len);
for (i, &pos) in head.iter().enumerate() {
if pos == '\n' as u8 {
if pos == b'\n' {
range.start += i as u64;
break;
}
@ -218,7 +216,7 @@ fn citymap_thread(
head.truncate(len);
for (i, &pos) in head.iter().enumerate() {
if pos == '\n' as u8 {
if pos == b'\n' {
range.end += i as u64;
break;
}
@ -249,7 +247,7 @@ fn citymap_naive(input: &mut impl BufRead) -> Citymap {
}
// Skip over just newline strings that get created by the alignment process
if buf == &[b'\n'] {
if buf == b"\n" {
continue;
}

View File

@ -14,7 +14,7 @@ pub fn run() {
let file = File::open(FILE_PATH).expect("File measurements.txt not found");
let mmap = unsafe { MmapOptions::new().map(&file).unwrap() };
let file_length = mmap.len();
let hasher = FxBuildHasher::default();
let hasher = FxBuildHasher;
let mut stations: HashMap<u64, (String, StationMeasurements)> =
HashMap::with_capacity_and_hasher(DEFAULT_HASHMAP_LENGTH, hasher);
let (tx, rx) = mpsc::channel();
@ -44,7 +44,7 @@ pub fn run() {
let mut t_stations: HashMap<u64, (String, StationMeasurements)> =
HashMap::with_capacity_and_hasher(DEFAULT_HASHMAP_LENGTH, hasher);
for line in mmap_slice.split(|&byte| byte == b'\n') {
if line.len() == 0 {
if line.is_empty() {
break;
}
let (station, temp) = line.rsplit_once(|&byte| byte == b';').unwrap();

View File

@ -16,7 +16,7 @@ pub fn run() {
let file = File::open(FILE_PATH).expect("File structured_measurements.txt not found");
let mmap = unsafe { MmapOptions::new().map(&file).unwrap() };
let file_length = mmap.len();
let hasher = FxBuildHasher::default();
let hasher = FxBuildHasher;
let mut stations: FxHashMap<String, StationMeasurements> =
FxHashMap::with_capacity_and_hasher(DEFAULT_HASHMAP_LENGTH, hasher);
let (tx, rx) = mpsc::channel();

View File

@ -115,7 +115,7 @@ fn merge_hashmaps<'a>(
}
/// Parses a chunk of the input as StationData values.
fn process_chunk<'a>(current_chunk_slice: &'a [u8]) -> HashMap<&'a [u8], StationData> {
fn process_chunk(current_chunk_slice: &[u8]) -> HashMap<&[u8], StationData> {
let mut station_map: HashMap<&[u8], StationData> = HashMap::with_capacity(MAX_STATIONS);
let mut start = 0;
while let Some(end) = current_chunk_slice[start..]
@ -187,7 +187,7 @@ fn write_output_to_stdout(station_map: HashMap<&[u8], StationData>) -> io::Resul
pub fn run() -> io::Result<()> {
// won't accept non-utf-8 args
let args: Vec<String> = env::args().collect();
let file_name = match args.get(2).clone() {
let file_name = match args.get(2) {
Some(fname) => fname,
None => "../../../measurements.txt",
};

View File

@ -50,7 +50,7 @@ impl State {
fn make_map<'a>(i: impl Iterator<Item = &'a [u8]>) -> HashMap<&'a BStr, State> {
let mut state: HashMap<&'a BStr, State> = Default::default();
for line in i {
let (name, value) = line.split_once_str(&[b';']).unwrap();
let (name, value) = line.split_once_str(b";").unwrap();
let value = fast_float::parse(value).unwrap();
state.entry(name.into()).or_default().update(value);
}
@ -58,7 +58,7 @@ fn make_map<'a>(i: impl Iterator<Item = &'a [u8]>) -> HashMap<&'a BStr, State> {
}
fn solve_for_part((start, end): (usize, usize), mem: &[u8]) -> HashMap<&BStr, State> {
make_map((&mem[start..end]).lines())
make_map((mem[start..end]).lines())
}
fn merge<'a>(a: &mut HashMap<&'a BStr, State>, b: &HashMap<&'a BStr, State>) {
@ -70,7 +70,7 @@ fn merge<'a>(a: &mut HashMap<&'a BStr, State>, b: &HashMap<&'a BStr, State>) {
pub fn run() {
let now = Instant::now();
let cores: usize = std::thread::available_parallelism().unwrap().into();
let path = match std::env::args().skip(1).next() {
let path = match std::env::args().nth(1) {
Some(path) => path,
None => "../../../measurements.txt".to_owned(),
};
@ -104,7 +104,7 @@ pub fn run() {
});
let mut all: Vec<_> = state.into_iter().collect();
all.sort_unstable_by(|a, b| a.0.cmp(&b.0));
all.sort_unstable_by(|a, b| a.0.cmp(b.0));
#[cfg(feature = "json")]
{
print!("[");