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

Implementation of PartialEq, Eq, PartialOrd and Ord for IndexMap #91

Closed
torkleyy opened this issue Feb 14, 2019 · 2 comments
Closed

Implementation of PartialEq, Eq, PartialOrd and Ord for IndexMap #91

torkleyy opened this issue Feb 14, 2019 · 2 comments

Comments

@torkleyy
Copy link

Hey, I'd like to replace BTreeMap by IndexMap to preserve the order of deserialized elements in RON. However, IndexMap lacks PartialEq, Eq, PartialOrd and Ord.

Is that intentional or just not implemented yet?

@cuviper
Copy link
Member

cuviper commented Feb 16, 2019

IndexMap does implement equality in the same fashion as HashMap -- maps are considered equal if they contain equal keys and values. This is independent of order, which is natural for HashMap but perhaps surprising for IndexMap.

PartialOrd and Ord must agree with PartialEq and Eq in what they call Ordering::Equal, which means this comparison must also be independent of the IndexMap's order. It must also be antisymmetric and transitive, as well as being total for Ord. BTreeMap can easily implement a consistent comparison since the keys are sorted, but we have no such luxury here.

If you do know your keys are sorted, or if you just want to compare by each maps' current order regardless, you can iterate them and use Iterator::cmp and friends.

@torkleyy
Copy link
Author

I see, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants