20130703【Java】重率を掛けたハッシュ値を生成する
お題
重率を掛けたハッシュ値を生成する
ソース
public class List7_2 {
public static int makeHash2(String str, int hasmax){
int hash = 0, weight = 0;
for(int n = 0; n < str.length(); ++n, ++weight){
if (weight > 7){
weight = 0;
}
hash += 1 << (4 * weight);
}
return hash % hasmax;
}
public static void main(String[] args) {
System.out.println(makeHash2("hoge", 100));
System.out.println(makeHash2("hogehoge", 100));
}
}
実行結果
69
53