Lazy loading reading
This commit is contained in:
parent
4873ab04a9
commit
7319a235c0
3 changed files with 24 additions and 23 deletions
|
@ -3,6 +3,7 @@ package net.osmand.binary;
|
||||||
|
|
||||||
import com.google.protobuf.CodedInputStream;
|
import com.google.protobuf.CodedInputStream;
|
||||||
import com.google.protobuf.CodedOutputStream;
|
import com.google.protobuf.CodedOutputStream;
|
||||||
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
import com.google.protobuf.WireFormat;
|
import com.google.protobuf.WireFormat;
|
||||||
|
|
||||||
import net.osmand.Collator;
|
import net.osmand.Collator;
|
||||||
|
@ -26,6 +27,7 @@ import net.osmand.binary.OsmandOdb.OsmAndMapIndex.MapRootLevel;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.Building;
|
import net.osmand.data.Building;
|
||||||
import net.osmand.data.City;
|
import net.osmand.data.City;
|
||||||
|
import net.osmand.data.IncompleteTransportRoute;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.MapObject;
|
import net.osmand.data.MapObject;
|
||||||
import net.osmand.data.Street;
|
import net.osmand.data.Street;
|
||||||
|
@ -54,7 +56,6 @@ import java.io.InputStreamReader;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -110,9 +111,7 @@ public class BinaryMapIndexReader {
|
||||||
/*private*/ List<TransportIndex> transportIndexes = new ArrayList<TransportIndex>();
|
/*private*/ List<TransportIndex> transportIndexes = new ArrayList<TransportIndex>();
|
||||||
/*private*/ List<RouteRegion> routingIndexes = new ArrayList<RouteRegion>();
|
/*private*/ List<RouteRegion> routingIndexes = new ArrayList<RouteRegion>();
|
||||||
/*private*/ List<BinaryIndexPart> indexes = new ArrayList<BinaryIndexPart>();
|
/*private*/ List<BinaryIndexPart> indexes = new ArrayList<BinaryIndexPart>();
|
||||||
|
TLongObjectHashMap<IncompleteTransportRoute> incompleteTransportRoutes = null;
|
||||||
private final TLongObjectHashMap<net.osmand.data.IncompleteTransportRoute> incompleteRoutes =
|
|
||||||
new TLongObjectHashMap<net.osmand.data.IncompleteTransportRoute>();
|
|
||||||
|
|
||||||
protected CodedInputStream codedIS;
|
protected CodedInputStream codedIS;
|
||||||
|
|
||||||
|
@ -227,7 +226,7 @@ public class BinaryMapIndexReader {
|
||||||
ind.filePointer = codedIS.getTotalBytesRead();
|
ind.filePointer = codedIS.getTotalBytesRead();
|
||||||
if (transportAdapter != null) {
|
if (transportAdapter != null) {
|
||||||
oldLimit = codedIS.pushLimit(ind.length);
|
oldLimit = codedIS.pushLimit(ind.length);
|
||||||
transportAdapter.readTransportIndex(ind, incompleteRoutes);
|
transportAdapter.readTransportIndex(ind);
|
||||||
codedIS.popLimit(oldLimit);
|
codedIS.popLimit(oldLimit);
|
||||||
transportIndexes.add(ind);
|
transportIndexes.add(ind);
|
||||||
indexes.add(ind);
|
indexes.add(ind);
|
||||||
|
@ -2635,12 +2634,17 @@ public class BinaryMapIndexReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public net.osmand.data.IncompleteTransportRoute getIncompleteRoutePointers(long id) {
|
public TLongObjectHashMap<IncompleteTransportRoute> getIncompleteTransportRoutes() throws InvalidProtocolBufferException, IOException {
|
||||||
return incompleteRoutes.get(id);
|
if (incompleteTransportRoutes == null) {
|
||||||
|
incompleteTransportRoutes = new TLongObjectHashMap<>();
|
||||||
|
for (TransportIndex ti : transportIndexes) {
|
||||||
|
if (ti.incompleteRoutesLength > 0) {
|
||||||
|
transportAdapter.readIncompleteRoutesList(incompleteTransportRoutes, ti.incompleteRoutesLength,
|
||||||
|
ti.incompleteRoutesOffset);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public Collection<net.osmand.data.IncompleteTransportRoute> getIncompleteRoutes() {
|
}
|
||||||
return incompleteRoutes.valueCollection();
|
return incompleteTransportRoutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class BinaryMapTransportReaderAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void readTransportIndex(TransportIndex ind, TLongObjectHashMap<net.osmand.data.IncompleteTransportRoute> incompleteRoutes) throws IOException {
|
protected void readTransportIndex(TransportIndex ind) throws IOException {
|
||||||
while(true){
|
while(true){
|
||||||
int t = codedIS.readTag();
|
int t = codedIS.readTag();
|
||||||
int tag = WireFormat.getTagFieldNumber(t);
|
int tag = WireFormat.getTagFieldNumber(t);
|
||||||
|
@ -113,13 +113,9 @@ public class BinaryMapTransportReaderAdapter {
|
||||||
codedIS.seek(st.length + st.fileOffset);
|
codedIS.seek(st.length + st.fileOffset);
|
||||||
break;
|
break;
|
||||||
case OsmandOdb.OsmAndTransportIndex.INCOMPLETEROUTES_FIELD_NUMBER :
|
case OsmandOdb.OsmAndTransportIndex.INCOMPLETEROUTES_FIELD_NUMBER :
|
||||||
TIntObjectHashMap<String> stab = new TIntObjectHashMap<String>();
|
|
||||||
ind.incompleteRoutesLength = codedIS.readRawVarint32();
|
ind.incompleteRoutesLength = codedIS.readRawVarint32();
|
||||||
ind.incompleteRoutesOffset = codedIS.getTotalBytesRead();
|
ind.incompleteRoutesOffset = codedIS.getTotalBytesRead();
|
||||||
int oldl = codedIS.pushLimit(ind.incompleteRoutesLength);
|
codedIS.seek(ind.incompleteRoutesLength + ind.incompleteRoutesOffset);
|
||||||
//may be we should start caching stringTable in advance?
|
|
||||||
readIncompleteRoutesList(incompleteRoutes, ind.incompleteRoutesLength, ind.incompleteRoutesOffset, stab);
|
|
||||||
codedIS.popLimit(oldl);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -129,6 +125,7 @@ public class BinaryMapTransportReaderAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void readTransportBounds(TransportIndex ind) throws IOException {
|
private void readTransportBounds(TransportIndex ind) throws IOException {
|
||||||
while(true){
|
while(true){
|
||||||
int t = codedIS.readTag();
|
int t = codedIS.readTag();
|
||||||
|
@ -254,8 +251,8 @@ public class BinaryMapTransportReaderAdapter {
|
||||||
return ((char) i)+"";
|
return ((char) i)+"";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readIncompleteRoutesList(TLongObjectHashMap<net.osmand.data.IncompleteTransportRoute> incompleteRoutes,
|
public void readIncompleteRoutesList(TLongObjectHashMap<net.osmand.data.IncompleteTransportRoute> incompleteRoutes,
|
||||||
int length, int offset, TIntObjectHashMap<String> stringTable) throws IOException {
|
int length, int offset) throws IOException {
|
||||||
codedIS.seek(offset);
|
codedIS.seek(offset);
|
||||||
boolean end = false;
|
boolean end = false;
|
||||||
while (!end) {
|
while (!end) {
|
||||||
|
@ -268,7 +265,7 @@ public class BinaryMapTransportReaderAdapter {
|
||||||
case OsmandOdb.IncompleteTransportRoutes.ROUTES_FIELD_NUMBER:
|
case OsmandOdb.IncompleteTransportRoutes.ROUTES_FIELD_NUMBER:
|
||||||
int l = codedIS.readRawVarint32();
|
int l = codedIS.readRawVarint32();
|
||||||
int olds = codedIS.pushLimit(l);
|
int olds = codedIS.pushLimit(l);
|
||||||
net.osmand.data.IncompleteTransportRoute ir = readIncompleteRoute(stringTable);
|
net.osmand.data.IncompleteTransportRoute ir = readIncompleteRoute();
|
||||||
net.osmand.data.IncompleteTransportRoute itr = incompleteRoutes.get(ir.getRouteId());
|
net.osmand.data.IncompleteTransportRoute itr = incompleteRoutes.get(ir.getRouteId());
|
||||||
if(itr != null) {
|
if(itr != null) {
|
||||||
itr.setNextLinkedRoute(ir);
|
itr.setNextLinkedRoute(ir);
|
||||||
|
@ -286,7 +283,7 @@ public class BinaryMapTransportReaderAdapter {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public net.osmand.data.IncompleteTransportRoute readIncompleteRoute(TIntObjectHashMap<String> stringTable) throws IOException {
|
public net.osmand.data.IncompleteTransportRoute readIncompleteRoute() throws IOException {
|
||||||
net.osmand.data.IncompleteTransportRoute dataObject = new net.osmand.data.IncompleteTransportRoute();
|
net.osmand.data.IncompleteTransportRoute dataObject = new net.osmand.data.IncompleteTransportRoute();
|
||||||
boolean end = false;
|
boolean end = false;
|
||||||
while(!end){
|
while(!end){
|
||||||
|
|
|
@ -1126,9 +1126,9 @@ public class TransportRoutePlanner {
|
||||||
|
|
||||||
private List<TransportRoute> findIncompleteRouteParts(TransportRoute baseRoute) throws IOException {
|
private List<TransportRoute> findIncompleteRouteParts(TransportRoute baseRoute) throws IOException {
|
||||||
List<TransportRoute> allRoutes = null;
|
List<TransportRoute> allRoutes = null;
|
||||||
// TODO completely irrelevant always reiteration over all maps
|
// TODO completely irrelevant always reiteration over all maps (especially not in bbox of the route probabl)
|
||||||
for (BinaryMapIndexReader bmir : routeMap.keySet()) {
|
for (BinaryMapIndexReader bmir : routeMap.keySet()) {
|
||||||
IncompleteTransportRoute ptr = bmir.getIncompleteRoutePointers(baseRoute.getId());
|
IncompleteTransportRoute ptr = bmir.getIncompleteTransportRoutes().get(baseRoute.getId());
|
||||||
if (ptr != null) {
|
if (ptr != null) {
|
||||||
TIntArrayList lst = new TIntArrayList();
|
TIntArrayList lst = new TIntArrayList();
|
||||||
while(ptr != null) {
|
while(ptr != null) {
|
||||||
|
|
Loading…
Reference in a new issue