Search in sources :

Example 11 with TLongArrayList

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);
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList)

Example 12 with TLongArrayList

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 }));
}
Also used : CandidateCellForSweeping(com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping) ImmutableCandidateCellForSweeping(com.palantir.atlasdb.keyvalue.api.ImmutableCandidateCellForSweeping) TLongArrayList(gnu.trove.list.array.TLongArrayList) Test(org.junit.Test)

Example 13 with TLongArrayList

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();
    }
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList) TLongList(gnu.trove.list.TLongList) Nullable(javax.annotation.Nullable)

Example 14 with TLongArrayList

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;
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList)

Example 15 with TLongArrayList

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);
                    }
                }
            }
        }
    }
}
Also used : Relation(net.osmand.osm.edit.Relation) RelationMember(net.osmand.osm.edit.Relation.RelationMember) TLongArrayList(gnu.trove.list.array.TLongArrayList)

Aggregations

TLongArrayList (gnu.trove.list.array.TLongArrayList)28 ArrayList (java.util.ArrayList)5 TIntArrayList (gnu.trove.list.array.TIntArrayList)4 Test (org.junit.Test)4 CandidateCellForSweeping (com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping)3 ImmutableCandidateCellForSweeping (com.palantir.atlasdb.keyvalue.api.ImmutableCandidateCellForSweeping)3 TLongList (gnu.trove.list.TLongList)3 Relation (net.osmand.osm.edit.Relation)3 RelationMember (net.osmand.osm.edit.Relation.RelationMember)3 TByteArrayList (gnu.trove.list.array.TByteArrayList)2 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 IOException (java.io.IOException)2 Node (net.osmand.osm.edit.Node)2 Way (net.osmand.osm.edit.Way)2 RunMiXCR (com.milaboratory.mixcr.util.RunMiXCR)1 TLongIterator (gnu.trove.iterator.TLongIterator)1 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1 TFloatArrayList (gnu.trove.list.array.TFloatArrayList)1 TShortArrayList (gnu.trove.list.array.TShortArrayList)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1