Пример #1
0
 /** ************************ TEST MUTATION ******************************************* */
 @Test
 public void testOversizedMiddleInsert() {
   TreeSet<Integer> canon = new TreeSet<>();
   for (int i = 0; i < 10000000; i++) canon.add(i);
   Object[] btree =
       BTree.build(Arrays.asList(Integer.MIN_VALUE, Integer.MAX_VALUE), UpdateFunction.noOp());
   btree = BTree.update(btree, naturalOrder(), canon, UpdateFunction.<Integer>noOp());
   canon.add(Integer.MIN_VALUE);
   canon.add(Integer.MAX_VALUE);
   assertTrue(BTree.isWellFormed(btree, naturalOrder()));
   testEqual("Oversize", BTree.iterator(btree), canon.iterator());
 }
Пример #2
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);
   }
 }
Пример #3
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()));
  }
Пример #4
0
 public BTreeSet<V> update(Collection<V> updateWith) {
   return new BTreeSet<>(
       BTree.update(tree, comparator, updateWith, UpdateFunction.<V>noOp()), comparator);
 }