From be37a4ed4059ce79321c5e3f2438934866ec7be5 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Fri, 19 Jan 2024 20:14:57 +0100 Subject: add function_cache for performence gain --- src/math/complex.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/math/complex.rs') 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(&self, state: &mut H) { + format!("{}#{}", self.real, self.imag).hash(state); + state.finish(); + } +} + +impl Eq for Complex {} + #[derive(Debug)] pub struct ComplexParseError; -- cgit v1.2.3-70-g09d2