0001 static size_t hashCode ( char c ) { return ( size_t ) c; } //字符 0002 static size_t hashCode ( int k ) { return ( size_t ) k; } //整数以及长长整数 0003 static size_t hashCode ( long long i ) { return ( size_t ) ( ( i >> 32 ) + ( int ) i ); } 0004 static size_t hashCode ( char s[] ) { //生成字符串的循环移位散列码(cyclic shift hash code) 0005 unsigned int h = 0; //散列码 0006 for ( size_t n = strlen ( s ), i = 0; i < n; i++ ) //自左向右,逐个处理每一字符 0007 { h = ( h << 5 ) | ( h >> 27 ); h += ( int ) s[i]; } //散列码循环左移5位,再累加当前字符 0008 return ( size_t ) h; //如此所得的散列码,实际上可理解为近似的“多项式散列码” 0009 } //对于英语单词,"循环左移5位"是实验统计得出的最佳值