0001 static Rank hashCode(char s[], Rank m) { //多项式散列码 0002 Rank h = 0; 0003 for (Rank i = 0; i < m; i++) { //自左向右,由高位至低位,逐个处理各字符 0004 h = (h << 5) | (h >> 27); //左移5位即乘以32;右移27位作为扰动 0005 h += s[i]; //累计上当前字符的贡献 0006 } //n次乘法与加法,通过整数溢出实现模余,故本质上也是MAD法 0007 return h; 0008 } //32接近于26,故适用于英文;对于中文字符串,需做相应的调整 0009 static Rank hashCode(char s[]) { return hashCode(s, strlen(s)); } //多项式散列码