/************************************/
/* ハッシュ法(HashSet クラスの利用) */
/* coded by Y.Suganuma */
/************************************/
import java.io.*;
import java.util.*;
/****************/
/* main program */
/****************/
public class Test
{
public static void main (String[] args) throws IOException
{
int i1, k, n = 0, ct = 0;
boolean sw;
String st, s[] = new String [100000];
HashSet <String> H = new HashSet <String> (2000000);
long tm1, tm2, tm3;
Random rn = new Random((long)12345);
System.out.printf("ハッシュ法(HashSet クラス)\n");
tm1 = System.currentTimeMillis();
while (ct < 2000000) {
k = rn.nextInt();
st = Integer.toString(k);
sw = H.add(st);
if (sw) {
ct++;
if (n < 100000) {
s[n] = st;
n++;
}
}
}
tm2 = System.currentTimeMillis();
System.out.printf(" 保存: %d ms\n", tm2-tm1);
for (i1 = 0; i1 < n; i1++)
H.contains(s[i1]);
tm3 = System.currentTimeMillis();
System.out.printf(" 探索: %d ms\n", tm3-tm2);
System.out.printf(" データ数: %d\n", ct);
}
}