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