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

Conversation

plafer
Copy link
Contributor

@plafer plafer commented Oct 30, 2023

Implements Ord for all BaseElements. One benefit is that they can be used as the key to a BTreeMap (or any other data structure that requires ordering).

@@ -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?

@plafer
Copy link
Contributor Author

plafer commented Oct 30, 2023

Closing after speaking with @irakliyk, as this is no longer needed in miden-node (and @irakliyk preferred not to have fields be Ord since they don't have an inherent order).

@plafer plafer closed this Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants