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

Approximate element pairing for sets #67

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

spavikevik
Copy link

@spavikevik spavikevik commented Dec 12, 2024

This tries to implement #66 in the following manner:

  • Introduces difference counts (one for the number of differences, and another for the number of ignored differences)
  • Abstracts pairing functions into PairingFn which can be equals-based or differ-based:
    • Equals-based functions work the same way as they used to
    • Differ-based pairing can be either approximate, using the default item differ or can rely on a user-specified differ instance. This is to allow for user customizability.
    • Differ-based pairing functions take an additional parameter for difference count threshold.
  • The difference count is compared against the threshold specified in the pairing function to then match similar elements.

I tried to approach this in as common-sense way as possible and made some assumptions when implementing this such as using the approximate pairing function by default and specifying difference threshold to be 1, but I am open to discussing/adjusting them as needed.

@jatcwang
Copy link
Owner

Thanks for the PR @spavikevik. Sorry I wasn't able to reply to your issue yesterday.

When I saw your message I was original thinking that we can changes things such that Differ[Set[A]] is available when there's an implicit ValueDiffer[A], otherwise the user has the specify the paring function manually.

However, I do like the user-experience here of providing a default a Set differ which tries to do some smart guessing. Let's explore further!

@spavikevik
Copy link
Author

spavikevik commented Dec 12, 2024

@jatcwang I thought it's worth to mention that my colleague at work had a suggestion about using an algorithm such as Hungarian Matching to always find the best candidates for pairing but I think its asymptotic complexity would be too bad for this use case.. I do wonder if there's more edge cases here that we can catch using some heuristics, however.

false
}
val found = expWithIdx.find { case (e, idx) =>
val res = itemDiffer.diff(a, e)
Copy link
Owner

Choose a reason for hiding this comment

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

Hm I don't think we can take this out of the if statement otherwise we're going to be running diff for all elements in obtained against all elements in expected.

Perhaps we need to separate PairingFunction into two sub-traits: One that knows whether a pair matches without needing to run diff and one that doesn't? The former can be used for ordered collections such as Seq etc and the latter for unordered collections like Set?

Copy link
Author

Choose a reason for hiding this comment

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

Perhaps something like this:
70c7bb1#diff-8183b3e34522b40214dc9c2bae969b6bdcc2d12f54eba714ba972ffd22d7cbd5R182-R198

Though I am not sure how you would feel about the boolean algebra one-liner there?

Copy link
Author

Choose a reason for hiding this comment

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

@jatcwang hope you've been able to take a look at the changes.
Wishing you happy holidays and Happy New Year!

@jatcwang jatcwang self-requested a review December 27, 2024 10:30
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