refactor: make update_url_scores and normalize_string functions private

This commit is contained in:
Alex Wellnitz 2024-02-13 08:36:32 +01:00
parent c0cbb11b3e
commit d510178127

View File

@ -1,13 +1,13 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::f64; use std::f64;
pub fn update_url_scores(old: &mut HashMap<String, f64>, new: &HashMap<String, f64>) { fn update_url_scores(old: &mut HashMap<String, f64>, new: &HashMap<String, f64>) {
for (url, score) in new { for (url, score) in new {
old.entry(url.to_string()).and_modify(|e| *e += score).or_insert(*score); old.entry(url.to_string()).and_modify(|e| *e += score).or_insert(*score);
} }
} }
pub fn normalize_string(input_string: &str) -> String { fn normalize_string(input_string: &str) -> String {
let string_without_punc: String = input_string.chars().filter(|&c| !c.is_ascii_punctuation()).collect(); let string_without_punc: String = input_string.chars().filter(|&c| !c.is_ascii_punctuation()).collect();
let string_without_double_spaces: String = string_without_punc.split_whitespace().collect::<Vec<&str>>().join(" "); let string_without_double_spaces: String = string_without_punc.split_whitespace().collect::<Vec<&str>>().join(" ");
string_without_double_spaces.to_lowercase() string_without_double_spaces.to_lowercase()