多对一映射哈希函数
我不知道实际的数学术语(多对一映射是我使用的术语)
这是我的要求:
hash_code = hash_function(element 1, element 2, ...... element n)
我应该能够检索
bool b = is_valid_hash(hash_code, element x)
函数 is_valid_hash
应该能够告诉我天气“element x
”是在 hash_function
中传递的一个元素,
此类哈希函数的名称是什么?一个散列应该能够映射到多个元素(而不是冲突)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在寻找的是: Bloom Filter
what i was looking for is : Bloom Filter
假设 hash_function 是标准哈希算法(md5 等),这是无法完成的。但是,如果它是自定义函数,您可以通过以下两种方式之一来完成:
hash_function() 可以对每个元素进行散列,然后连接字符串(这会产生非常长的散列,并且在某些方面会不太安全) ,但它会工作),然后你可以对 is_valid_hash() 进行子字符串比较(查看散列元素 x 是否是 hash_code 的子字符串。
类似地,hash_function 可以返回一个哈希数组...如果您需要一个字符串或考虑安全性,您还可以返回一个 2 路加密的序列化数组...然后可以将其解密和在 is_valid_hash() 中反序列化,您可以检查元素 x 哈希是否在数组中。
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.