Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement Ord for BaseElement #225

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion math/src/field/f128/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const ELEMENT_BYTES: usize = core::mem::size_of::<u128>();
///
/// Internal values are stored in their canonical form in the range [0, M). The backing type is
/// `u128`.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct BaseElement(u128);
Expand Down
4 changes: 1 addition & 3 deletions math/src/field/f62/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const G: u64 = 4421547261963328785;
///
/// Internal values are stored in Montgomery representation and can be in the range [0; 2M). The
/// backing type is `u64`.
#[derive(Copy, Clone, Debug, Default)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(from = "u64", into = "u64"))]
pub struct BaseElement(u64);
Expand Down Expand Up @@ -251,8 +251,6 @@ impl PartialEq for BaseElement {
}
}

impl Eq for BaseElement {}

// OVERLOADED OPERATORS
// ================================================================================================

Expand Down
4 changes: 1 addition & 3 deletions math/src/field/f64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ELEMENT_BYTES: usize = core::mem::size_of::<u64>();
///
/// Internal values represent x * R mod M where R = 2^64 mod M and x in [0, M).
/// The backing type is `u64` but the internal values are always in the range [0, M).
#[derive(Copy, Clone, Debug, Default)]
#[derive(Copy, Clone, Debug, Default, Eq, PartialOrd, Ord)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think deriving PartialOrd directly relies on lexicographic ordering, which has little meaning when dealing with possibly unreduced elements or in Montgomery form?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any recommendations on how to implement this properly, if at all possible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume comparing reduced elements is the way to go (same as in implementations of PartialEq) though maybe @irakliyk has a different solution?

#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[cfg_attr(feature = "serde", serde(from = "u64", into = "u64"))]
pub struct BaseElement(u64);
Expand Down Expand Up @@ -312,8 +312,6 @@ impl PartialEq for BaseElement {
}
}

impl Eq for BaseElement {}

// OVERLOADED OPERATORS
// ================================================================================================

Expand Down
Loading