How about friends, I have a query since I can't find much information about it, how could I implement a compression hash function to order 10 license plates for example? The license plates consist of 3 numbers and 3 letters, someone could support me by giving me a example of it.
Asked
Active
Viewed 233 times
0
-
Hi Louis, welcome to stack overflow. Your question is quiet vague. What language are you using? We need some more context to be able to assist. – NULL pointer Jun 07 '21 at 00:58
-
I haven't actually programmed it yet, I just want to understand the algorithm to be able to do it, some example of how a compression hash is calculated. – Louis Jun 07 '21 at 01:00
-
Questions need to be a lot more specific to get quality answers. Maybe start at Wikipedia to learn what a hash function is, and come back here to ask any specific queries. – NULL pointer Jun 07 '21 at 23:20
1 Answers
0
One easy way is just to arrange the values side by side in memory, then run an existing hash function over that block of memory. Even a CRC function will produce a good enough result for most purposes.
Another approach is to pick any function that produces a good hash from a number, and hash each part in turn (or at a pinch just use the number - an identity hash - which would be the ASCII/Unicode/etc value for the letters): 3 digits then 3 letters, giving you six hash values - which let's assume you've put in array elements h[0]
through h[5]
, that you could then combine as follows:
size_t x = 0;
for (int i = 0; i < 5; ++i)
x ^= h[i] + 0x9e3779b9 + (x<<6) + (x>>2);
If you want to know why that's generally reasonable, check this question.

Tony Delroy
- 102,968
- 15
- 177
- 252