Repository navigation
Add rich comparison operators via PartialOrd trait implementation - #58
Conversation
…ering semantics - PartialEq now compares keys using the implici 'zero' element, rather than using equality on the underlying map. - PartialOrd is now implemented to allow for the <, >, <=, >= operator overloads. Migrated is_subset and is_superset to wrap around the ParitialOrd::partial_cmp method.
PR Summary by QodoImplement PartialOrd and fix zero-aware equality for Counter
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
Context used✅ Tickets:
🎫 `impl PartialOrd` via `is_{sub,super}set` 1. Comparisons depend on wrong zero
|
coriolinus
left a comment
There was a problem hiding this comment.
Thanks for implementing this! I do need two changes:
- Remove the double-scan of the keys in
partial_cmp. - Restore the wrongly-deleted doc comment.
| where | ||
| T: Eq + Hash, | ||
| N: PartialEq, | ||
| N: PartialEq + Zero, |
There was a problem hiding this comment.
This is in fact a breaking change, but I'm inclined to permit it on the basis that this is long overdue to replace the zero field with references to N: ConstZero, and that would also break the same things.
Thanks @coriolinus ! I've incorporated those amemndments :) |
coriolinus
left a comment
There was a problem hiding this comment.
Looks good, thanks for putting in the work!
To address #49 I've implemented
PartialOrd. This should use the correct multiset partial ordering semantics as in the Python implmentation.<, >, <=, >=operator overloads. Migratedis_subsetandis_supersetmethods to wrap around theParitialOrd::partial_cmpmethod.I'm not sure if adding
Zeroas a trait bound is considered a breaking change, though?Specifically, I think there's a bug in the
masterbranch in that I don't think it's correct to useself.map == other.mapfor equality comparisons. If you manually set a key to be0on aCounter, it should be considered to be equal to a newCounter.counter-rs/src/lib.rs
Lines 302 to 305 in e518825