Speed search (check for duplicates)

This commit is contained in:
Victor Shcherb 2016-06-29 20:23:33 +02:00
parent 0e175abee4
commit da6121e8d4
4 changed files with 41 additions and 12 deletions

View file

@ -2,6 +2,12 @@ apply plugin: 'java'
apply plugin: 'application' apply plugin: 'application'
mainClassName = "net.osmand.util.GeoPointParserUtil" mainClassName = "net.osmand.util.GeoPointParserUtil"
tasks.withType(JavaCompile) {
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
}
sourceSets { sourceSets {
main { main {
java { java {
@ -27,3 +33,4 @@ artifacts {
dependencies { dependencies {
compile fileTree(dir: "libs", include: ["*.jar"]) compile fileTree(dir: "libs", include: ["*.jar"])
} }

View file

@ -75,7 +75,7 @@ public class BinaryInspector {
// "-vrouting", // "-vrouting",
"-vaddress", "-vcities","-vstreetgroups", "-vaddress", "-vcities","-vstreetgroups",
"-vstreets", "-vbuildings", "-vintersections", "-vstreets", "-vbuildings", "-vintersections",
"-lang=ru", // "-lang=ru",
"-bbox=4.8486,52.3084,4.8747,52.2970", "-bbox=4.8486,52.3084,4.8747,52.2970",
// "-osm="+System.getProperty("maps.dir")+"/map.obf.osm" // "-osm="+System.getProperty("maps.dir")+"/map.obf.osm"
System.getProperty("maps.dir")+"/Netherlands_noord-holland_europe.obf" System.getProperty("maps.dir")+"/Netherlands_noord-holland_europe.obf"

View file

@ -1,6 +1,7 @@
package net.osmand.binary; package net.osmand.binary;
import gnu.trove.list.array.TIntArrayList; import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.hash.TIntLongHashMap;
import gnu.trove.set.TIntSet; import gnu.trove.set.TIntSet;
import gnu.trove.set.hash.TIntHashSet; import gnu.trove.set.hash.TIntHashSet;
@ -587,9 +588,12 @@ public class BinaryMapAddressReaderAdapter {
case OsmAndAddressNameIndexData.ATOM_FIELD_NUMBER: case OsmAndAddressNameIndexData.ATOM_FIELD_NUMBER:
// also offsets can be randomly skipped by limit // also offsets can be randomly skipped by limit
loffsets.sort(); loffsets.sort();
TIntArrayList[] refs = new TIntArrayList[5]; TIntArrayList[] refs = new TIntArrayList[5];
TIntArrayList[] refsContainer = new TIntArrayList[5];
for (int i = 0; i < refs.length; i++) { for (int i = 0; i < refs.length; i++) {
refs[i] = new TIntArrayList(); refs[i] = new TIntArrayList();
refsContainer[i] = new TIntArrayList();
} }
LOG.info("Searched address structure in " + (System.currentTimeMillis() - time) + "ms. Found " + loffsets.size() LOG.info("Searched address structure in " + (System.currentTimeMillis() - time) + "ms. Found " + loffsets.size()
@ -606,7 +610,7 @@ public class BinaryMapAddressReaderAdapter {
if (stag == AddressNameIndexData.ATOM_FIELD_NUMBER) { if (stag == AddressNameIndexData.ATOM_FIELD_NUMBER) {
int slen = codedIS.readRawVarint32(); int slen = codedIS.readRawVarint32();
int soldLim = codedIS.pushLimit(slen); int soldLim = codedIS.pushLimit(slen);
readAddressNameData(req, refs, fp); readAddressNameData(req, refs, refsContainer, fp);
codedIS.popLimit(soldLim); codedIS.popLimit(soldLim);
} else if (stag != 0) { } else if (stag != 0) {
skipUnknownField(st); skipUnknownField(st);
@ -623,23 +627,35 @@ public class BinaryMapAddressReaderAdapter {
} }
for (int i = 0; i < typeFilter.size() && !req.isCancelled(); i++) { for (int i = 0; i < typeFilter.size() && !req.isCancelled(); i++) {
TIntArrayList list = refs[typeFilter.get(i)]; TIntArrayList list = refs[typeFilter.get(i)];
TIntArrayList listContainer = refsContainer[typeFilter.get(i)];
if (typeFilter.get(i) == STREET_TYPE) { if (typeFilter.get(i) == STREET_TYPE) {
for (int j = 0; j < list.size() && !req.isCancelled(); j += 2) { TIntLongHashMap mp = new TIntLongHashMap();
for (int j = 0; j < list.size(); j++) {
mp.put(list.get(j), listContainer.get(j));
}
list.sort();
for (int j = 0; j < list.size() && !req.isCancelled(); j ++) {
int offset = list.get(j);
if (j > 0 && offset == list.get(j - 1)) {
continue;
}
City obj; City obj;
{ {
codedIS.seek(list.get(j + 1)); int contOffset = (int) mp.get(offset);
codedIS.seek(contOffset);
int len = codedIS.readRawVarint32(); int len = codedIS.readRawVarint32();
int old = codedIS.pushLimit(len); int old = codedIS.pushLimit(len);
obj = readCityHeader(null, list.get(j + 1), null); obj = readCityHeader(null, contOffset, null);
codedIS.popLimit(old); codedIS.popLimit(old);
} }
if (obj != null) { if (obj != null) {
codedIS.seek(list.get(j)); codedIS.seek(offset);
int len = codedIS.readRawVarint32(); int len = codedIS.readRawVarint32();
int old = codedIS.pushLimit(len); int old = codedIS.pushLimit(len);
LatLon l = obj.getLocation(); LatLon l = obj.getLocation();
Street s = new Street(obj); Street s = new Street(obj);
s.setFileOffset(list.get(j)); s.setFileOffset(offset);
readStreet(s, null, false, MapUtils.get31TileNumberX(l.getLongitude()) >> 7, readStreet(s, null, false, MapUtils.get31TileNumberX(l.getLongitude()) >> 7,
MapUtils.get31TileNumberY(l.getLatitude()) >> 7, obj.isPostcode() ? obj.getName() : null, MapUtils.get31TileNumberY(l.getLatitude()) >> 7, obj.isPostcode() ? obj.getName() : null,
reg.attributeTagsTable); reg.attributeTagsTable);
@ -663,6 +679,9 @@ public class BinaryMapAddressReaderAdapter {
TIntSet published = new TIntHashSet(); TIntSet published = new TIntHashSet();
for (int j = 0; j < list.size() && !req.isCancelled(); j++) { for (int j = 0; j < list.size() && !req.isCancelled(); j++) {
int offset = list.get(j); int offset = list.get(j);
if (j > 0 && offset == list.get(j - 1)) {
continue;
}
codedIS.seek(offset); codedIS.seek(offset);
int len = codedIS.readRawVarint32(); int len = codedIS.readRawVarint32();
int old = codedIS.pushLimit(len); int old = codedIS.pushLimit(len);
@ -686,8 +705,10 @@ public class BinaryMapAddressReaderAdapter {
} }
private void readAddressNameData(SearchRequest<MapObject> req, TIntArrayList[] refs, int fp) throws IOException { private void readAddressNameData(SearchRequest<MapObject> req, TIntArrayList[] refs,
TIntArrayList[] refsContainer, int fp) throws IOException {
TIntArrayList toAdd = null; TIntArrayList toAdd = null;
TIntArrayList toAddCity = null;
while (true) { while (true) {
if (req.isCancelled()) { if (req.isCancelled()) {
return; return;
@ -704,8 +725,8 @@ public class BinaryMapAddressReaderAdapter {
codedIS.readString(); codedIS.readString();
break; break;
case AddressNameIndexDataAtom.SHIFTTOCITYINDEX_FIELD_NUMBER: case AddressNameIndexDataAtom.SHIFTTOCITYINDEX_FIELD_NUMBER:
if (toAdd != null) { if (toAddCity != null) {
toAdd.add(fp - codedIS.readInt32()); toAddCity.add(fp - codedIS.readInt32());
} }
break; break;
case AddressNameIndexDataAtom.SHIFTTOINDEX_FIELD_NUMBER: case AddressNameIndexDataAtom.SHIFTTOINDEX_FIELD_NUMBER:
@ -716,6 +737,7 @@ public class BinaryMapAddressReaderAdapter {
case AddressNameIndexDataAtom.TYPE_FIELD_NUMBER: case AddressNameIndexDataAtom.TYPE_FIELD_NUMBER:
int type = codedIS.readInt32(); int type = codedIS.readInt32();
toAdd = refs[type]; toAdd = refs[type];
toAddCity = refsContainer[type];
break; break;
default: default:
skipUnknownField(t); skipUnknownField(t);

View file

@ -2019,7 +2019,7 @@ public class BinaryMapIndexReader {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
// File fl = new File(System.getProperty("maps") + /Synthetic_test_rendering.obf"); // File fl = new File(System.getProperty("maps") + /Synthetic_test_rendering.obf");
File fl = new File(System.getProperty("maps") + "/Netherlands_noord-holland_europe_merge.obf"); File fl = new File(System.getProperty("maps") + "/Netherlands_noord-holland_europe.obf");
RandomAccessFile raf = new RandomAccessFile(fl, "r"); RandomAccessFile raf = new RandomAccessFile(fl, "r");
BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, fl); BinaryMapIndexReader reader = new BinaryMapIndexReader(raf, fl);
@ -2304,7 +2304,7 @@ public class BinaryMapIndexReader {
public boolean isCancelled() { public boolean isCancelled() {
return false; return false;
} }
}, "P", StringMatcherMode.CHECK_ONLY_STARTS_WITH); }, "Amstelvee", StringMatcherMode.CHECK_ONLY_STARTS_WITH);
reader.searchAddressDataByName(req); reader.searchAddressDataByName(req);
} }