I have a series of hash keys, many of which need to map to the same result. If I know exactly which hash keys need to map where, how can I go about designing a hash function that maximizes these collisions (minimizes necessary table size)? I am interested only in function speed and table size, not security.
I will be doing this for >100 tables, and am primarily asking for tips/suggestions on how to approach the problem, since each table will have its own range of keys and such.
As an example, here is the first table I am working on. The keys range from 0 to 31 (not all will occur in practice), and each should map to a particular group.
Group Key
1 0
2 3,6,9,15,18,21,24,27
3 8,10,12,14,16,20,22,26,28
4 11,17,23,29
5 13,25
6 19
7 31
I know know I could just make a lookup table or switch case for this instance, but other tables will span approximately 2^12 different hash keys and only have 49 unique groups. So in an effort to balance speed and table size, how would I even start to try finding a simple function for this (and similar cases)?
EDIT To clarify, I am not looking for an answer to this particular example. I am simply looking for insight to different patterns to look out for, how to take advantage of said patterns, common techniques (if this is a common thing to do?), etc. I am not sure that was clear on the original wording.