Search in sources :

Example 71 with Node

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

the class NodeTreeV11 method addEntry.

@SuppressWarnings("unchecked")
public static <T> T addEntry(NtNode<T> root, long hcPos, long[] kdKey, Object value, Node phNode) {
    NtNode<T> currentNode = root;
    while (true) {
        long localHcPos = NtNode.pos2LocalPos(hcPos, currentNode.getPostLen());
        int pin = currentNode.getPosition(localHcPos, NtNode.MAX_DIM);
        if (pin < 0) {
            // insert
            currentNode.localAddEntryPIN(pin, localHcPos, hcPos, kdKey, value);
            incCounter(phNode);
            return null;
        }
        Object localVal = currentNode.getValueByPIN(pin);
        boolean isSubNode = localVal instanceof NtNode;
        long postInFix;
        int conflictingLevels;
        NtNode<T> sub = null;
        if (isSubNode) {
            sub = (NtNode<T>) localVal;
            // check infix if infixLen > 0
            if (currentNode.getPostLen() - sub.getPostLen() > 1) {
                postInFix = currentNode.localReadInfix(pin, localHcPos);
                conflictingLevels = NtNode.getConflictingLevels(hcPos, postInFix, currentNode.getPostLen(), sub.getPostLen());
            } else {
                postInFix = 0;
                conflictingLevels = 0;
            }
        } else {
            postInFix = currentNode.localReadPostfix(pin, localHcPos);
            // long mask = ~((-1L) << (currentNode.getPostLen()*NtNode.MAX_DIM));
            // conflictingLevels = NtNode.getMaxConflictingLevelsWithMask(hcPos, postInFix, mask);
            // TODO
            conflictingLevels = NtNode.getConflictingLevels(hcPos, postInFix, currentNode.getPostLen());
        }
        if (conflictingLevels != 0) {
            int newPostLen = conflictingLevels - 1;
            NtNode<T> newNode = NtNode.createNode(newPostLen, kdKey.length);
            currentNode.localReplaceEntryWithSub(pin, localHcPos, hcPos, newNode);
            long localHcInSubOfNewEntry = NtNode.pos2LocalPos(hcPos, newPostLen);
            long localHcInSubOfPrevEntry = NtNode.pos2LocalPos(postInFix, newPostLen);
            // TODO assume pin=0 for first entry?
            newNode.localAddEntry(localHcInSubOfNewEntry, hcPos, kdKey, value);
            long[] localKdKey = new long[kdKey.length];
            currentNode.readKdKeyPIN(pin, localKdKey);
            newNode.localAddEntry(localHcInSubOfPrevEntry, postInFix, localKdKey, localVal);
            incCounter(phNode);
            return null;
        }
        if (isSubNode) {
            // traverse subNode
            currentNode = sub;
        } else {
            // external postfix is not checked
            if (phNode == null) {
                return (T) currentNode.localReplaceEntry(pin, kdKey, value);
            } else {
                if (localVal instanceof Node) {
                    Node subNode = (Node) localVal;
                    // TODO
                    // TODO
                    // TODO
                    // if (hasSubInfix(offs, dims)) {
                    long mask = phNode.calcInfixMask(subNode.getPostLen());
                    return (T) insertSplitPH(kdKey, value, localVal, pin, mask, currentNode, phNode);
                // }
                // return v;
                } else {
                    if (phNode.getPostLen() > 0) {
                        long mask = phNode.calcPostfixMask();
                        return (T) insertSplitPH(kdKey, value, localVal, pin, mask, currentNode, phNode);
                    }
                    // perfect match -> replace value
                    currentNode.localReplaceValue(pin, value);
                    return (T) value;
                }
            }
        }
    }
}
Also used : Node(ch.ethz.globis.phtree.v11.Node)

Example 72 with Node

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

the class TestBST16compute method testEmpty.

@Test
public void testEmpty() {
    Node ht = create();
    checkEmpty(ht);
}
Also used : Node(ch.ethz.globis.phtree.v16.Node) Test(org.junit.Test)

Example 73 with Node

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

the class TestBST16compute 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);
        ht.bstCompute((int) i.getValue(), i.getKdKey(), tree, true, (longs, o) -> {
            assertSame(i.getKdKey(), longs);
            assertNull(o);
            // TODO clone 'i'?
            return 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() - 1) & 0xFFFFFFFE));
    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()));
        ht.bstCompute((Integer) i.getValue(), i.getKdKey(), tree, true, (longs, o) -> -(Integer) i.getValue());
    }
    long l32 = System.currentTimeMillis();
    assertEquals(list.size(), ht.getEntryCount());
    // remove some
    long l41 = System.currentTimeMillis();
    boolean[] found = new boolean[1];
    for (BSTEntry i : list) {
        found[0] = false;
        ht.bstCompute((Integer) i.getValue(), i.getKdKey(), tree, true, (longs, o) -> {
            found[0] = true;
            return null;
        });
        assertTrue(found[0]);
    }
    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)

Example 74 with Node

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

the class TestBST16compute method testEmptyAfterLoad.

@Test
public void testEmptyAfterLoad() {
    Node ht = create();
    for (int r = 0; r < 10; r++) {
        for (int i = 0; i < 100000; i++) {
            BSTEntry e = ht.bstGetOrCreate(i, tree);
            e.set(i, new long[] { i }, i);
        }
        for (int i = 0; i < 100000; i++) {
            BSTEntry e = ht.bstRemove(i, new long[] { i }, null, tree);
            assertEquals(i, (int) e.getValue());
        }
        checkEmpty(ht);
    }
}
Also used : BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry) Node(ch.ethz.globis.phtree.v16.Node) Test(org.junit.Test)

Example 75 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project openhab-addons by openhab.

the class HomieChildMapTests method testArrayToSubtopicCreateAndRemove.

@Test
public void testArrayToSubtopicCreateAndRemove() {
    AddedAction addedAction = spy(new AddedAction());
    // Assign "abc,def" to the
    subject.apply(new String[] { "abc", "def" }, addedAction, this::createNode, this::removedNode);
    assertThat(future.isDone(), is(true));
    assertThat(subject.get("abc").nodeID, is("abc"));
    assertThat(subject.get("def").nodeID, is("def"));
    verify(addedAction, times(2)).apply(any());
    Node soonToBeRemoved = subject.get("def");
    subject.apply(new String[] { "abc" }, addedAction, this::createNode, this::removedNode);
    verify(callback).nodeRemoved(eq(soonToBeRemoved));
}
Also used : Node(org.openhab.binding.mqtt.homie.internal.homie300.Node) Test(org.junit.jupiter.api.Test)

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