More idiomatic implementation of Ord for Field
Co-authored-by: str4d <jack@z.cash>
This commit is contained in:
parent
89fd6e4d44
commit
6f6378b2ea
|
@ -66,15 +66,14 @@ impl std::cmp::Ord for Fp {
|
||||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||||
let left = self.to_bytes();
|
let left = self.to_bytes();
|
||||||
let right = other.to_bytes();
|
let right = other.to_bytes();
|
||||||
for (left_byte, right_byte) in left.iter().zip(right.iter()).rev() {
|
left.iter()
|
||||||
let tmp = left_byte.cmp(right_byte);
|
.zip(right.iter())
|
||||||
if let std::cmp::Ordering::Equal = tmp {
|
.rev()
|
||||||
continue;
|
.find_map(|(left_byte, right_byte)| match left_byte.cmp(right_byte) {
|
||||||
} else {
|
std::cmp::Ordering::Equal => None,
|
||||||
return tmp;
|
res => Some(res),
|
||||||
}
|
})
|
||||||
}
|
.unwrap_or(std::cmp::Ordering::Equal)
|
||||||
std::cmp::Ordering::Equal
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,15 +66,14 @@ impl std::cmp::Ord for Fq {
|
||||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||||
let left = self.to_bytes();
|
let left = self.to_bytes();
|
||||||
let right = other.to_bytes();
|
let right = other.to_bytes();
|
||||||
for (left_byte, right_byte) in left.iter().zip(right.iter()).rev() {
|
left.iter()
|
||||||
let tmp = left_byte.cmp(right_byte);
|
.zip(right.iter())
|
||||||
if let std::cmp::Ordering::Equal = tmp {
|
.rev()
|
||||||
continue;
|
.find_map(|(left_byte, right_byte)| match left_byte.cmp(right_byte) {
|
||||||
} else {
|
std::cmp::Ordering::Equal => None,
|
||||||
return tmp;
|
res => Some(res),
|
||||||
}
|
})
|
||||||
}
|
.unwrap_or(std::cmp::Ordering::Equal)
|
||||||
std::cmp::Ordering::Equal
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue