Skip to content

Fix the uniqueItems implementation to accommodate non-primitive values #511

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

Merged
merged 1 commit into from
Feb 18, 2022

Conversation

adamthom-amzn
Copy link
Contributor

Description of changes:
JavaScript Sets do not work in the same fashion as HashSets do in Java, in that
object equivalence is determined by reference, not by value. In order to work
around this, this commit adds a duplicate finder that works on the same
principals as a value-based hashtable: it creates a hash of the object's value
to bucket objects and then uses deep equality to determine if a hash collision
is actually a duplicate value.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

});

// This is relatively slow and may be flaky if the input size is tuned to let it run reasonably fast
it.skip("is faster than the naive implementation", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

import * as util from "util";

/**
* A shortcut for document-like objects or Smithy structures.
Copy link
Contributor

Choose a reason for hiding this comment

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

Broader than that? in that it includes primitives like number

JavaScript Sets do not work in the same fashion as HashSets do in Java, in that
object equivalence is determined by reference, not by value. In order to work
around this, this commit adds a duplicate finder that works on the same
principals as a value-based hashtable: it creates a hash of the object's value
to bucket objects and then uses deep equality to determine if a hash collision
is actually a duplicate value.
@adamthom-amzn adamthom-amzn merged commit 8a7cddb into smithy-lang:main Feb 18, 2022
@adamthom-amzn adamthom-amzn deleted the fix-uniqueness branch February 18, 2022 23:42
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.

3 participants