mirror of https://github.com/zcash/halo2.git
Implement Ord and PartialOrd for Field
This commit is contained in:
parent
07e2d390a9
commit
1e21c08acd
|
@ -36,6 +36,8 @@ pub trait Field:
|
|||
+ for<'a> SubAssign<&'a Self>
|
||||
+ PartialEq
|
||||
+ Eq
|
||||
+ PartialOrd
|
||||
+ Ord
|
||||
+ ConditionallySelectable
|
||||
+ ConstantTimeEq
|
||||
+ Group<Scalar = Self>
|
||||
|
|
|
@ -62,6 +62,28 @@ impl PartialEq for Fp {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::cmp::Ord for Fp {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
let left = self.to_bytes();
|
||||
let right = other.to_bytes();
|
||||
for (left_byte, right_byte) in left.iter().zip(right.iter()).rev() {
|
||||
let tmp = left_byte.cmp(right_byte);
|
||||
if let std::cmp::Ordering::Equal = tmp {
|
||||
continue;
|
||||
} else {
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
std::cmp::Ordering::Equal
|
||||
}
|
||||
}
|
||||
|
||||
impl std::cmp::PartialOrd for Fp {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl ConditionallySelectable for Fp {
|
||||
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
|
||||
Fp([
|
||||
|
|
|
@ -62,6 +62,28 @@ impl PartialEq for Fq {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::cmp::Ord for Fq {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
let left = self.to_bytes();
|
||||
let right = other.to_bytes();
|
||||
for (left_byte, right_byte) in left.iter().zip(right.iter()).rev() {
|
||||
let tmp = left_byte.cmp(right_byte);
|
||||
if let std::cmp::Ordering::Equal = tmp {
|
||||
continue;
|
||||
} else {
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
std::cmp::Ordering::Equal
|
||||
}
|
||||
}
|
||||
|
||||
impl std::cmp::PartialOrd for Fq {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl ConditionallySelectable for Fq {
|
||||
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
|
||||
Fq([
|
||||
|
|
Loading…
Reference in New Issue