use of gnu.trove.list.array.TLongArrayList in project Osmand by osmandapp.
the class BinaryMapRouteReaderAdapter method readRouteTreeData.
private void readRouteTreeData(RouteSubregion routeTree, TLongArrayList idTables, TLongObjectHashMap<TLongArrayList> restrictions) throws IOException {
routeTree.dataObjects = new ArrayList<RouteDataObject>();
idTables.clear();
restrictions.clear();
List<String> stringTable = null;
while (true) {
int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t);
switch(tag) {
case 0:
TLongObjectIterator<TLongArrayList> it = restrictions.iterator();
while (it.hasNext()) {
it.advance();
int from = (int) it.key();
RouteDataObject fromr = routeTree.dataObjects.get(from);
fromr.restrictions = new long[it.value().size()];
for (int k = 0; k < fromr.restrictions.length; k++) {
int to = (int) (it.value().get(k) >> RouteDataObject.RESTRICTION_SHIFT);
long valto = (idTables.get(to) << RouteDataObject.RESTRICTION_SHIFT) | ((long) it.value().get(k) & RouteDataObject.RESTRICTION_MASK);
fromr.restrictions[k] = valto;
}
}
for (RouteDataObject o : routeTree.dataObjects) {
if (o != null) {
if (o.id < idTables.size()) {
o.id = idTables.get((int) o.id);
}
if (o.names != null && stringTable != null) {
int[] keys = o.names.keys();
for (int j = 0; j < keys.length; j++) {
o.names.put(keys[j], stringTable.get(o.names.get(keys[j]).charAt(0)));
}
}
if (o.pointNames != null && stringTable != null) {
for (String[] ar : o.pointNames) {
if (ar != null) {
for (int j = 0; j < ar.length; j++) {
ar[j] = stringTable.get(ar[j].charAt(0));
}
}
}
}
}
}
return;
case RouteDataBlock.DATAOBJECTS_FIELD_NUMBER:
int length = codedIS.readRawVarint32();
int oldLimit = codedIS.pushLimit(length);
RouteDataObject obj = readRouteDataObject(routeTree.routeReg, routeTree.left, routeTree.top);
while (obj.id >= routeTree.dataObjects.size()) {
routeTree.dataObjects.add(null);
}
routeTree.dataObjects.set((int) obj.id, obj);
codedIS.popLimit(oldLimit);
break;
case RouteDataBlock.IDTABLE_FIELD_NUMBER:
long routeId = 0;
length = codedIS.readRawVarint32();
oldLimit = codedIS.pushLimit(length);
idLoop: while (true) {
int ts = codedIS.readTag();
int tags = WireFormat.getTagFieldNumber(ts);
switch(tags) {
case 0:
break idLoop;
case IdTable.ROUTEID_FIELD_NUMBER:
routeId += codedIS.readSInt64();
idTables.add(routeId);
break;
default:
skipUnknownField(ts);
break;
}
}
codedIS.popLimit(oldLimit);
break;
case RouteDataBlock.RESTRICTIONS_FIELD_NUMBER:
length = codedIS.readRawVarint32();
oldLimit = codedIS.pushLimit(length);
long from = 0;
long to = 0;
long type = 0;
idLoop: while (true) {
int ts = codedIS.readTag();
int tags = WireFormat.getTagFieldNumber(ts);
switch(tags) {
case 0:
break idLoop;
case RestrictionData.FROM_FIELD_NUMBER:
from = codedIS.readInt32();
break;
case RestrictionData.TO_FIELD_NUMBER:
to = codedIS.readInt32();
break;
case RestrictionData.TYPE_FIELD_NUMBER:
type = codedIS.readInt32();
break;
default:
skipUnknownField(ts);
break;
}
}
if (!restrictions.containsKey(from)) {
restrictions.put(from, new TLongArrayList());
}
restrictions.get(from).add((to << RouteDataObject.RESTRICTION_SHIFT) + type);
codedIS.popLimit(oldLimit);
break;
case RouteDataBlock.STRINGTABLE_FIELD_NUMBER:
length = codedIS.readRawVarint32();
oldLimit = codedIS.pushLimit(length);
stringTable = map.readStringTable();
// codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
codedIS.popLimit(oldLimit);
break;
default:
skipUnknownField(t);
break;
}
}
}
use of gnu.trove.list.array.TLongArrayList in project Osmand by osmandapp.
the class BinaryMapRouteReaderAdapter method loadRouteRegionData.
public void loadRouteRegionData(List<RouteSubregion> toLoad, ResultMatcher<RouteDataObject> matcher) throws IOException {
Collections.sort(toLoad, new Comparator<RouteSubregion>() {
@Override
public int compare(RouteSubregion o1, RouteSubregion o2) {
int p1 = o1.filePointer + o1.shiftToData;
int p2 = o2.filePointer + o2.shiftToData;
return p1 == p2 ? 0 : (p1 < p2 ? -1 : 1);
}
});
TLongArrayList idMap = new TLongArrayList();
TLongObjectHashMap<TLongArrayList> restrictionMap = new TLongObjectHashMap<TLongArrayList>();
for (RouteSubregion rs : toLoad) {
if (rs.dataObjects == null) {
codedIS.seek(rs.filePointer + rs.shiftToData);
int limit = codedIS.readRawVarint32();
int oldLimit = codedIS.pushLimit(limit);
readRouteTreeData(rs, idMap, restrictionMap);
codedIS.popLimit(oldLimit);
}
for (RouteDataObject ro : rs.dataObjects) {
if (ro != null) {
matcher.publish(ro);
}
}
// free objects
rs.dataObjects = null;
}
}
use of gnu.trove.list.array.TLongArrayList in project Osmand by osmandapp.
the class MapRenderRepositories method processCoastlines.
// / MULTI POLYGONS (coastline)
// returns true if coastlines were added!
private boolean processCoastlines(List<BinaryMapDataObject> coastLines, int leftX, int rightX, int bottomY, int topY, int zoom, boolean doNotAddIfIncompleted, boolean addDebugIncompleted, List<BinaryMapDataObject> result) {
List<TLongList> completedRings = new ArrayList<TLongList>();
List<TLongList> uncompletedRings = new ArrayList<TLongList>();
MapIndex mapIndex = null;
long dbId = 0;
for (BinaryMapDataObject o : coastLines) {
int len = o.getPointsLength();
if (len < 2) {
continue;
}
mapIndex = o.getMapIndex();
dbId = o.getId() >> 1;
TLongList coordinates = new TLongArrayList(o.getPointsLength() / 2);
int px = o.getPoint31XTile(0);
int py = o.getPoint31YTile(0);
int x = px;
int y = py;
boolean pinside = leftX <= x && x <= rightX && y >= topY && y <= bottomY;
if (pinside) {
coordinates.add(combine2Points(x, y));
}
for (int i = 1; i < len; i++) {
x = o.getPoint31XTile(i);
y = o.getPoint31YTile(i);
boolean inside = leftX <= x && x <= rightX && y >= topY && y <= bottomY;
boolean lineEnded = calculateLineCoordinates(inside, x, y, pinside, px, py, leftX, rightX, bottomY, topY, coordinates);
if (lineEnded) {
combineMultipolygonLine(completedRings, uncompletedRings, coordinates);
// create new line if it goes outside
coordinates = new TLongArrayList();
}
px = x;
py = y;
pinside = inside;
}
combineMultipolygonLine(completedRings, uncompletedRings, coordinates);
}
if (completedRings.size() == 0 && uncompletedRings.size() == 0) {
return false;
}
if (uncompletedRings.size() > 0) {
unifyIncompletedRings(uncompletedRings, completedRings, leftX, rightX, bottomY, topY, dbId, zoom);
}
long mask = 0xffffffffL;
// draw uncompleted for debug purpose
for (int i = 0; i < uncompletedRings.size(); i++) {
TLongList ring = uncompletedRings.get(i);
int[] coordinates = new int[ring.size() * 2];
for (int j = 0; j < ring.size(); j++) {
coordinates[j * 2] = (int) (ring.get(j) >> 32);
coordinates[j * 2 + 1] = (int) (ring.get(j) & mask);
}
BinaryMapDataObject o = new BinaryMapDataObject(dbId, coordinates, new int[0][], RenderingRulesStorage.POLYGON_RULES, true, new int[] { mapIndex.coastlineBrokenEncodingType }, null);
o.setMapIndex(mapIndex);
result.add(o);
}
if (!doNotAddIfIncompleted && uncompletedRings.size() > 0) {
return false;
}
boolean clockwiseFound = false;
for (int i = 0; i < completedRings.size(); i++) {
TLongList ring = completedRings.get(i);
int[] coordinates = new int[ring.size() * 2];
for (int j = 0; j < ring.size(); j++) {
coordinates[j * 2] = (int) (ring.get(j) >> 32);
coordinates[j * 2 + 1] = (int) (ring.get(j) & mask);
}
boolean clockwise = MapAlgorithms.isClockwiseWay(ring);
clockwiseFound = clockwiseFound || clockwise;
BinaryMapDataObject o = new BinaryMapDataObject(dbId, coordinates, new int[0][], RenderingRulesStorage.POLYGON_RULES, true, new int[] { clockwise ? mapIndex.coastlineEncodingType : mapIndex.landEncodingType }, null);
o.setMapIndex(mapIndex);
o.setArea(true);
result.add(o);
}
if (!clockwiseFound && uncompletedRings.size() == 0) {
// add complete water tile
BinaryMapDataObject o = new BinaryMapDataObject(dbId, new int[] { leftX, topY, rightX, topY, rightX, bottomY, leftX, bottomY, leftX, topY }, new int[0][], RenderingRulesStorage.POLYGON_RULES, true, new int[] { mapIndex.coastlineEncodingType }, null);
o.setMapIndex(mapIndex);
// $NON-NLS-1$
log.info("!!! Isolated islands !!!");
result.add(o);
}
return true;
}
use of gnu.trove.list.array.TLongArrayList in project BuildCraft by BuildCraft.
the class NbtSquishMapWriter method write.
private void write(DataOutput to) throws IOException {
profiler.startSection("write");
profiler.startSection("flags");
WrittenType type = map.getWrittenType();
type.writeType(to);
TByteArrayList bytes = map.bytes;
TShortArrayList shorts = map.shorts;
TIntArrayList ints = map.ints;
TLongArrayList longs = map.longs;
TFloatArrayList floats = map.floats;
TDoubleArrayList doubles = map.doubles;
List<TByteArrayList> byteArrays = map.byteArrays;
List<TIntArrayList> intArrays = map.intArrays;
List<String> strings = map.strings;
List<NBTBase> complex = map.complex;
int flags = 0;
if (!bytes.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_BYTES;
if (!shorts.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_SHORTS;
if (!ints.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_INTS;
if (!longs.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_LONGS;
if (!floats.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_FLOATS;
if (!doubles.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_DOUBLES;
if (!byteArrays.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_BYTE_ARRAYS;
if (!intArrays.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_INT_ARRAYS;
if (!strings.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_STRINGS;
if (!complex.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_COMPLEX;
if (debug)
log("\nUsed flags = " + Integer.toBinaryString(flags));
to.writeInt(flags);
profiler.endStartSection("bytes");
if (!bytes.isEmpty()) {
if (debug)
log("\nByte dictionary size = " + bytes.size());
if (sort)
bytes.sort();
writeVarInt(to, bytes.size());
for (byte b : bytes.toArray()) {
to.writeByte(b);
}
}
profiler.endStartSection("shorts");
if (!shorts.isEmpty()) {
if (debug)
log("\nShort dictionary size = " + shorts.size());
if (sort)
shorts.sort();
writeVarInt(to, shorts.size());
for (short s : shorts.toArray()) {
to.writeShort(s);
}
}
profiler.endStartSection("integers");
if (!ints.isEmpty()) {
if (debug)
log("\nInt dictionary size = " + ints.size());
if (sort)
ints.sort();
writeVarInt(to, ints.size());
for (int i : ints.toArray()) {
to.writeInt(i);
}
}
profiler.endStartSection("longs");
if (!longs.isEmpty()) {
if (debug)
log("\nLong dictionary size = " + longs.size());
if (sort)
longs.sort();
writeVarInt(to, longs.size());
for (long l : longs.toArray()) {
to.writeLong(l);
}
}
profiler.endStartSection("floats");
if (!floats.isEmpty()) {
if (debug)
log("\nFloat dictionary size = " + floats.size());
if (sort)
floats.sort();
writeVarInt(to, floats.size());
for (float f : floats.toArray()) {
to.writeFloat(f);
}
}
profiler.endStartSection("doubles");
if (!doubles.isEmpty()) {
if (debug)
log("\nDouble dictionary size = " + doubles.size());
if (sort)
doubles.sort();
writeVarInt(to, doubles.size());
for (double d : doubles.toArray()) {
to.writeDouble(d);
}
}
profiler.endStartSection("byte_arrays");
if (!byteArrays.isEmpty()) {
if (debug)
log("\nByte Array dictionary size = " + byteArrays.size());
writeVarInt(to, byteArrays.size());
for (TByteArrayList ba : byteArrays) {
to.writeShort(ba.size());
for (byte b : ba.toArray()) {
to.writeByte(b);
}
}
}
profiler.endStartSection("int_arrays");
if (!intArrays.isEmpty()) {
if (debug)
log("\nInt Array dictionary size = " + intArrays.size());
writeVarInt(to, intArrays.size());
for (TIntArrayList ia : intArrays) {
to.writeShort(ia.size());
for (int i : ia.toArray()) {
to.writeInt(i);
}
}
}
profiler.endStartSection("strings");
if (!strings.isEmpty()) {
if (debug)
log("\nString dictionary size = " + strings.size());
if (sort)
Collections.sort(strings);
writeVarInt(to, strings.size());
for (int i = 0; i < strings.size(); i++) {
String s = strings.get(i);
if (debug)
log("\n String " + i + " = " + s);
byte[] stringBytes = s.getBytes(StandardCharsets.UTF_8);
to.writeShort(stringBytes.length);
to.write(stringBytes);
}
}
profiler.endStartSection("complex");
if (!complex.isEmpty()) {
if (debug)
log("\nComplex dictionary size = " + complex.size());
writeVarInt(to, complex.size());
for (NBTBase nbt : complex) {
if (nbt instanceof NBTTagList) {
NBTTagList list = (NBTTagList) nbt;
writeList(type, list, to);
} else {
NBTTagCompound compound = (NBTTagCompound) nbt;
writeCompound(type, compound, to);
}
}
}
profiler.endSection();
profiler.endSection();
}
use of gnu.trove.list.array.TLongArrayList in project spf4j by zolyfarkas.
the class TSDBQuery method getTimeSeries.
public static TimeSeries getTimeSeries(final File tsdbFile, final long[] tableIds, final long startTimeMillis, final long endTimeMillis) throws IOException {
TLongList timestamps = new TLongArrayList();
List<long[]> metrics = new ArrayList<>();
try (TSDBReader reader = new TSDBReader(tsdbFile, 8192)) {
Either<TableDef, DataBlock> read;
while ((read = reader.read()) != null) {
if (read.isRight()) {
DataBlock data = read.getRight();
long baseTs = data.baseTimestamp;
for (DataRow row : data.getValues()) {
for (long tableId : tableIds) {
if (tableId == row.tableDefId) {
final long ts = baseTs + row.relTimeStamp;
if (ts >= startTimeMillis && ts <= endTimeMillis) {
timestamps.add(ts);
metrics.add(Longs.toArray(row.data));
}
}
}
}
}
}
}
return new TimeSeries(timestamps.toArray(), metrics.toArray(new long[metrics.size()][]));
}
Aggregations