Search in sources :

Example 81 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.

the class CHTurnCostTest method testFindPath_pTurn_uTurnAtContractedNode_twoShortcutsInAndOut.

@Test
public void testFindPath_pTurn_uTurnAtContractedNode_twoShortcutsInAndOut() {
    // 2- 3
    // |  |
    // 4- 0
    // |
    // 1
    // |
    // 5 ->  6 -> 7
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(5, 6).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(6, 7).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 1).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 4).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(4, 0).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 3).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 2).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 4).setDistance(1));
    graph.freeze();
    setRestriction(5, 6, 7);
    final IntArrayList expectedPath = IntArrayList.from(5, 6, 1, 4, 0, 3, 2, 4, 1, 6, 7);
    checkPath(expectedPath, 10, 0, 5, 7, new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 82 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.

the class QueryGraphTest method testEnforceHeading.

@Test
public void testEnforceHeading() {
    // setup graph
    // ____
    // |    |
    // x    |
    // |    |
    // 0    1
    NodeAccess na = g.getNodeAccess();
    na.setNode(0, 0, 0);
    na.setNode(1, 0, 2);
    GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(10)).setWayGeometry(Helper.createPointList(2, 0, 2, 2));
    EdgeIteratorState edge = GHUtility.getEdge(g, 0, 1);
    // snap on first vertical part of way (upward, base is in south)
    Snap snap = fakeEdgeSnap(edge, 1.5, 0, 0);
    QueryGraph queryGraph = lookup(snap);
    // enforce going out north
    HeadingResolver headingResolver = new HeadingResolver(queryGraph);
    IntArrayList unfavoredEdges = headingResolver.getEdgesWithDifferentHeading(snap.getClosestNode(), 0);
    queryGraph.unfavorVirtualEdges(unfavoredEdges);
    // test penalized south
    boolean expect = true;
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(1, 2)));
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(1, 0)));
    queryGraph.clearUnfavoredStatus();
    // test cleared edges south
    expect = false;
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(1, 2)));
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(1, 0)));
    // enforce going south (same as coming in from north)
    unfavoredEdges = headingResolver.getEdgesWithDifferentHeading(snap.getClosestNode(), 180);
    queryGraph.unfavorVirtualEdges(unfavoredEdges);
    // test penalized north
    expect = true;
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(2, 1)));
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(2, 2)));
    // snap on second vertical part of way (downward, base is in north)
    // ____
    // |    |
    // |    x
    // |    |
    // 0    1
    snap = fakeEdgeSnap(edge, 1.5, 2, 2);
    queryGraph = lookup(Arrays.asList(snap));
    // enforce north
    unfavoredEdges = headingResolver.getEdgesWithDifferentHeading(snap.getClosestNode(), 180);
    queryGraph.unfavorVirtualEdges(unfavoredEdges);
    // test penalized south
    expect = true;
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(2, 1)));
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(2, 2)));
    queryGraph.clearUnfavoredStatus();
    // enforce south
    unfavoredEdges = headingResolver.getEdgesWithDifferentHeading(snap.getClosestNode(), 0);
    queryGraph.unfavorVirtualEdges(unfavoredEdges);
    // test penalized north
    expect = true;
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(1, 0)));
    assertEquals(expect, isAvoidEdge(queryGraph.getEdgeIteratorState(1, 2)));
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) Snap(com.graphhopper.storage.index.Snap) HeadingResolver(com.graphhopper.routing.HeadingResolver) Test(org.junit.jupiter.api.Test)

Example 83 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.

the class BinaryHeapTestInterface method pollSorted.

@Test
default void pollSorted() {
    create(10);
    push(9, 3.6f);
    push(5, 2.1f);
    push(3, 2.3f);
    push(8, 5.7f);
    push(7, 2.2f);
    IntArrayList polled = new IntArrayList();
    while (!isEmpty()) {
        polled.add(poll());
    }
    assertEquals(IntArrayList.from(5, 7, 3, 9, 8), polled);
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) Test(org.junit.jupiter.api.Test)

Example 84 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project baseio by generallycloud.

the class NioEventLoop method remove_closed_channels.

private void remove_closed_channels() {
    IntArrayList c_list = this.close_channels;
    IntObjectMap<Channel> channels = this.channels;
    if (!c_list.isEmpty()) {
        for (int i = 0; i < c_list.size(); i++) {
            Channel ch = channels.remove(c_list.get(i));
            if (ch.isOpen()) {
                channels.put(ch.getFd(), ch);
            }
        }
        c_list.clear();
        int keys_length = channels.keys.length;
        if (keys_length >= CHANNELS_COMPACT_SIZE) {
            if (channels.size() < keys_length >>> 3) {
                int map_size = Math.max(CHANNELS_COMPACT_SIZE >>> 2, channels.size());
                IntObjectMap<Channel> new_channels = new IntObjectMap<>(map_size);
                new_channels.putAll(channels);
                this.channels = new_channels;
            }
        }
    }
}
Also used : IntObjectMap(com.firenio.collection.IntObjectMap) SocketChannel(java.nio.channels.SocketChannel) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 85 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project crate by crate.

the class FetchRows method create.

public static FetchRows create(TransactionContext txnCtx, NodeContext nodeCtx, Map<RelationName, FetchSource> fetchSourceByTable, List<Symbol> outputSymbols) {
    IntArrayList fetchIdPositions = new IntArrayList();
    ArrayList<Object[]> nullRows = new ArrayList<>();
    IntObjectHashMap<UnsafeArrayRow> fetchedRows = new IntObjectHashMap<>();
    for (var fetchSource : fetchSourceByTable.values()) {
        Object[] nullRow = new Object[fetchSource.references().size()];
        for (InputColumn ic : fetchSource.fetchIdCols()) {
            fetchIdPositions.add(ic.index());
            nullRows.add(nullRow);
            fetchedRows.put(ic.index(), new UnsafeArrayRow());
        }
    }
    final UnsafeArrayRow inputRow = new UnsafeArrayRow();
    var visitor = new BaseImplementationSymbolVisitor<Void>(txnCtx, nodeCtx) {

        @Override
        public Input<?> visitInputColumn(final InputColumn inputColumn, final Void context) {
            final int idx = inputColumn.index();
            return () -> inputRow.get(idx);
        }

        @Override
        public Input<?> visitFetchReference(final FetchReference fetchReference, final Void context) {
            var ref = fetchReference.ref();
            UnsafeArrayRow row = fetchedRows.get(fetchReference.fetchId().index());
            int posInFetchedRow = fetchSourceByTable.get(ref.ident().tableIdent()).references().indexOf(ref);
            return () -> row.get(posInFetchedRow);
        }
    };
    List<Input<?>> outputExpressions = Lists2.map(outputSymbols, x -> x.accept(visitor, null));
    return new FetchRows(fetchIdPositions, outputExpressions, inputRow, fetchedRows, nullRows);
}
Also used : IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) ArrayList(java.util.ArrayList) IntArrayList(com.carrotsearch.hppc.IntArrayList) BaseImplementationSymbolVisitor(io.crate.expression.BaseImplementationSymbolVisitor) Input(io.crate.data.Input) UnsafeArrayRow(io.crate.data.UnsafeArrayRow) InputColumn(io.crate.expression.symbol.InputColumn) FetchReference(io.crate.expression.symbol.FetchReference) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Aggregations

IntArrayList (com.carrotsearch.hppc.IntArrayList)94 Test (org.junit.jupiter.api.Test)16 RepeatedTest (org.junit.jupiter.api.RepeatedTest)13 GHPoint (com.graphhopper.util.shapes.GHPoint)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)7 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)5 HashMap (java.util.HashMap)5 UUID (java.util.UUID)5 GHIntArrayList (com.graphhopper.coll.GHIntArrayList)4 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)4 RelationName (io.crate.metadata.RelationName)4 IOException (java.io.IOException)4 IntObjectMap (com.carrotsearch.hppc.IntObjectMap)3 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)3 PrepEdgeFilter (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)3