hashcode-string.html

来自「经典的数据结构源代码(java 实现)」· HTML 代码 · 共 21 行

HTML
21
字号
<html><head><title>Code Fragment</title></head><body text=#000000><center></center><br><br><dl><dd><pre>  <font color=#8000a0><font color=#8000a0>static</font> </font><font color=#8000a0>int</font> <font color=#0000ff>hashCode</font>(<font color=#8000a0>String</font> s) {    <font color=#8000a0><font color=#8000a0>int</font> </font>h=0;    <font color=#ff8000>for</font><font color=#0000ff> </font>(<font color=#8000a0>int</font> i=0; i&lt;s.<font color=#0000ff>length</font>(); i++) {      h =<font color=#0000ff> </font>(h &lt;&lt; 5) |<font color=#0000ff> </font>(h &gt;&gt;&gt; 27); <font color=#ff0080>// 5-bit cyclic shift of the running sum</font>      h +=<font color=#0000ff> </font>(<font color=#8000a0>int</font>) s.<font color=#0000ff>charAt</font>(i);   <font color=#ff0080>// add in next character</font>    }    <font color=#8000a0><font color=#ff8000>return</font> </font>h;  }</dl></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?