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

CRC32 as a hash function option? #8

Closed
michaeleisel opened this issue Feb 18, 2020 · 1 comment
Closed

CRC32 as a hash function option? #8

michaeleisel opened this issue Feb 18, 2020 · 1 comment

Comments

@michaeleisel
Copy link

CRC32 is nice for speed when we can use _mm_crc32_u*. I was curious if benchmarking had been done with a function like the following:

static inline size_t CRCHash(const char *__s, size_t len) {
	uint32_t __h = 5183;
	int curr = len;
	uint64_t *chunks = (uint64_t *)__s;
	while (curr >= 8) {
		__h = (uint32_t)_mm_crc32_u64((uint64_t)__h, *chunks);
		chunks++;
		curr -= 8;
	}
	if (curr >= 4) {
		uint32_t *bits = (uint32_t *)(__s + len - curr);
		__h = _mm_crc32_u32(__h, *bits);
		curr -= 4;
	}
	if (curr >= 2) {
		uint16_t *bits = (uint16_t *)(__s + len - curr);
		__h = _mm_crc32_u16(__h, *bits);
		curr -= 2;
	}
	if (curr >= 1) {
		__h = _mm_crc32_u8(__h, __s[len - 1]);
	}
	return (size_t)__h;
}
@Tessil
Copy link
Owner

Tessil commented Feb 19, 2020

Hi,

No, I didn't benchmark a lot of hash functions as I don't have much time to spend on that. I prefer to keep the default simple FNV-1a for now and use std::hash<std::string_view> when available but you can easily use your own hash function with the library.

Thibaut

@Tessil Tessil closed this as completed Mar 28, 2020
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

No branches or pull requests

2 participants