Java hashcode Parsing

Source: Internet
Author: User

The hash table is a better algorithm for quick search. The hash function in the hash table is important. The hash functions used by Java are described as follows:

/**
* Returns a hash code for this string. The hash code for
* <Code> string </code> object is computed
* <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
* <I> I </I> TH character of the string, <code> n </code> is the length
* 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;
}

Because it is a hash function, conflicts are inevitable. For example, the following Chinese characters may share the same hash value:

The Java hash values are the same as follows:

Ancient Chinese:
The word frequency table of the Chinese National Learning Bao dian (from 1 billion punctuation statistics, the simplified Chinese Word Table is temporarily released) 1.0 [] [Top 10 thousand]

The Chinese learning database is currently the largest full-text database of ancient books. It is hoped that statistics based on this database will be useful to friends who are engaged in Linguistics and search engines.
Http://www.gxbd.com
Http://bbs.guoxue.com [get updates]

Hash Value
60774744 loss
Tomo-629648662
Tokyo fork 1835901360

In addition, there are also a lot of modern Chinese, such

Settlement fines

There are still many problems with hash tables.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.