diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-01-19 20:14:57 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-01-19 20:14:57 +0100 |
| commit | be37a4ed4059ce79321c5e3f2438934866ec7be5 (patch) | |
| tree | 9ab9ece4b21bd805e614743420896dafe9f794dd /src/math/complex.rs | |
| parent | 1c5233b185e52d42c7878ac8b6cf046a5bb54a09 (diff) | |
add function_cache for performence gain
Diffstat (limited to 'src/math/complex.rs')
| -rw-r--r-- | src/math/complex.rs | 16 |
1 files changed, 16 insertions, 0 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; |