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

Added magic hashes for xxHash, non-cryptographic hash function #27

Merged
merged 1 commit into from
Oct 7, 2023

Conversation

spaze
Copy link
Owner

@spaze spaze commented Oct 7, 2023

xxHash is an extremely fast non-cryptographic hash algorithm, working at RAM speed limit. It is proposed in four flavors (XXH32, XXH64, XXH3_64bits and XXH3_128bits). The latest variant, XXH3, offers improved performance across the board, especially on small data.

https://xxhash.com/

All four flavors are supported by PHP 8.1+.

Generated with a code like this, the numbers in the for loop had to be extended of course for the higher-bit flavors:

$algo = 'xxh32',
for ($i = 10_000_000; $i < 10_009_999; $i++) {
	$input = $i;
	$hash = hash($algo, $input);
	if ($hash == 0) {
		echo "$input:$hash\n";
	}
}
for ($i = 100_000_000; $i < 100_099_999; $i++) {
	$input = base64_encode($i);
	$hash = hash($algo, $input);
	if ($hash == 0) {
		echo "$input:$hash\n";
	}
}
for ($i = 100_000_000; $i < 100_099_999; $i++) {
	$input = base64_encode(random_bytes(9));
	$hash = hash($algo, $input);
	if ($hash == 0) {
		echo "$input:$hash\n";
	}
}

> xxHash is an extremely fast non-cryptographic hash algorithm, working at RAM speed limit. It is proposed in four flavors (XXH32, XXH64, XXH3_64bits and XXH3_128bits). The latest variant, XXH3, offers improved performance across the board, especially on small data.

https://xxhash.com/

All four flavors are supported by PHP 8.1+.
@spaze spaze self-assigned this Oct 7, 2023
@spaze spaze merged commit 8038d79 into master Oct 7, 2023
@spaze spaze deleted the spaze/xxhash branch October 7, 2023 01:21
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.

1 participant