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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations