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

Improve hashsocket to avoid collisions #1646

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Coeur
Copy link
Contributor

@Coeur Coeur commented May 4, 2024

In 91e3ead, @nmathewson "improved" the hashsocket function with a "rotate-and-add trick".

Well, while rotating the bits is fine, performing an addition on the other hand will divide by two the number of possible different hashes. With twice less possible hashes, there will be collisions. Example:

unsigned h = 0x33333333;
h += (h >> 2) | (h << 30);
// result is 0xFFFFFFFF
unsigned h = 0xCCCCCCCC;
h += (h >> 2) | (h << 30);
// result is 0xFFFFFFFF

So we can keep the rotation, but we need to remove the addition for proper hashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant