Skip to content

Commit

Permalink
online-phase: algebra: scalar: Implement Ord, PartialOrd
Browse files Browse the repository at this point in the history
  • Loading branch information
joeykraut committed Nov 4, 2024
1 parent a7c1185 commit 39593e0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions online-phase/src/algebra/scalar/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// ----------------------------

use std::{
cmp::Ordering,
fmt::{Display, Formatter, Result as FmtResult},
iter::{Product, Sum},
ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign},
Expand Down Expand Up @@ -698,6 +699,12 @@ impl<C: CurveGroup> From<BigUint> for Scalar<C> {
}
}

impl<C: CurveGroup> From<Scalar<C>> for BigUint {
fn from(value: Scalar<C>) -> Self {
value.0.into()
}
}

// -------------------
// | Iterator Traits |
// -------------------
Expand Down Expand Up @@ -729,6 +736,18 @@ impl<C: CurveGroup> Product for ScalarResult<C> {
}
}

impl<C: CurveGroup> PartialOrd for Scalar<C> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl<C: CurveGroup> Ord for Scalar<C> {
fn cmp(&self, other: &Self) -> Ordering {
self.0.cmp(&other.0)
}
}

#[cfg(test)]
mod test {
use crate::{
Expand Down

0 comments on commit 39593e0

Please sign in to comment.