{"id":1113,"date":"2023-02-10T10:20:13","date_gmt":"2023-02-10T02:20:13","guid":{"rendered":"http:\/\/www.algmain.com\/?page_id=1113"},"modified":"2023-02-10T10:24:37","modified_gmt":"2023-02-10T02:24:37","slug":"integer","status":"publish","type":"page","link":"http:\/\/www.algmain.com\/index.php\/algorithm-article\/hash-function\/integer\/","title":{"rendered":"\u6574\u6570\u5316"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">1 \u5b57\u7b26\u4e32\u53d6\u4f59\u64cd\u4f5c<\/h3>\n\n\n\n<p>\u5f53\u5173\u952e\u5b57\\(key\\)\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u65f6\uff0c\u53ef\u4ee5\u5c06\u8be5\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3a\u5b57\u8282\u6570\u7ec4\u3002\u5982\u679c\u5173\u952e\u5b57\\(key\\)\u7684\u5b57\u7b26\u4e32\u4e2d\u6ca1\u6709\u4efb\u4f55\u672c\u5730\u8bed\u8a00\u5b57\u7b26\uff08\u5373\u5168\u90e8\u5747\u4e3aASCII\u7801\uff09\uff0c\u5219\u76f4\u63a5\u53ef\u4ee5\u8f6c\u6362\u6210\u5b57\u8282\u6570\u7ec4\uff1b\u5982\u679c\u5173\u952e\u5b57\u7684\u5b57\u7b26\u4e32\u4e2d\u53ef\u80fd\u6709\u672c\u5730\u8bed\u8a00\u5b57\u7b26\uff0c\u5219\u53ef\u4ee5\u4f9d\u636e\u672c\u5730\u5b57\u7b26\u96c6\u7f16\u7801\u6216\u8005\u901a\u7528\u5b57\u7b26\u96c6\u7f16\u7801\uff0c\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5b57\u8282\u6570\u7ec4\u3002\u8f6c\u5316\u4e3a\u5b57\u8282\u6570\u7ec4\u540e\uff0c\u5373\u53ef\u6309\u7167\u5b57\u8282\u6570\u7ec4\u8fdb\u884c\u53d6\u4f59\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>\u5728Java\u7a0b\u5e8f\u4e2d\uff0c\u5b57\u7b26\u4e32\u53ef\u4ee5\u6309\u7167char\u7c7b\u578b\uff08unicode\u7f16\u7801\uff09\u8fdb\u884c\u8bbf\u95ee\uff0c\u5c06char\u7c7b\u578b\u76f4\u63a5\u6309\u7167short\u7c7b\u578b\u8fdb\u884c\u5904\u7406\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\/** \n * Get residue of string. \n * \n * @param value Value of string. \n * @param prime A prime for dividing. \n * @return \n *     &lt;p&gt;Residue of string.&lt;\/p&gt; \n *\/  \npublic static  \n       int getResidue(String value,int prime)  \n{  \n    \/\/Residue  \n    int residue = 0;  \n    \/\/Each char is divided by prime.  \n    for(int i = 0;i &lt; value.length();i ++)  \n    {  \n        \/\/Get residue.  \n        residue = (value.charAt(i) + (residue &lt;&lt; 16)) % prime;  \n    }  \n    \/\/Return residue.  \n    return residue;  \n}  \n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">2 \u5b57\u8282\u6570\u7ec4\u53d6\u4f59\u64cd\u4f5c<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\/** \n * Get residue of byte array. \n * \n * @param bytes Byte array. \n * @param prime A prime for dividing. \n * @return \n *     &lt;p&gt;Residue of byte array.&lt;\/p&gt; \n *\/  \npublic static  \n      int getResidue(byte&#x5B;] bytes,int prime)  \n{  \n    \/\/Residue  \n    int residue = 0;  \n    \/\/Each byte is divided by prime.  \n    for(int i = 0;i &lt; bytes.length;i ++)  \n    {  \n        \/\/Get residue.  \n        residue = (bytes&#x5B;i] + (residue &lt;&lt; 8)) % prime;  \n    }  \n    \/\/Return residue.  \n    return residue;  \n}  \n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>1 \u5b57\u7b26\u4e32\u53d6\u4f59\u64cd\u4f5c \u5f53\u5173\u952e\u5b57\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u65f6\uff0c\u53ef\u4ee5\u5c06\u8be5\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3a\u5b57\u8282\u6570\u7ec4\u3002\u5982\u679c\u5173\u952e\u5b57\u7684\u5b57\u7b26\u4e32\u4e2d\u6ca1\u6709\u4efb\u4f55\u672c\u5730\u8bed\u8a00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1021,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1113","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.algmain.com\/index.php\/wp-json\/wp\/v2\/pages\/1113"}],"collection":[{"href":"http:\/\/www.algmain.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.algmain.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.algmain.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.algmain.com\/index.php\/wp-json\/wp\/v2\/comments?post=1113"}],"version-history":[{"count":3,"href":"http:\/\/www.algmain.com\/index.php\/wp-json\/wp\/v2\/pages\/1113\/revisions"}],"predecessor-version":[{"id":1118,"href":"http:\/\/www.algmain.com\/index.php\/wp-json\/wp\/v2\/pages\/1113\/revisions\/1118"}],"up":[{"embeddable":true,"href":"http:\/\/www.algmain.com\/index.php\/wp-json\/wp\/v2\/pages\/1021"}],"wp:attachment":[{"href":"http:\/\/www.algmain.com\/index.php\/wp-json\/wp\/v2\/media?parent=1113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}