many to one mapping Hash Function
-
07-04-2021 - |
Вопрос
I don't know the actual mathematical term (many to one mapping is the terminology i've used)
This is my requirement:
hash_code = hash_function(element 1, element 2, ...... element n)
i should be able to retrieve
bool b = is_valid_hash(hash_code, element x)
the function is_valid_hash
should be able to tell me weather 'element x
' was an element passed in the hash_function
What is the name to such hash functions? One hash should be able to map to multiple elements (not collision).
Решение
what i was looking for is : Bloom Filter
Другие советы
Assuming that hash_function is a standard hashing algorithm (md5, etc) this can't be done. However, if it's a custom function you could do it in one of two ways:
hash_function() could hash each element and then concatenate the strings (this would produce a very long hash, and it would be less secure in some ways, but it would work), and then you could do a sub-string compare on is_valid_hash() (see if the hashed element x is a substring of hash_code.
Similarly, hash_function could return an array of hashes... if you need a string or security is a concern, you could also return a 2-way encrypted serialized array... this could then be decrypted and unserialized in is_valid_hash() and you could check if the element x hash is in the array.