Search in sources :

Example 1 with LongIterator

use of jetbrains.exodus.tree.LongIterator in project xodus by JetBrains.

the class BottomPageMutable method delete.

@Override
public boolean delete(@NotNull ByteIterable key, @Nullable ByteIterable value) {
    final int pos = binarySearch(key);
    if (pos < 0)
        return false;
    final BTreeMutable tree = (BTreeMutable) getTree();
    if (tree.allowsDuplicates) {
        final ILeafNode ln = getKey(pos);
        if (value == null) {
            // size will be decreased dramatically, all dup sub-tree will expire
            tree.addExpiredLoggable(keysAddresses[pos]);
            LongIterator it = ln.addressIterator();
            while (it.hasNext()) tree.addExpiredLoggable(it.next());
            copyChildren(pos + 1, pos);
            tree.decrementSize(ln.getDupCount());
            decrementSize(1);
            return true;
        }
        if (ln.isDup()) {
            LeafNodeDupMutable lnm;
            boolean res;
            if (ln.isMutable()) {
                lnm = (LeafNodeDupMutable) ln;
                res = lnm.delete(value);
            } else {
                LeafNodeDup lnd = (LeafNodeDup) ln;
                final BTreeDupMutable dupTree = lnd.getTreeCopyMutable();
                dupTree.mainTree = tree;
                if (res = dupTree.delete(value)) {
                    tree.addExpiredLoggable(ln.getAddress());
                    lnm = LeafNodeDupMutable.convert(ln, tree, dupTree);
                    // remember in page
                    set(pos, lnm, null);
                } else {
                    return false;
                }
            }
            if (res) {
                // if only one node left
                if (lnm.getRootPage().isBottom() && lnm.getRootPage().getSize() == 1) {
                    // expire previous address
                    tree.addExpiredLoggable(keysAddresses[pos]);
                    // expire single duplicate from sub-tree
                    LongIterator it = ln.addressIterator();
                    tree.addExpiredLoggable(it.next());
                    // convert back to leaf without duplicates
                    set(pos, tree.createMutableLeaf(lnm.getKey(), lnm.getValue()), null);
                }
                return true;
            }
            return false;
        }
    }
    tree.addExpiredLoggable(keysAddresses[pos]);
    copyChildren(pos + 1, pos);
    tree.decrementSize(1);
    decrementSize(1);
    return true;
}
Also used : LongIterator(jetbrains.exodus.tree.LongIterator)

Example 2 with LongIterator

use of jetbrains.exodus.tree.LongIterator in project xodus by JetBrains.

the class BTreeDuplicatesExpiredAddressesTest method countNodes.

private long countNodes(BasePage page) {
    if (page.isBottom()) {
        long result = 1;
        for (int i = 0; i < page.getSize(); i++) {
            long r = 1;
            BaseLeafNode node = page.getKey(i);
            if (node.isDup()) {
                LongIterator it = node.addressIterator();
                while (it.hasNext()) {
                    it.next();
                    r += 1;
                }
            } else {
                r += 1;
            }
            result += r;
        }
        return result;
    }
    long result = 1;
    for (int i = 0; i < page.getSize(); i++) {
        result += countNodes(page.getChild(i));
    }
    return result;
}
Also used : LongIterator(jetbrains.exodus.tree.LongIterator)

Example 3 with LongIterator

use of jetbrains.exodus.tree.LongIterator in project xodus by JetBrains.

the class BTreeStructureIdTest method assertStructureIdNotEqual.

public static void assertStructureIdNotEqual(long firstAddress, long secondAddress) {
    ITree firstImTree = new BTree(log, firstAddress, false, 3);
    ITree secondImTree = new BTree(log, secondAddress, false, 3);
    LongIterator it = firstImTree.addressIterator();
    LongHashSet firstSet = new LongHashSet();
    LongHashSet secondSet = new LongHashSet();
    while (it.hasNext()) firstSet.add(log.read(it.next()).getStructureId());
    it = secondImTree.addressIterator();
    while (it.hasNext()) secondSet.add(log.read(it.next()).getStructureId());
    for (long firstStructureId : firstSet) {
        for (long seconfStrutureId : secondSet) {
            if (firstStructureId == seconfStrutureId)
                throw new AssertionError("Structure ids are equal!");
        }
    }
}
Also used : LongHashSet(jetbrains.exodus.core.dataStructures.hash.LongHashSet) ITree(jetbrains.exodus.tree.ITree) LongIterator(jetbrains.exodus.tree.LongIterator)

Example 4 with LongIterator

use of jetbrains.exodus.tree.LongIterator in project xodus by JetBrains.

the class BTreeStructureIdTest method assertContains.

private void assertContains(long expectedId, long address) {
    ITree firstImTree = new BTree(log, address, false, 3);
    LongIterator it = firstImTree.addressIterator();
    while (it.hasNext()) Assert.assertEquals(expectedId, log.read(it.next()).getStructureId());
}
Also used : ITree(jetbrains.exodus.tree.ITree) LongIterator(jetbrains.exodus.tree.LongIterator)

Aggregations

LongIterator (jetbrains.exodus.tree.LongIterator)4 ITree (jetbrains.exodus.tree.ITree)2 LongHashSet (jetbrains.exodus.core.dataStructures.hash.LongHashSet)1