Search in sources :

Example 1 with BSTEntry

use of ch.ethz.globis.phtree.v16.Node.BSTEntry in project phtree by tzaeschke.

the class PhTree16 method replace.

@Override
public boolean replace(long[] key, T oldValue, T newValue) {
    if (getRoot() == null) {
        return false;
    }
    Object o = getRoot();
    while (true) {
        Node currentNode = (Node) o;
        long hcPos = posInArray(key, currentNode.getPostLen());
        BSTEntry e = currentNode.getEntry(hcPos, key);
        if (e == null) {
            return false;
        }
        o = e.getValue();
        if (!(o instanceof Node)) {
            if (Objects.equals(maskNull(oldValue), o)) {
                e.setValue(maskNull(newValue));
                return true;
            }
            return false;
        }
    }
}
Also used : BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry)

Example 2 with BSTEntry

use of ch.ethz.globis.phtree.v16.Node.BSTEntry in project phtree by tzaeschke.

the class PhTree16 method putIfAbsent.

@Override
public T putIfAbsent(long[] key, T value) {
    if (getRoot() == null) {
        insertRoot(key, maskNull(value));
        return null;
    }
    Object o = getRoot();
    while (true) {
        Node currentNode = (Node) o;
        long hcPos = posInArray(key, currentNode.getPostLen());
        BSTEntry e = currentNode.getEntry(hcPos, key);
        if (e == null) {
            increaseNrEntries();
            currentNode.addEntry(hcPos, key, maskNull(value), this);
            return null;
        }
        o = e.getValue();
        if (!(o instanceof Node)) {
            return unmaskNull(o);
        }
    }
}
Also used : BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry)

Example 3 with BSTEntry

use of ch.ethz.globis.phtree.v16.Node.BSTEntry in project phtree by tzaeschke.

the class BSTIteratorAll method nextEntry.

public BSTEntry nextEntry() {
    if (!hasNextEntry()) {
        throw new NoSuchElementException();
    }
    BSTEntry ret = nextValue;
    findNext();
    return ret;
}
Also used : BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with BSTEntry

use of ch.ethz.globis.phtree.v16.Node.BSTEntry in project phtree by tzaeschke.

the class BSTIteratorMask method nextEntry.

public BSTEntry nextEntry() {
    if (!hasNextEntry()) {
        throw new NoSuchElementException();
    }
    BSTEntry ret = nextValue;
    findNext();
    return ret;
}
Also used : BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with BSTEntry

use of ch.ethz.globis.phtree.v16.Node.BSTEntry in project phtree by tzaeschke.

the class BSTreePage method findAndRemove.

public BSTEntry findAndRemove(long key, long[] kdKey, Node node, PhTree16.UpdateInfo ui) {
    // The stored value[i] is the min-values of the according page[i+1}
    int pos = binarySearchInnerNode(key);
    // read page before that value
    BSTreePage page = subPages[pos];
    BSTEntry result;
    if (page.isLeaf()) {
        result = page.remove(key, kdKey, node, ui);
        checkUnderflowSubpageLeaf(pos, node);
    } else {
        result = page.findAndRemove(key, kdKey, node, ui);
        handleUnderflowSubInner(pos);
    }
    return result;
}
Also used : BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry)

Aggregations

BSTEntry (ch.ethz.globis.phtree.v16.Node.BSTEntry)26 BSTIteratorAll (ch.ethz.globis.phtree.v16.bst.BSTIteratorAll)7 Node (ch.ethz.globis.phtree.v16.Node)6 BSTIteratorMask (ch.ethz.globis.phtree.v16.bst.BSTIteratorMask)4 BSTreePage (ch.ethz.globis.phtree.v16.bst.BSTreePage)2 NoSuchElementException (java.util.NoSuchElementException)2 Random (java.util.Random)2 Test (org.junit.Test)2 REMOVE_OP (ch.ethz.globis.phtree.v16.Node.REMOVE_OP)1 ArrayList (java.util.ArrayList)1