use of gnu.trove.list.array.TLongArrayList in project Osmand by osmandapp.
the class Way method addNode.
public void addNode(Node n, int index) {
if (nodeIds == null) {
nodeIds = new TLongArrayList();
}
if (nodes == null) {
nodes = new ArrayList<Node>();
}
nodeIds.insert(index, n.getId());
nodes.add(index, n);
}
use of gnu.trove.list.array.TLongArrayList in project atlasdb by palantir.
the class SweepableCellFilterTest method thorough_getTimestampsToSweep_oneTransaction_emptyValue_returnsIt.
@Test
public void thorough_getTimestampsToSweep_oneTransaction_emptyValue_returnsIt() {
List<CandidateCellForSweeping> candidate = ImmutableList.of(ImmutableCandidateCellForSweeping.builder().cell(SINGLE_CELL).sortedTimestamps(ImmutableList.of(LOW_START_TS)).isLatestValueEmpty(true).build());
when(mockTransactionService.get(anyCollection())).thenReturn(ImmutableMap.of(LOW_START_TS, LOW_COMMIT_TS));
SweepableCellFilter filter = new SweepableCellFilter(mockTransactionService, Sweeper.THOROUGH, HIGH_START_TS);
List<CellToSweep> cells = filter.getCellsToSweep(candidate).cells();
assertThat(cells.size()).isEqualTo(1);
assertThat(Iterables.getOnlyElement(cells).sortedTimestamps()).isEqualTo(new TLongArrayList(new long[] { LOW_START_TS }));
}
use of gnu.trove.list.array.TLongArrayList in project atlasdb by palantir.
the class SweepableCellFilter method getCellToSweep.
// Decide if the candidate cell needs to be swept, and if so, for which timestamps.
@Nullable
private CellToSweep getCellToSweep(CandidateCellForSweeping candidate, CommitTsLoader commitTss) {
Preconditions.checkArgument(candidate.sortedTimestamps().size() > 0);
TLongList timestampsToSweep = new TLongArrayList();
TLongList uncommittedTimestamps = new TLongArrayList();
long maxStartTs = TransactionConstants.FAILED_COMMIT_TS;
boolean maxStartTsIsCommitted = false;
for (long startTs : candidate.sortedTimestamps()) {
long commitTs = commitTss.load(startTs);
if (startTs > maxStartTs && commitTs < sweepTs) {
maxStartTs = startTs;
maxStartTsIsCommitted = commitTs != TransactionConstants.FAILED_COMMIT_TS;
}
// passing condition (1)
if (commitTs > 0 && commitTs < sweepTs) {
timestampsToSweep.add(startTs);
} else if (commitTs == TransactionConstants.FAILED_COMMIT_TS) {
uncommittedTimestamps.add(startTs);
}
}
boolean needsSentinel = sweeper.shouldAddSentinels() && timestampsToSweep.size() > 1;
boolean shouldSweepLastCommitted = sweeper.shouldSweepLastCommitted() && candidate.isLatestValueEmpty() && maxStartTsIsCommitted;
if (!timestampsToSweep.isEmpty() && !shouldSweepLastCommitted) {
timestampsToSweep.removeAt(timestampsToSweep.size() - 1);
}
timestampsToSweep.addAll(uncommittedTimestamps);
if (timestampsToSweep.isEmpty()) {
return null;
} else {
return ImmutableCellToSweep.builder().cell(candidate.cell()).sortedTimestamps(timestampsToSweep).needsSentinel(needsSentinel).build();
}
}
use of gnu.trove.list.array.TLongArrayList in project mixcr by milaboratory.
the class ClnAWriter method writeAlignmentsAndIndex.
/**
* Step 3
*/
public synchronized void writeAlignmentsAndIndex() {
// Checking state
if (sortedAlignments == null)
throw new IllegalStateException("Call sortAlignments before this method.");
if (finished)
throw new IllegalStateException("Writer already closed.");
// Indices that will be written below all alignments
TLongArrayList aBlockOffset = new TLongArrayList();
TLongArrayList aBlockCount = new TLongArrayList();
// Position of alignments with cloneIndex = -1 (not aligned alignments)
aBlockOffset.add(outputStream.getByteCount());
long previousAlsCount = 0;
int currentCloneIndex = -1;
// Writing alignments and writing indices
for (VDJCAlignments alignments : CUtils.it(sortedAlignments)) {
if (currentCloneIndex != alignments.cloneIndex) {
++currentCloneIndex;
if (currentCloneIndex != alignments.cloneIndex)
throw new IllegalArgumentException("No alignments for clone number " + currentCloneIndex);
if (alignments.cloneIndex >= numberOfClones)
throw new IllegalArgumentException("Out of range clone Index in alignment: " + currentCloneIndex);
aBlockOffset.add(outputStream.getByteCount());
aBlockCount.add(numberOfAlignmentsWritten - previousAlsCount);
previousAlsCount = numberOfAlignmentsWritten;
}
output.writeObject(alignments);
++numberOfAlignmentsWritten;
}
// Closing sorted output port, this will delete presorted file
sortedAlignments.close();
// Writing count of alignments in the last block
aBlockCount.add(numberOfAlignmentsWritten - previousAlsCount);
// Writing position of last alignments block end
aBlockOffset.add(outputStream.getByteCount());
// To make counts index the same length as aBlockOffset
aBlockCount.add(0);
// Saving index offset in file to write in the end of stream
long indexBeginOffset = outputStream.getByteCount();
long previousValue = 0;
// Writing both indices
for (int i = 0; i < aBlockOffset.size(); i++) {
long iValue = aBlockOffset.get(i);
// Writing offset index using deltas to save space
// (smaller values are represented by less number of bytes in VarLong representation)
output.writeVarLong(iValue - previousValue);
previousValue = iValue;
output.writeVarLong(aBlockCount.get(i));
}
// Writing two key positions in a file
// This values will be using during deserialization to find certain blocks
output.writeLong(positionOfFirstClone);
output.writeLong(indexBeginOffset);
// Setting finished flag (will stop progress reporting)
finished = true;
}
use of gnu.trove.list.array.TLongArrayList in project OsmAnd-tools by osmandapp.
the class IndexRouteCreator method indexHighwayRestrictions.
private void indexHighwayRestrictions(Entity e, OsmDbAccessorContext ctx) throws SQLException {
if (e instanceof Relation && "restriction".equals(e.getTag(OSMTagKey.TYPE))) {
// $NON-NLS-1$
// $NON-NLS-1$
String val = e.getTag("restriction");
if (val != null) {
if ("no_u_turn".equalsIgnoreCase(val) && Algorithms.objectEquals(e.getTag("from"), e.getTag("to"))) {
// don't index such roads - can't go through issue https://www.openstreetmap.org/way/338099991#map=17/46.86699/-0.20473
return;
}
byte type = -1;
if ("no_right_turn".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_NO_RIGHT_TURN;
} else if ("no_left_turn".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_NO_LEFT_TURN;
} else if ("no_u_turn".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_NO_U_TURN;
} else if ("no_straight_on".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_NO_STRAIGHT_ON;
} else if ("only_right_turn".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_ONLY_RIGHT_TURN;
} else if ("only_left_turn".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_ONLY_LEFT_TURN;
} else if ("only_straight_on".equalsIgnoreCase(val)) {
// $NON-NLS-1$
type = MapRenderingTypes.RESTRICTION_ONLY_STRAIGHT_ON;
}
if (type != -1) {
ctx.loadEntityRelation((Relation) e);
// $NON-NLS-1$
Collection<RelationMember> fromL = ((Relation) e).getMembers("from");
// $NON-NLS-1$
Collection<RelationMember> toL = ((Relation) e).getMembers("to");
if (!fromL.isEmpty() && !toL.isEmpty()) {
RelationMember from = fromL.iterator().next();
RelationMember to = toL.iterator().next();
if (from.getEntityId().getType() == EntityType.WAY) {
if (!highwayRestrictions.containsKey(from.getEntityId().getId())) {
highwayRestrictions.put(from.getEntityId().getId(), new TLongArrayList());
}
highwayRestrictions.get(from.getEntityId().getId()).add((to.getEntityId().getId() << 3) | (long) type);
}
}
}
}
}
}
Aggregations