Search in sources :

Example 51 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project phtree by tzaeschke.

the class BSTreePage method computeLeaf.

public <T> Object computeLeaf(long key, long[] kdKey, int posInParent, Node node, boolean doIfAbsent, BiFunction<long[], ? super T, ? extends T> mappingFunction) {
    int pos = binarySearch(key);
    if (pos < 0) {
        // key not found
        if (doIfAbsent) {
            T newValue = mappingFunction.apply(kdKey, null);
            if (newValue != null) {
                BSTEntry e = addForCompute(key, pos, posInParent, node);
                e.set(key, kdKey, newValue);
                return newValue;
            }
        }
        return null;
    }
    BSTEntry currentEntry = values[pos];
    Object currentValue = currentEntry.getValue();
    if (currentValue instanceof Node) {
        if (((Node) currentValue).getInfixLen() == 0) {
            // Shortcut that avoid MCB calculation: No infix conflict, just traverse the subnode (=currentValue)
            return currentValue;
        }
    }
    long[] localKdKey = currentEntry.getKdKey();
    int maxConflictingBits = Node.calcConflictingBits(kdKey, localKdKey);
    if (maxConflictingBits == 0) {
        if (currentValue instanceof Node) {
            // return entry with subnode
            return currentValue;
        }
        T newValue = mappingFunction.apply(kdKey, PhTreeHelper.unmaskNull(currentEntry.getValue()));
        if (newValue == null) {
            // remove
            removeForCompute(key, pos, posInParent, node);
            tree.bstPool().offerEntry(currentEntry);
            return null;
        } else {
            // replace (cannot be null)
            currentEntry.setValue(newValue);
        }
        return newValue;
    }
    if (currentValue instanceof Node) {
        Node subNode = (Node) currentValue;
        if (subNode.getPostLen() + 1 >= maxConflictingBits) {
            return subNode;
        }
    }
    // Key found, but entry does not match
    if (doIfAbsent) {
        // We have two entries in the same location (local hcPos).
        // If the kdKey differs, we have to split, insert a newSubNode and return null.
        T newValue = mappingFunction.apply(kdKey, null);
        if (newValue != null) {
            insertSplit(currentEntry, kdKey, newValue, tree, maxConflictingBits, node);
            return newValue;
        }
        return null;
    }
    // Return 'null' when ignoring absent values
    return null;
}
Also used : BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry) Node(ch.ethz.globis.phtree.v16.Node)

Example 52 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project phtree by tzaeschke.

the class BSTreePage method insertSplit.

private void insertSplit(BSTEntry currentEntry, long[] newKey, Object newValue, PhTree16<?> tree, int maxConflictingBits, Node node) {
    long[] localKdKey = currentEntry.getKdKey();
    Node newNode = node.createNode(newKey, newValue, localKdKey, currentEntry.getValue(), maxConflictingBits, tree);
    // replace local entry with new subnode
    currentEntry.set(currentEntry.getKey(), tree.longPool().arrayClone(localKdKey), newNode);
    Node.incEntryCountTree(tree);
}
Also used : Node(ch.ethz.globis.phtree.v16.Node)

Example 53 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project phtree by tzaeschke.

the class NodeTreeV11 method insertSplitPH.

private static Object insertSplitPH(long[] newKey, Object newValue, Object currentValue, int pin, long mask, NtNode<?> currentNode, Node phNode) {
    long[] localKdKey = new long[newKey.length];
    currentNode.readKdKeyPIN(pin, localKdKey);
    int maxConflictingBits = Node.calcConflictingBits(newKey, localKdKey, mask);
    if (maxConflictingBits == 0) {
        if (!(currentValue instanceof Node)) {
            currentNode.localReplaceValue(pin, newValue);
        }
        return currentValue;
    }
    Node newNode = phNode.createNode(newKey, newValue, localKdKey, currentValue, maxConflictingBits);
    currentNode.localReplaceEntry(pin, newKey, newNode);
    // entry did not exist
    return null;
}
Also used : Node(ch.ethz.globis.phtree.v11.Node)

Example 54 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project phtree by tzaeschke.

the class NodeTreeV11 method phGetIfKdMatches.

private static Object phGetIfKdMatches(long[] keyToMatch, NtNode<?> currentNodeNt, int pinNt, Object currentVal, Node phNode) {
    if (currentVal instanceof Node) {
        Node sub = (Node) currentVal;
        // if (hasSubInfix(offs, dims)) {
        final long mask = phNode.calcInfixMask(sub.getPostLen());
        if (!currentNodeNt.readKdKeyAndCheck(pinNt, keyToMatch, mask)) {
            // no match
            return null;
        }
        // }
        return currentVal;
    } else {
        final long mask = phNode.calcPostfixMask();
        if (!currentNodeNt.readKdKeyAndCheck(pinNt, keyToMatch, mask)) {
            // no match
            return null;
        }
        // We simply remove it an l;ett Node handle the merging, if required.
        return currentVal;
    }
}
Also used : Node(ch.ethz.globis.phtree.v11.Node)

Example 55 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project phtree by tzaeschke.

the class TestBST16 method runTest.

private void runTest(List<BSTEntry> list, String prefix) {
    Node ht = create();
    // populate
    long l11 = System.currentTimeMillis();
    for (BSTEntry i : list) {
        // if (i%1000 == 0)
        // System.out.println("ins=" + i);
        // ht.bstPut((Integer)i.getValue(), i);
        BSTEntry newBE = ht.bstGetOrCreate((int) i.getValue(), tree);
        newBE.set((int) i.getValue(), i.getKdKey(), i.getValue());
        // Check
        BSTEntry be = ht.bstGet((Integer) i.getValue());
        assertEquals((int) i.getValue(), (int) be.getValue());
    }
    long l12 = System.currentTimeMillis();
    assertEquals(list.size(), ht.getEntryCount());
    // println(ht.getStats().toString());
    // lookup
    long l21 = System.currentTimeMillis();
    for (BSTEntry i : list) {
        BSTEntry e = ht.bstGet((Integer) i.getValue());
        // assertNotNull("i=" + i, e);
        int x = (int) e.getValue();
        assertEquals(i.getValue(), x);
    }
    long l22 = System.currentTimeMillis();
    // iterate
    long l51 = System.currentTimeMillis();
    BSTIteratorAll iter = ht.iterator();
    long prev = -1;
    while (iter.hasNextEntry()) {
        long current = iter.nextEntry().getKey();
        assertEquals(prev + 1, current);
        prev = current;
    }
    assertEquals(prev, list.size() - 1);
    long l52 = System.currentTimeMillis();
    long l61 = System.currentTimeMillis();
    BSTIteratorMask iterMask = new BSTIteratorMask().reset(ht.getRoot(), 0, 0xFFFFFFFFFFFEL, ht.getEntryCount());
    prev = -2;
    while (iterMask.hasNextEntry()) {
        long current = iterMask.nextEntry().getKey();
        assertEquals(prev + 2, current);
        prev = current;
    }
    assertEquals(prev, list.size() - 2);
    long l62 = System.currentTimeMillis();
    // replace some
    long l31 = System.currentTimeMillis();
    for (BSTEntry i : list) {
        // ht.bstPut((Integer)i.getValue(), new BSTEntry(i.getKdKey(), -(Integer)i.getValue()));
        BSTEntry newBE = ht.bstGetOrCreate((Integer) i.getValue(), tree);
        newBE.setValue(-(Integer) i.getValue());
    }
    long l32 = System.currentTimeMillis();
    assertEquals(list.size(), ht.getEntryCount());
    // remove some
    long l41 = System.currentTimeMillis();
    for (BSTEntry i : list) {
        assertEquals(-(Integer) i.getValue(), ht.bstRemove((Integer) i.getValue(), i.getKdKey(), null, tree).getValue());
    }
    long l42 = System.currentTimeMillis();
    assertEquals(0, ht.getEntryCount());
    println(prefix + "Load: " + (l12 - l11));
    println(prefix + "Get:  " + (l22 - l21));
    println(prefix + "Iter: " + (l52 - l51));
    println(prefix + "IterM:" + (l62 - l61));
    println(prefix + "Load: " + (l32 - l31));
    println(prefix + "Rem : " + (l42 - l41));
    println();
}
Also used : BSTIteratorMask(ch.ethz.globis.phtree.v16.bst.BSTIteratorMask) BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry) BSTIteratorAll(ch.ethz.globis.phtree.v16.bst.BSTIteratorAll) Node(ch.ethz.globis.phtree.v16.Node)

Aggregations

Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)52 Test (org.junit.Test)27 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)26 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)21 Date (java.util.Date)18 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)17 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)16 Node (org.flyte.api.v1.Node)15 Test (org.junit.jupiter.api.Test)15 ArrayList (java.util.ArrayList)14 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)14 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)13 TaskNode (org.flyte.api.v1.TaskNode)10 Bound (org.openstreetmap.osmosis.core.domain.v0_6.Bound)10 List (java.util.List)9 Map (java.util.Map)9 Node (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node)9 Node (org.openhab.binding.mqtt.homie.internal.homie300.Node)9 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)9 Node (ch.ethz.globis.phtree.v16.Node)8