0

I have a set S of random positive integers that is of known size n. Is there a way to generate a hashing function which perfectly maps each value of S uniquely onto the set P where P consists of values 0 to n-1.

For example:

Given:

S = { 345, 69205, 0, 8237, 512 }

P = { 0, 1, 2, 3, 4 }

a valid function f could be

f(345) = 2, f(69205) = 4, f(0) = 3, f(8237) = 3, f(512) = 1

Note that the ordering of the mapping need not match the ordering of the elements of set S, that is, 345 need not map to 0. While the given example function f is valid, it would not be the only valid mapping.

TheBat
  • 101
  • Did some more searching, the answer is bijection. – TheBat Jun 23 '22 at 21:15
  • The idea is that storing the parameters of the function would be smaller than storing a full key -> value mapping using a set/hash map. For example, if I could generate a polynomial function that does the mapping, then storing the terms of that polynomial may be smaller. Generic hash tables use the same hash function for all elements then modulo the hashed value to map to a position within the allocated space. I want skip needing the underlying container and the modulo math. – TheBat Jun 27 '22 at 16:21
  • Interesting. Although I am a retired programmer, I am totally unfamiliar with hash functions. So, I am out of my depth here. So, I will delete my previous comments. – user2661923 Jun 27 '22 at 18:10

0 Answers0