Fix wrong implementation of hash_complex

This commit is contained in:
Gyubong Lee committed 2022-07-25 18:07:10 +09:00
1 parent 3c0f3cacdd
commit 6098eb66ed
2 files changed
+15 -10

No files matched your search

+14 -4
View File
@@ -141,11 +141,21 @@ pub fn hash_float(value: f64) -> Option<PyHash> {
}
#[inline]
pub fn hash_complex(value: &Complex64) -> Option<PyHash> {
let re_hash = hash_float(value.re)?;
let im_hash = hash_float(value.im)?;
pub fn hash_complex(value: &Complex64) -> PyHash {
let re_hash = (match hash_float(value.re) {
Some(value) => Some(value),
None => Some(hash_pointer(value as *const _ as *const std::ffi::c_void)),
})
.unwrap();
let im_hash = (match hash_float(value.im) {
Some(value) => Some(value),
None => Some(hash_pointer(value as *const _ as *const std::ffi::c_void)),
})
.unwrap();
let Wrapping(ret) = Wrapping(re_hash) + Wrapping(im_hash) * Wrapping(IMAG);
Some(fix_sentinel(ret))
fix_sentinel(ret)
}
pub fn hash_iter_unordered<'a, T: 'a, I, F, E>(iter: I, hashf: F) -> Result<PyHash, E>
+1 -6
View File
@@ -417,12 +417,7 @@ impl Comparable for PyComplex {
impl Hashable for PyComplex {
#[inline]
fn hash(zelf: &crate::Py<Self>, _vm: &VirtualMachine) -> PyResult<hash::PyHash> {
match hash::hash_complex(&zelf.value) {
Some(value) => Ok(value),
None => Ok(hash::hash_pointer(
zelf as *const _ as *const std::ffi::c_void,
)),
}
Ok(hash::hash_complex(&zelf.value))
}
}