位图图像作为字典键 [英] Bitmap Image as a dictionary key
问题描述
我想知道图像的大小,以将其用作哈希集/字典键.我也在考虑为此目的使用哈希函数,但是我担心哈希冲突.我需要存储大约一百万张图片.
I want to know what size should be the image to use it as a hashset/dictionary key. I'm also thinking about using hash functions for this purpose but i'm afraid of hash collisions. I need to store about million of images.
推荐答案
将位图图像作为键?那不是一个好主意.哈希键应尽可能小,否则性能会受到严重影响.
A bitmap image as a key? That's not a very good idea. Hashset keys should be as small as possible, otherwise performance will suffer significantly.
您可以做的是从图像中计算一个哈希值(例如SHA1),然后将其用作键.它只有20个字节,因此应该是一个不错的大小,无论如何都要比完整的位图图像好得多.
What you can do is calculate a hash value (say a SHA1) from the image, and then use that as the key. It's only 20 bytes so that should be a good size, much better than a full bitmap image anyway.
这篇关于位图图像作为字典键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!