use of com.graphhopper.storage.VLongStorage in project graphhopper by graphhopper.
the class CompressedArray method get.
public GHPoint get(long index) {
int segmentNo = (int) (index / entriesPerSegment);
int entry = (int) (index % entriesPerSegment);
try {
if (segmentNo >= segments.size()) {
return null;
}
byte[] bytes = segments.get(segmentNo);
VLongStorage store = new VLongStorage(decompress(bytes));
long len = store.getLength();
for (int i = 0; store.getPosition() < len; i++) {
long latlon = store.readVLong();
if (i == entry) {
GHPoint point = new GHPoint();
algo.decode(latlon, point);
return point;
}
}
return null;
} catch (ArrayIndexOutOfBoundsException ex) {
throw new RuntimeException("index " + index + "=> segNo:" + segmentNo + ", entry=" + entry + ", segments:" + segments.size(), ex);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of com.graphhopper.storage.VLongStorage in project graphhopper by graphhopper.
the class CompressedArray method write.
public void write(double lat, double lon) {
try {
if (currentWriter == null)
currentWriter = new VLongStorage(entriesPerSegment * approxBytesPerEntry);
long latlon = algo.encode(new GHPoint(lat, lon));
// we cannot use delta encoding as vlong does not support negative numbers
// but compression of vlong is much more efficient than directly storing the integers
currentWriter.writeVLong(latlon);
currentEntry++;
if (currentEntry >= entriesPerSegment) {
flush();
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
Aggregations