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.CodedOutputStream;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.google.protobuf.WireFormat;
|
||||
|
||||
import net.osmand.Collator;
|
||||
|
@ -26,6 +27,7 @@ import net.osmand.binary.OsmandOdb.OsmAndMapIndex.MapRootLevel;
|
|||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.Building;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.IncompleteTransportRoute;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.MapObject;
|
||||
import net.osmand.data.Street;
|
||||
|
@ -54,7 +56,6 @@ import java.io.InputStreamReader;
|
|||
import java.io.RandomAccessFile;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
|
@ -110,9 +111,7 @@ public class BinaryMapIndexReader {
|
|||
/*private*/ List<TransportIndex> transportIndexes = new ArrayList<TransportIndex>();
|
||||
/*private*/ List<RouteRegion> routingIndexes = new ArrayList<RouteRegion>();
|
||||
/*private*/ List<BinaryIndexPart> indexes = new ArrayList<BinaryIndexPart>();
|
||||
|
||||
private final TLongObjectHashMap<net.osmand.data.IncompleteTransportRoute> incompleteRoutes =
|
||||
new TLongObjectHashMap<net.osmand.data.IncompleteTransportRoute>();
|
||||
TLongObjectHashMap<IncompleteTransportRoute> incompleteTransportRoutes = null;
|
||||
|
||||
protected CodedInputStream codedIS;
|
||||
|
||||
|
@ -227,7 +226,7 @@ public class BinaryMapIndexReader {
|
|||
ind.filePointer = codedIS.getTotalBytesRead();
|
||||
if (transportAdapter != null) {
|
||||
oldLimit = codedIS.pushLimit(ind.length);
|
||||
transportAdapter.readTransportIndex(ind, incompleteRoutes);
|
||||
transportAdapter.readTransportIndex(ind);
|
||||
codedIS.popLimit(oldLimit);
|
||||
transportIndexes.add(ind);
|
||||
indexes.add(ind);
|
||||
|
@ -2635,12 +2634,17 @@ public class BinaryMapIndexReader {
|
|||
}
|
||||
}
|
||||
|
||||
public net.osmand.data.IncompleteTransportRoute getIncompleteRoutePointers(long id) {
|
||||
return incompleteRoutes.get(id);
|
||||
}
|
||||
|
||||
public Collection<net.osmand.data.IncompleteTransportRoute> getIncompleteRoutes() {
|
||||
return incompleteRoutes.valueCollection();
|
||||
public TLongObjectHashMap<IncompleteTransportRoute> getIncompleteTransportRoutes() throws InvalidProtocolBufferException, IOException {
|
||||
if (incompleteTransportRoutes == null) {
|
||||
incompleteTransportRoutes = new TLongObjectHashMap<>();
|
||||
for (TransportIndex ti : transportIndexes) {
|
||||
if (ti.incompleteRoutesLength > 0) {
|
||||
transportAdapter.readIncompleteRoutesList(incompleteTransportRoutes, ti.incompleteRoutesLength,
|
||||
ti.incompleteRoutesOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
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){
|
||||
int t = codedIS.readTag();
|
||||
int tag = WireFormat.getTagFieldNumber(t);
|
||||
|
@ -113,13 +113,9 @@ public class BinaryMapTransportReaderAdapter {
|
|||
codedIS.seek(st.length + st.fileOffset);
|
||||
break;
|
||||
case OsmandOdb.OsmAndTransportIndex.INCOMPLETEROUTES_FIELD_NUMBER :
|
||||
TIntObjectHashMap<String> stab = new TIntObjectHashMap<String>();
|
||||
ind.incompleteRoutesLength = codedIS.readRawVarint32();
|
||||
ind.incompleteRoutesOffset = codedIS.getTotalBytesRead();
|
||||
int oldl = codedIS.pushLimit(ind.incompleteRoutesLength);
|
||||
//may be we should start caching stringTable in advance?
|
||||
readIncompleteRoutesList(incompleteRoutes, ind.incompleteRoutesLength, ind.incompleteRoutesOffset, stab);
|
||||
codedIS.popLimit(oldl);
|
||||
codedIS.seek(ind.incompleteRoutesLength + ind.incompleteRoutesOffset);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -128,6 +124,7 @@ public class BinaryMapTransportReaderAdapter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void readTransportBounds(TransportIndex ind) throws IOException {
|
||||
while(true){
|
||||
|
@ -254,8 +251,8 @@ public class BinaryMapTransportReaderAdapter {
|
|||
return ((char) i)+"";
|
||||
}
|
||||
|
||||
private void readIncompleteRoutesList(TLongObjectHashMap<net.osmand.data.IncompleteTransportRoute> incompleteRoutes,
|
||||
int length, int offset, TIntObjectHashMap<String> stringTable) throws IOException {
|
||||
public void readIncompleteRoutesList(TLongObjectHashMap<net.osmand.data.IncompleteTransportRoute> incompleteRoutes,
|
||||
int length, int offset) throws IOException {
|
||||
codedIS.seek(offset);
|
||||
boolean end = false;
|
||||
while (!end) {
|
||||
|
@ -268,7 +265,7 @@ public class BinaryMapTransportReaderAdapter {
|
|||
case OsmandOdb.IncompleteTransportRoutes.ROUTES_FIELD_NUMBER:
|
||||
int l = codedIS.readRawVarint32();
|
||||
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());
|
||||
if(itr != null) {
|
||||
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();
|
||||
boolean end = false;
|
||||
while(!end){
|
||||
|
|
|
@ -1126,9 +1126,9 @@ public class TransportRoutePlanner {
|
|||
|
||||
private List<TransportRoute> findIncompleteRouteParts(TransportRoute baseRoute) throws IOException {
|
||||
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()) {
|
||||
IncompleteTransportRoute ptr = bmir.getIncompleteRoutePointers(baseRoute.getId());
|
||||
IncompleteTransportRoute ptr = bmir.getIncompleteTransportRoutes().get(baseRoute.getId());
|
||||
if (ptr != null) {
|
||||
TIntArrayList lst = new TIntArrayList();
|
||||
while(ptr != null) {
|
||||
|
|
Loading…
Reference in a new issue