Пример #1
0
  public static void main(String[] args) {

    strings = new String[N];

    for (int i = 0; i < N; i++) {
      strings[i] = rndString();
    }
    System.out.printf("begin\n");

    boolean mine = true;
    if (mine) {

      long time4 = System.currentTimeMillis();

      HashTable ht = new HashTable();

      for (int i = 0; i < N; i++) {
        ht.insert(strings[i]);
      }

      System.out.printf("time: %d\n", System.currentTimeMillis() - time4);

      System.out.printf("col: %d\n", ht.colProbe);

      long time1 = System.currentTimeMillis();

      for (int j = 0; j < 10; j++) {
        for (int i = 0; i < N; i++) {
          int idx = ht.search(strings[i]);
          if (idx == -1) {
            System.out.printf("%s: %d %d %s\n", strings[i], i, idx, idx != -1 ? "true" : "false");
          }
        }
      }
      System.out.printf("time: %d\n", System.currentTimeMillis() - time1);
      System.out.printf("hops: %d %d %f\n", ht.nhops, ht.nsearch, (float) ht.nhops / ht.nsearch);
    }
    if (!mine) {
      long time3 = System.currentTimeMillis();
      HashSet<String> hs = new HashSet<String>();

      for (int i = 0; i < N; i++) {
        hs.add(strings[i]);
      }

      System.out.printf("time: %d\n", System.currentTimeMillis() - time3);

      long time2 = System.currentTimeMillis();

      for (int j = 0; j < 10; j++) {
        for (int i = 0; i < N; i++) {

          if (!hs.contains(strings[i])) {
            System.out.printf("%s: %d\n", strings[i], i);
          }
        }
      }
      System.out.printf("time: %d\n", System.currentTimeMillis() - time2);
    }
  }