This commit is contained in:
Simon Gardling 2022-03-31 14:43:35 -04:00
parent 92e8da6198
commit dc53889dd5
4 changed files with 15 additions and 30 deletions

View File

@ -604,7 +604,6 @@ mod tests {
do_extrema: false, do_extrema: false,
do_roots: false, do_roots: false,
plot_width: pixel_width, plot_width: pixel_width,
..crate::egui_app::AppSettings::default()
} }
} }

View File

@ -5,14 +5,12 @@ pub fn compile_hashmap(data: Vec<String>) -> Vec<(String, String)> {
let start = std::time::Instant::now(); let start = std::time::Instant::now();
println!("compile_hashmap"); println!("compile_hashmap");
let functions_processed: Vec<String> = data.iter().map(|e| e.to_string() + "(").collect();
let mut seen = HashSet::new(); let mut seen = HashSet::new();
let tuple_list_1: Vec<(String, String)> = functions_processed let tuple_list_1: Vec<(String, String)> = data
.into_iter() .iter()
.map(|func| all_possible_splits(func, &mut seen)) .map(|e| e.to_string() + "(")
.flatten() .flat_map(|func| all_possible_splits(func, &mut seen))
.collect(); .collect();
let keys: Vec<&String> = tuple_list_1.iter().map(|(a, _)| a).collect(); let keys: Vec<&String> = tuple_list_1.iter().map(|(a, _)| a).collect();
@ -48,22 +46,20 @@ pub fn compile_hashmap(data: Vec<String>) -> Vec<(String, String)> {
fn all_possible_splits( fn all_possible_splits(
func: String, seen: &mut HashSet<(String, String)>, func: String, seen: &mut HashSet<(String, String)>,
) -> Vec<(String, String)> { ) -> Vec<(String, String)> {
return (1..func.len()) (1..func.len())
.map(|i| { .map(|i| {
let (first, last) = func.split_at(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())) { if seen.contains(&(first.clone(), last.clone())) {
return None; return None;
} }
seen.insert((first.to_string(), last.to_string())); seen.insert((first.to_string(), last.to_string()));
return Some((first.to_string(), last.to_string())); Some((first, last))
}) })
.filter(|a| a.is_some()) .collect::<Vec<(String, String)>>()
.map(|a| a.unwrap())
.collect::<Vec<(String, String)>>();
} }
#[cfg(test)] #[cfg(test)]

View File

@ -6,7 +6,7 @@ use serde_json::Value as JsonValue;
use rayon::prelude::*; use rayon::prelude::*;
#[cfg(not(threading))] #[cfg(not(threading))]
pub fn dyn_iter<'a, T>(input: &'a Vec<T>) -> impl Iterator<Item = &'a T> pub fn dyn_iter<'a, T>(input: &'a [T]) -> impl Iterator<Item = &'a T>
where where
&'a [T]: IntoIterator, &'a [T]: IntoIterator,
{ {
@ -22,7 +22,7 @@ where
} }
#[cfg(not(threading))] #[cfg(not(threading))]
pub fn dyn_mut_iter<'a, T>(input: &'a mut Vec<T>) -> impl Iterator<Item = &'a mut T> pub fn dyn_mut_iter<'a, T>(input: &'a mut [T]) -> impl Iterator<Item = &'a mut T>
where where
&'a mut [T]: IntoIterator, &'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) /// `f_1` is f'(x) aka the derivative of f(x)
/// The function returns a Vector of `x` values where roots occur /// The function returns a Vector of `x` values where roots occur
pub fn newtons_method_helper( pub fn newtons_method_helper(
threshold: &f64, range: &std::ops::Range<f64>, data: &Vec<EguiValue>, f: &dyn Fn(f64) -> f64, threshold: &f64, range: &std::ops::Range<f64>, data: &[EguiValue], f: &dyn Fn(f64) -> f64,
f_1: &dyn Fn(f64) -> f64, f_1: &dyn Fn(f64) -> f64,
) -> Vec<f64> { ) -> Vec<f64> {
data.iter() data.iter()
@ -277,7 +277,7 @@ fn newtons_method(
let mut x2: f64; let mut x2: f64;
let mut fail: bool = false; let mut fail: bool = false;
loop { loop {
x2 = &x1 - (f(x1) / f_1(x1)); x2 = x1 - (f(x1) / f_1(x1));
if !range.contains(&x2) { if !range.contains(&x2) {
fail = true; fail = true;
break; break;

View File

@ -64,12 +64,7 @@ impl HintEnum<'static> {
} }
} }
pub fn is_multi(&self) -> bool { pub fn is_multi(&self) -> bool { matches!(self, HintEnum::Many(_)) }
match self {
HintEnum::Many(_) => true,
_ => false,
}
}
pub fn ensure_many(&self) -> &[&str] { pub fn ensure_many(&self) -> &[&str] {
match self { match self {
@ -77,12 +72,7 @@ impl HintEnum<'static> {
_ => panic!("ensure_many called on non-Many value"), _ => panic!("ensure_many called on non-Many value"),
} }
} }
pub fn is_some(&self) -> bool { pub fn is_some(&self) -> bool { !matches!(self, HintEnum::None) }
match self {
HintEnum::None => false,
_ => true,
}
}
pub fn is_none(&self) -> bool { !self.is_some() } pub fn is_none(&self) -> bool { !self.is_some() }