Exemple #1
0
 @Before
 public void setup() {
   tree = new BTree<Integer>();
   tree.add(2);
   tree.add(4);
   tree.add(3);
   tree.add(1);
   tree.add(5);
   tree.add(6);
 }
Exemple #2
0
  @Test
  public void sucessorElement_() {
    BTree<Integer> t = new BTree<Integer>();
    t.add(5);
    t.add(3);
    t.add(7);
    t.add(2);
    t.add(4);
    t.add(6);

    Integer suc = t.sucessor(4);
    assertThat(suc, is(5));
  }
Exemple #3
0
  @Test
  public void removeFromOneElementTree() {
    tree = new BTree<Integer>();
    tree.add(1);
    tree.remove(1);

    assertThat(tree.size(), is(0));
  }
 public void mapId(int id, Slot slot) {
   _slotTree.add(trans(), new IdSlotMapping(id, slot.address(), slot.length()));
   if (_commitFrequency > 0) {
     _slotInsertCount++;
     if (_commitFrequency == _slotInsertCount) {
       _slotTree.commit(trans());
       _slotInsertCount = 0;
     }
   }
 }
 protected void mapNonClassIDs(int origID, int mappedID) {
   _cache = new MappedIDPair(origID, mappedID);
   _idTree.add(trans(), _cache);
   if (_commitFrequency > 0) {
     _idInsertCount++;
     if (_commitFrequency == _idInsertCount) {
       _idTree.commit(trans());
       _idInsertCount = 0;
     }
   }
 }
Exemple #6
0
  @Test
  public void checkcheckIfItIsBalanced() {
    assertThat(tree.isBalanced(), is(false));

    BTree<Integer> tree2 = new BTree<Integer>();
    assertThat(tree2.isBalanced(), is(true));

    tree2 = new BTree<Integer>();
    tree2.add(2);
    assertThat(tree2.isBalanced(), is(true));

    tree2 = new BTree<Integer>();
    tree2.add(2);
    tree2.add(4);
    assertThat(tree2.isBalanced(), is(true));

    tree2 = new BTree<Integer>();
    tree2.add(2);
    tree2.add(4);
    tree2.add(3);
    assertThat(tree2.isBalanced(), is(false));

    tree2 = new BTree<Integer>();
    tree2.add(2);
    tree2.add(4);
    tree2.add(3);
    tree2.add(1);
    assertThat(tree2.isBalanced(), is(true));
  }