aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
Diffstat (limited to 'src/math')
-rw-r--r--src/math/complex.rs16
-rw-r--r--src/math/expression.rs3
-rw-r--r--src/math/function.rs2
-rw-r--r--src/math/operation.rs2
4 files changed, 21 insertions, 2 deletions
diff --git a/src/math/complex.rs b/src/math/complex.rs
index 5b95df4..4d85155 100644
--- a/src/math/complex.rs
+++ b/src/math/complex.rs
@@ -1,4 +1,5 @@
use std::f64::consts::E;
+use std::hash::Hash;
use std::num::ParseFloatError;
use std::str::FromStr;
@@ -75,6 +76,21 @@ impl std::fmt::Display for Complex {
}
}
+impl PartialEq for Complex {
+ fn eq(&self, other: &Self) -> bool {
+ self.real == other.real && self.imag == other.imag
+ }
+}
+
+impl Hash for Complex {
+ fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
+ format!("{}#{}", self.real, self.imag).hash(state);
+ state.finish();
+ }
+}
+
+impl Eq for Complex {}
+
#[derive(Debug)]
pub struct ComplexParseError;
diff --git a/src/math/expression.rs b/src/math/expression.rs
index 049886d..14a3eb8 100644
--- a/src/math/expression.rs
+++ b/src/math/expression.rs
@@ -4,6 +4,7 @@ use super::function::FunctionArgument;
use super::string::{ContainsAndSkipBrackets, SplitMatchingBracket};
use super::operation::Operation;
+#[derive(PartialEq, Eq, Hash, Clone)]
enum ExpressionType {
Value(Complex),
Variable(String),
@@ -17,7 +18,7 @@ impl Default for ExpressionType {
}
}
-#[derive(Default)]
+#[derive(Default, PartialEq, Eq, Hash, Clone)]
pub struct Expression {
expr_type: ExpressionType,
repr: String,
diff --git a/src/math/function.rs b/src/math/function.rs
index 93d288c..700bee1 100644
--- a/src/math/function.rs
+++ b/src/math/function.rs
@@ -1,11 +1,13 @@
use super::expression::Expression;
use super::{complex::Complex, context::Context};
+#[derive(PartialEq, Eq, Hash, Clone)]
enum FunctionArgumentType {
ExpressionArgument(Vec<Expression>),
ValueArgument(Vec<Complex>),
}
+#[derive(PartialEq, Eq, Hash, Clone)]
pub struct FunctionArgument {
args: FunctionArgumentType,
len: usize,
diff --git a/src/math/operation.rs b/src/math/operation.rs
index bcf6510..e54a2d1 100644
--- a/src/math/operation.rs
+++ b/src/math/operation.rs
@@ -2,7 +2,7 @@ use crate::math::complex::Complex;
pub type Operator = fn(Complex, Complex) -> Complex;
-#[derive(Clone)]
+#[derive(Clone, PartialEq, Eq, Hash)]
pub struct Operation {
sign: char,
func: Operator