Пример #1
0
 @Test
 public void testSlicingAllSmallTrees() throws ExecutionException, InterruptedException {
   Object[] cur = BTree.empty();
   TreeSet<Integer> canon = new TreeSet<>();
   // we set FAN_FACTOR to 4, so 128 items is four levels deep, three fully populated
   for (int i = 0; i < 128; i++) {
     String id = String.format("[0..%d)", canon.size());
     log("Testing " + id);
     Futures.allAsList(testAllSlices(id, cur, canon)).get();
     Object[] next = null;
     while (next == null)
       next = BTree.update(cur, naturalOrder(), Arrays.asList(i), SPORADIC_ABORT);
     cur = next;
     canon.add(i);
   }
 }
Пример #2
0
  private static RandomTree randomTreeByUpdate(int minSize, int maxSize) {
    assert minSize > 3;
    TreeSet<Integer> canonical = new TreeSet<>();

    ThreadLocalRandom random = ThreadLocalRandom.current();
    int targetSize = random.nextInt(minSize, maxSize);
    int maxModificationSize = random.nextInt(2, targetSize);
    Object[] accmumulate = BTree.empty();
    int curSize = 0;
    while (curSize < targetSize) {
      int nextSize = maxModificationSize == 1 ? 1 : random.nextInt(1, maxModificationSize);
      TreeSet<Integer> build = new TreeSet<>();
      for (int i = 0; i < nextSize; i++) {
        Integer next = random.nextInt();
        build.add(next);
        canonical.add(next);
      }
      accmumulate =
          BTree.update(accmumulate, naturalOrder(), build, UpdateFunction.<Integer>noOp());
      curSize += nextSize;
      maxModificationSize = Math.min(maxModificationSize, targetSize - curSize);
    }
    return new RandomTree(canonical, BTreeSet.<Integer>wrap(accmumulate, naturalOrder()));
  }
Пример #3
0
 public static <V> BTreeSet<V> empty(Comparator<? super V> comparator) {
   return new BTreeSet<>(BTree.empty(), comparator);
 }