This commit is contained in:
Simon Gardling
2022-05-04 23:43:50 -04:00
parent 5e5dd0f7a6
commit 243135b3dc
8 changed files with 47 additions and 30 deletions

View File

@@ -6,6 +6,7 @@ use serde_json::Value as JsonValue;
use rayon::prelude::*;
#[cfg(not(threading))]
#[inline]
pub fn dyn_iter<'a, T>(input: &'a [T]) -> impl Iterator<Item = &'a T>
where
&'a [T]: IntoIterator,
@@ -14,6 +15,7 @@ where
}
#[cfg(threading)]
#[inline]
pub fn dyn_iter<'a, I>(input: &'a I) -> <&'a I as IntoParallelIterator>::Iter
where
&'a I: IntoParallelIterator,
@@ -22,6 +24,7 @@ where
}
#[cfg(not(threading))]
#[inline]
pub fn dyn_mut_iter<'a, T>(input: &'a mut [T]) -> impl Iterator<Item = &'a mut T>
where
&'a mut [T]: IntoIterator,
@@ -30,6 +33,7 @@ where
}
#[cfg(threading)]
#[inline]
pub fn dyn_mut_iter<'a, I>(input: &'a mut I) -> <&'a mut I as IntoParallelIterator>::Iter
where
&'a mut I: IntoParallelIterator,
@@ -114,10 +118,10 @@ impl SteppedVector {
}
#[allow(dead_code)]
pub fn get_min(&self) -> f64 { self.min }
pub const fn get_min(&self) -> f64 { self.min }
#[allow(dead_code)]
pub fn get_max(&self) -> f64 { self.max }
pub const fn get_max(&self) -> f64 { self.max }
#[allow(dead_code)]
pub fn get_data(&self) -> Vec<f64> { self.data.clone() }

View File

@@ -34,19 +34,25 @@ impl<'a> const Default for AutoComplete<'a> {
}
impl<'a> AutoComplete<'a> {
#[allow(dead_code)]
pub fn update_string(&mut self, string: &str) {
if self.string != string {
// catch empty strings here to avoid call to `generate_hint` and unnecessary logic
if string.is_empty() {
*self = Self::default();
} else {
self.i = 0;
self.string = string.to_string();
self.hint = generate_hint(string);
self.do_update_logic();
}
}
}
/// Runs update logic assuming that a change to `self.string` has been made
fn do_update_logic(&mut self) {
self.i = 0;
self.hint = generate_hint(&self.string);
}
pub fn register_movement(&mut self, movement: &Movement) {
if movement == &Movement::None {
return;
@@ -90,8 +96,8 @@ impl<'a> AutoComplete<'a> {
}
pub fn apply_hint(&mut self, hint: &str) {
let new_string = self.string.clone() + hint;
self.update_string(&new_string);
self.string.push_str(hint);
self.do_update_logic();
}
}