理解散列码 [英] understanding of hash code

查看:152
本文介绍了理解散列码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哈希函数在实现哈希表中很重要。我知道在java
Object中有它的哈希代码,它可能是由弱哈希函数产生的。



以下是一个片段,它是补充散列函数

  static int hash(Object x){
int h = x.hashCode();

h + =〜(h <9);
h ^ =(h>>> 14);
h + =(h <4);
h ^ =(h>>> 10);
返回h;





$ b

任何人都可以帮助解释散列算法的基本思想是什么
?生成非重复的整数?如果是这样,那么这些按位
操作是如何实现的呢?

解决方案

哈希函数是任何定义良好的过程,数学函数,将大量的可能大小可变的数据转换为小数据,通常是一个可用作数组索引的整数。由散列函数返回的值称为散列值,散列码,散列总和,校验和或简单散列。 (维基百科



使用更多人语言对象散列是基于对象属性的简短紧凑值。这就是说,如果你有两个对象以某种方式变化 - 你可以期望他们的散列值是不同的。好的散列算法为不同的对象产生不同的值。

hash function is important in implementing hash table. I know that in java Object has its hash code, which might be generated from weak hash function.

Following is one snippet that is "supplement hash function"

static int hash(Object x) {
    int h = x.hashCode();

    h += ~(h << 9);
    h ^=  (h >>> 14);
    h +=  (h << 4);
    h ^=  (h >>> 10);
    return h;
}

Can anybody help to explain what is the fundamental idea of a hash algorithm ? to generate non-duplicate integer? If so, how does these bitwise operations make it?

解决方案

A hash function is any well-defined procedure or mathematical function that converts a large, possibly variable-sized amount of data into a small datum, usually a single integer that may serve as an index to an array. The values returned by a hash function are called hash values, hash codes, hash sums, checksums or simply hashes. (wikipedia)

Using more "human" language object hash is a short and compact value based on object's properties. That is if you have two objects that vary somehow - you can expect their hash values to be different. Good hash algorithm produces different values for different objects.

这篇关于理解散列码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆