diff --git a/src/function.rs b/src/function.rs index 9b0223b..a3c3af9 100644 --- a/src/function.rs +++ b/src/function.rs @@ -604,7 +604,6 @@ mod tests { do_extrema: false, do_roots: false, plot_width: pixel_width, - ..crate::egui_app::AppSettings::default() } } diff --git a/src/hashmap_helper.rs b/src/hashmap_helper.rs index 7239f8a..df1d6a5 100644 --- a/src/hashmap_helper.rs +++ b/src/hashmap_helper.rs @@ -5,14 +5,12 @@ pub fn compile_hashmap(data: Vec) -> Vec<(String, String)> { let start = std::time::Instant::now(); println!("compile_hashmap"); - let functions_processed: Vec = data.iter().map(|e| e.to_string() + "(").collect(); - let mut seen = HashSet::new(); - let tuple_list_1: Vec<(String, String)> = functions_processed - .into_iter() - .map(|func| all_possible_splits(func, &mut seen)) - .flatten() + let tuple_list_1: Vec<(String, String)> = data + .iter() + .map(|e| e.to_string() + "(") + .flat_map(|func| all_possible_splits(func, &mut seen)) .collect(); let keys: Vec<&String> = tuple_list_1.iter().map(|(a, _)| a).collect(); @@ -48,22 +46,20 @@ pub fn compile_hashmap(data: Vec) -> Vec<(String, String)> { fn all_possible_splits( func: String, seen: &mut HashSet<(String, String)>, ) -> Vec<(String, String)> { - return (1..func.len()) + (1..func.len()) .map(|i| { let (first, last) = func.split_at(i); - return (first.to_string(), last.to_string()); + (first.to_string(), last.to_string()) }) - .map(|(first, last)| { + .flat_map(|(first, last)| { if seen.contains(&(first.clone(), last.clone())) { return None; } seen.insert((first.to_string(), last.to_string())); - return Some((first.to_string(), last.to_string())); + Some((first, last)) }) - .filter(|a| a.is_some()) - .map(|a| a.unwrap()) - .collect::>(); + .collect::>() } #[cfg(test)] diff --git a/src/misc.rs b/src/misc.rs index 1a58dff..1cef17a 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -6,7 +6,7 @@ use serde_json::Value as JsonValue; use rayon::prelude::*; #[cfg(not(threading))] -pub fn dyn_iter<'a, T>(input: &'a Vec) -> impl Iterator +pub fn dyn_iter<'a, T>(input: &'a [T]) -> impl Iterator where &'a [T]: IntoIterator, { @@ -22,7 +22,7 @@ where } #[cfg(not(threading))] -pub fn dyn_mut_iter<'a, T>(input: &'a mut Vec) -> impl Iterator +pub fn dyn_mut_iter<'a, T>(input: &'a mut [T]) -> impl Iterator where &'a mut [T]: IntoIterator, { @@ -252,7 +252,7 @@ pub fn decimal_round(x: f64, n: usize) -> f64 { /// `f_1` is f'(x) aka the derivative of f(x) /// The function returns a Vector of `x` values where roots occur pub fn newtons_method_helper( - threshold: &f64, range: &std::ops::Range, data: &Vec, f: &dyn Fn(f64) -> f64, + threshold: &f64, range: &std::ops::Range, data: &[EguiValue], f: &dyn Fn(f64) -> f64, f_1: &dyn Fn(f64) -> f64, ) -> Vec { data.iter() @@ -277,7 +277,7 @@ fn newtons_method( let mut x2: f64; let mut fail: bool = false; loop { - x2 = &x1 - (f(x1) / f_1(x1)); + x2 = x1 - (f(x1) / f_1(x1)); if !range.contains(&x2) { fail = true; break; diff --git a/src/suggestions.rs b/src/suggestions.rs index e76e575..8569484 100644 --- a/src/suggestions.rs +++ b/src/suggestions.rs @@ -64,12 +64,7 @@ impl HintEnum<'static> { } } - pub fn is_multi(&self) -> bool { - match self { - HintEnum::Many(_) => true, - _ => false, - } - } + pub fn is_multi(&self) -> bool { matches!(self, HintEnum::Many(_)) } pub fn ensure_many(&self) -> &[&str] { match self { @@ -77,12 +72,7 @@ impl HintEnum<'static> { _ => panic!("ensure_many called on non-Many value"), } } - pub fn is_some(&self) -> bool { - match self { - HintEnum::None => false, - _ => true, - } - } + pub fn is_some(&self) -> bool { !matches!(self, HintEnum::None) } pub fn is_none(&self) -> bool { !self.is_some() }