int h = hash; if (h == 0) { int off = offset; char val[] = value; int len = count; for (int i = 0; i < len; i++) { h = 31*h + val[off++]; } hash = h; } return h; 也就是把所有的字符考虑在内,而且顺序也考虑在内了,为了保证更好的性能(离散性)哈西表的数组大小和key的哈西值没有关系,和放入哈西表的元素的数量有关。 但是离散的哈西值可以提高哈西表的性能!
对空间不会有任何的额外开销!
if (h == 0) {
int off = offset;
char val[] = value;
int len = count; for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
hash = h;
}
return h;
也就是把所有的字符考虑在内,而且顺序也考虑在内了,为了保证更好的性能(离散性)哈西表的数组大小和key的哈西值没有关系,和放入哈西表的元素的数量有关。
但是离散的哈西值可以提高哈西表的性能!