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

SE: Enumerable ContentHash for ordered and unordered sets #6979

Merged
merged 4 commits into from
Mar 27, 2023

Conversation

martin-strecker-sonarsource
Copy link
Contributor

Part of #6964

@martin-strecker-sonarsource martin-strecker-sonarsource changed the title SE: Enumerable ContentHash SE: Enumerable ContentHash for ordered and unordered sets Mar 23, 2023
Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

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

Some questions to clarify

@@ -28,12 +28,16 @@ public static class HashCode // Replacement for System.HashCode that is avail
private const uint PreMultiplier = 3266489917U;
private const uint PostMultiplier = 668265263U;
private const int RotateOffset = 17;
private const int IntSeed = 393241;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use Seed instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is givin "Empty" some random value? Why not keeping 0 for empy? It's valid integer has value like any other

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seed is unit. This number is taken from https://planetmath.org/goodhashtableprimes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to have a seed so the first value gets transformed (x ^ 0 = x) and a good hash function should distribute the values along the available number space.

Copy link
Contributor

Choose a reason for hiding this comment

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

I need answers to these questions before approving.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Damit! Always the same mistake:
image

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd argue that x is already a good distribution :D

analyzers/src/SonarAnalyzer.Common/Helpers/HashCode.cs Outdated Show resolved Hide resolved
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

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

There was one missed thread above that needs answers, or to be addressed

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

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

LGTM

@pavel-mikula-sonarsource pavel-mikula-sonarsource merged commit 4f63200 into feature/SE Mar 27, 2023
@pavel-mikula-sonarsource pavel-mikula-sonarsource deleted the Martin/SE_6964_EnumerableHash branch March 27, 2023 09:46
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