Пример #1
0
  @SuppressWarnings("unchecked")
  void testSpeed(AbstractPriorityQueue<Integer>... qs) {
    final int ITER = 1000, LENGTH = qs.length;
    final Random rand = new Random(0);

    StringBuilder build = new StringBuilder();
    long[][] times = new long[LENGTH][2];
    int[] keys;

    for (int size = 100; size <= 1000; size += 100) {
      for (int j = 0; j < ITER; j++) {
        keys = DSUtils.getRandomIntArray(rand, size);

        for (int k = 0; k < LENGTH; k++) addRuntime(qs[k], times[k], keys);
      }

      build.append(size);

      for (long[] time : times) {
        build.append("\t");
        build.append(StringUtils.join(time, "\t"));
      }

      build.append("\n");
    }

    System.out.println(build.toString());
  }
Пример #2
0
  public void run() throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    List<String> candidates;
    String prefix, pick;

    do {
      System.out.print("Enter a prefix: ");
      prefix = reader.readLine();

      // TODO: print out the top 10 candidates
      candidates = t_auto.getCandidates(prefix);
      System.out.println(StringUtils.join(candidates, "\n"));

      System.out.print("Pick: ");
      pick = reader.readLine();

      // TODO: update your Trie with this pick.
      t_auto.pickCandidate(prefix, pick);
      System.out.println("\"" + pick + "\" is learned.\n");
    } while (true);
  }