I recently read this article Throw away the keys: Easy, Minimal Perfect Hashing about generating a minimal perfect hash table for a known set of keys.
The article seems to assume that you need an intermediate table. Is there any other, simpler way to generate such a function if we assume that the set of keys is small (i.e. < 64).
In my case, I want to map a set of thread ID:s to a unique block of data within an array. The threads are started before the hash function is generated and stay constant during the running time of the program. The exact number of threads vary but stays fixed during the runtime of the program:
unsigned int thread_ids*;
unsigned int thread_count;
struct {
/* Some thread specific data */
}* ThreadData;
int start_threads () {
/* Code which starts the threads and allocates the threaddata. */
}
int f(thread_id) {
/* return unique index into threadData */
}
int main() {
thread_count = 64; /* This number will be small, e.g. < 64 */
start_threads();
ThreadData[f(thread_ids[0])]
}
f()
function. (typical average chainlength is ~1.5 for a N=M table) – Tussisf
? (For example: any 16 bit number, an integer between 0 and 63, etc.) Why can't we providef
the index of the thread in thread_ids rather than the thread id itself? Please forgive my ignorance. – Dariodariole