Skip to content

Conversation

@stanpapa
Copy link

@stanpapa stanpapa commented Dec 1, 2025

This PR adds AbsDiffEq, RelativeEq and UlpsEq from the approxim crate for IndexMap. The trait implementation are locked behind the approxim feature flag.

These traits build on top of PartialEq and are used to compare values with variable precision, which simplifies float comparisons.

@cuviper
Copy link
Member

cuviper commented Dec 1, 2025

This seems like a quite niche thing to add, in part because approxim has much less usage than the original approx crate, yet we don't have that implementation either.

These traits also don't seem to be container-oriented -- they're not implemented for the standard BTreeMap or HashMap, nor even Vec. They are implemented for slices, but I'd guess that's more simd-oriented. What is the use case where you need an IndexMap itself to implement these traits?

Without any new dependencies, I could imagine having a generic comparison method, something like:

fn eq_by(&self, other: &IndexMap<K, V2, S2>, eq: impl FnMut(&V, &V2)) -> bool;

Would that meet your needs?

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

Successfully merging this pull request may close these issues.

2 participants