diff --git a/Cargo.toml b/Cargo.toml index 278656f..63d692b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ uuid = { version = "1", features = ["v4", "fast-rng", "js"] } bincode = "1.3" serde = "1" base64 = { git = "https://github.com/marshallpierce/rust-base64.git" } -byte-unit = "4.0.14" +byte-unit = { version = "4", default-features = false } [dev-dependencies] benchmarks = { path = "./benchmarks" } diff --git a/parsing/src/lib.rs b/parsing/src/lib.rs index fa75d1e..e1af03c 100644 --- a/parsing/src/lib.rs +++ b/parsing/src/lib.rs @@ -2,7 +2,7 @@ #![feature(core_intrinsics)] #![feature(const_default_impls)] #![feature(const_mut_refs)] - +#![feature(const_for)] mod autocomplete; mod autocomplete_hashmap; mod parsing; diff --git a/parsing/src/suggestions.rs b/parsing/src/suggestions.rs index 40f0664..15be53e 100644 --- a/parsing/src/suggestions.rs +++ b/parsing/src/suggestions.rs @@ -36,7 +36,7 @@ pub enum SplitType { } pub fn split_function_chars(chars: &[char], split: SplitType) -> Vec { - // catch some basic cases + // Catch some basic cases match chars.len() { 0 => return Vec::new(), 1 => return vec![chars[0].to_string()], @@ -49,10 +49,7 @@ pub fn split_function_chars(chars: &[char], split: SplitType) -> Vec { } // Resulting split-up data - let mut data: Vec = Vec::with_capacity(chars.len()); - - // Need to start out with an empty string - data.push(String::new()); + let mut data: Vec = vec![chars[0].to_string()]; /// Used to store info about a character struct BoolSlice { @@ -85,6 +82,7 @@ pub fn split_function_chars(chars: &[char], split: SplitType) -> Vec { }, } } + const fn is_variable(&self) -> bool { self.variable && !self.masked_var } const fn is_number(&self) -> bool { self.number && !self.masked_num } @@ -108,8 +106,8 @@ pub fn split_function_chars(chars: &[char], split: SplitType) -> Vec { } } - fn splitable(&self, c: &char, other: &BoolSlice, split: &SplitType) -> bool { - if (c == &'*') | ((split == &SplitType::Term) && other.open_parens) { + const fn splitable(&self, c: &char, other: &BoolSlice, split: &SplitType) -> bool { + if (*c == '*') | (matches!(split, &SplitType::Term) && other.open_parens) { return true; } else if other.closing_parens { // Cases like `)x`, `)2`, and `)(` @@ -144,7 +142,6 @@ pub fn split_function_chars(chars: &[char], split: SplitType) -> Vec { let mut prev_char: BoolSlice = BoolSlice::from_char(&chars[0], false, false); let mut last = unsafe { data.last_mut().unwrap_unchecked() }; - last.push(chars[0]); // Iterate through all chars excluding the first one for c in chars.iter().skip(1) { diff --git a/src/function_entry.rs b/src/function_entry.rs index 9e13d1d..64d3dac 100644 --- a/src/function_entry.rs +++ b/src/function_entry.rs @@ -307,6 +307,7 @@ impl FunctionEntry { .iter() .map(|ele| ele.x) .collect::>() + .as_slice() .into(); let back_data: Vec = dyn_iter(&resolution_iter) diff --git a/src/misc.rs b/src/misc.rs index e13cc32..3256e98 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -1,3 +1,5 @@ +use std::intrinsics::assume; + use eframe::egui::plot::{Line, Points, Value as EguiValue, Values}; use itertools::Itertools; @@ -90,7 +92,7 @@ pub struct SteppedVector { impl SteppedVector { /// Returns `Option` with index of element with value `x`. and `None` if `x` does not exist in `data` pub fn get_index(&self, x: &f64) -> Option { - // if `x` is outside range, just go ahead and return `None` as it *shouldn't* be in `data` + // If `x` is outside range, just go ahead and return `None` as it *shouldn't* be in `data` if (x > &self.max) | (&self.min > x) { return None; } @@ -126,37 +128,39 @@ impl SteppedVector { pub fn get_data(&self) -> &Vec { &self.data } } -// Convert `Vec` into [`SteppedVector`] -impl From> for SteppedVector { - fn from(input_data: Vec) -> SteppedVector { - let mut data = input_data; - // length of data - let data_length = data.len(); - +// Convert `&[f64]` into [`SteppedVector`] +impl From<&[f64]> for SteppedVector { + fn from(data: &[f64]) -> SteppedVector { // Ensure data is of correct length - if data_length < 2 { + if data.len() < 2 { panic!("SteppedVector: data should have a length longer than 2"); } - // length of data subtracted by 1 (represents the maximum index value) - let data_i_length = data_length - 1; + unsafe { + assume(data.len() > 2); + assume(!data.is_empty()); + } - let mut max: f64 = data[data_i_length]; // The max value should be the first element - let mut min: f64 = data[0]; // The minimum value should be the last element + // length of data subtracted by 1 (represents the maximum index value) + let max: f64 = data[data.len() - 1]; // The max value should be the first element + let min: f64 = data[0]; // The minimum value should be the last element if min > max { + panic!("SteppedVector: min is larger than max"); + /* tracing::debug!("SteppedVector: min is larger than max, sorting."); data.sort_unstable_by(|a, b| a.partial_cmp(b).unwrap()); max = data[data_i_length]; min = data[0]; + */ } // Calculate the step between elements - let step = (max - min).abs() / (data_length as f64); + let step = (max - min).abs() / (data.len() as f64); // Create and return the struct SteppedVector { - data, + data: data.to_vec(), min, max, step, @@ -316,7 +320,7 @@ pub fn hashed_storage_read(data: String) -> (String, Vec) { #[allow(dead_code)] pub fn format_bytes(bytes: usize) -> String { - byte_unit::Byte::from_bytes(bytes as u128) + byte_unit::Byte::from_bytes(bytes as u64) .get_appropriate_unit(false) .to_string() } diff --git a/tests/misc.rs b/tests/misc.rs index b858dd9..337aebf 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -7,7 +7,7 @@ fn stepped_vector() { let max: i32 = 1000; let data: Vec = (min..=max).map(|x| x as f64).collect(); let len_data = data.len(); - let stepped_vector: SteppedVector = data.into(); + let stepped_vector: SteppedVector = data.as_slice().into(); assert_eq!(stepped_vector.get_min(), min as f64); assert_eq!(stepped_vector.get_max(), max as f64);