Search in sources :

Example 36 with IntArrayList

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

the class ArrayUtil method withoutConsecutiveDuplicates.

/**
 * Creates a copy of the given list where all consecutive duplicates are removed
 */
public static IntIndexedContainer withoutConsecutiveDuplicates(IntIndexedContainer arr) {
    IntArrayList result = new IntArrayList();
    if (arr.isEmpty())
        return result;
    int prev = arr.get(0);
    result.add(prev);
    for (int i = 1; i < arr.size(); i++) {
        int val = arr.get(i);
        if (val != prev)
            result.add(val);
        prev = val;
    }
    return result;
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 37 with IntArrayList

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

the class ArrayUtil method constant.

/**
 * Creates an IntArrayList of a given size where each element is set to the given value
 */
public static IntArrayList constant(int size, int value) {
    IntArrayList result = new IntArrayList(size);
    Arrays.fill(result.buffer, value);
    result.elementsCount = size;
    return result;
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 38 with IntArrayList

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

the class ArrayUtil method range.

/**
 * Creates an IntArrayList filled with the integers [startIncl,endExcl[
 */
public static IntArrayList range(int startIncl, int endExcl) {
    IntArrayList result = new IntArrayList(endExcl - startIncl);
    result.elementsCount = endExcl - startIncl;
    for (int i = 0; i < result.size(); ++i) result.set(i, startIncl + i);
    return result;
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 39 with IntArrayList

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

the class ArrayUtil method invert.

public static IntArrayList invert(IntArrayList list) {
    IntArrayList result = new IntArrayList(list.size());
    result.elementsCount = list.size();
    for (int i = 0; i < result.elementsCount; ++i) result.set(list.get(i), i);
    return result;
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 40 with IntArrayList

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

the class GHUtility method sortDFS.

/**
 * Sorts the graph according to depth-first search traversal. Other traversals have either no
 * significant difference (bfs) for querying or are worse (z-curve).
 */
public static Graph sortDFS(Graph g, Graph sortedGraph) {
    if (g.getTurnCostStorage() != null) {
        throw new IllegalArgumentException("Sorting the graph is currently not supported in the presence of turn costs");
    }
    int nodes = g.getNodes();
    final IntArrayList nodeList = ArrayUtil.constant(nodes, -1);
    final GHBitSetImpl nodeBitset = new GHBitSetImpl(nodes);
    final AtomicInteger nodeRef = new AtomicInteger(-1);
    int edges = g.getEdges();
    final IntArrayList edgeList = ArrayUtil.constant(edges, -1);
    final GHBitSetImpl edgeBitset = new GHBitSetImpl(edges);
    final AtomicInteger edgeRef = new AtomicInteger(-1);
    EdgeExplorer explorer = g.createEdgeExplorer();
    for (int startNode = 0; startNode >= 0 && startNode < nodes; startNode = nodeBitset.nextClear(startNode + 1)) {
        new DepthFirstSearch() {

            @Override
            protected GHBitSet createBitSet() {
                return nodeBitset;
            }

            @Override
            protected boolean checkAdjacent(EdgeIteratorState edge) {
                int edgeId = edge.getEdge();
                if (!edgeBitset.contains(edgeId)) {
                    edgeBitset.add(edgeId);
                    edgeList.set(edgeRef.incrementAndGet(), edgeId);
                }
                return super.checkAdjacent(edge);
            }

            @Override
            protected boolean goFurther(int nodeId) {
                nodeList.set(nodeId, nodeRef.incrementAndGet());
                return super.goFurther(nodeId);
            }
        }.start(explorer, startNode);
    }
    return createSortedGraph(g, sortedGraph, nodeList, edgeList);
}
Also used : GHBitSetImpl(com.graphhopper.coll.GHBitSetImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GHBitSet(com.graphhopper.coll.GHBitSet) 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