hash表是快速尋找演算法中比較好的一種,雜湊表中的雜湊函數是其中比較重要的。Java使用的Hash函數說明如下
/**
* Returns a hash code for this string. The hash code for a
* <code>String</code> object is computed as
* <blockquote><pre>
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* </pre></blockquote>
* using <code>int</code> arithmetic, where <code>s[i]</code> is the
* <i>i</i>th character of the string, <code>n</code> is the length of
* the string, and <code>^</code> indicates exponentiation.
* (The hash value of the empty string is zero.)
*
* @return a hash code value for this object.
*/
public int hashCode() {
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;
}
由於是Hash函數,所以一般情況下衝突不可避免,比如如下的漢字就會出現相同雜湊值的情況:
Java的Hash值相同的值如下:
古漢語:
國學寶典字詞頻表(從10億已標點字統計,暫時發布簡體字詞表)1.0[2007-06-10][前1萬個]
國學寶典是目前最大的古籍類全文資料庫,希望以該資料庫為基礎的統計能對搞語言學和檢索引擎的朋友有用
http://www.gxbd.com
http://bbs.guoxue.com[擷取更新]
雜湊值
獠 敗走 60774744
羹 弩 -629648662
東京 叉 1835901360
另外現代漢語中也有不少,比如
結算 罰款
hash表的方面還有很多問題,以後再說