preprocessor speedup

This commit is contained in:
Arndt Brenschede 2019-09-25 00:24:23 +02:00
parent ba34488447
commit 365d52db22
2 changed files with 28 additions and 17 deletions

View file

@ -141,10 +141,10 @@ public class OsmCutter extends MapCreatorBase
if ( tileIndex >= 0 ) if ( tileIndex >= 0 )
{ {
n.writeTo( getOutStreamForTile( tileIndex ) ); n.writeTo( getOutStreamForTile( tileIndex ) );
} if ( wayCutter != null )
if ( wayCutter != null ) {
{ wayCutter.nextNode( n );
wayCutter.nextNode( n ); }
} }
} }

View file

@ -25,7 +25,7 @@ public class PosUnifier extends MapCreatorBase
private DiffCoderDataOutputStream nodesOutStream; private DiffCoderDataOutputStream nodesOutStream;
private DiffCoderDataOutputStream borderNodesOut; private DiffCoderDataOutputStream borderNodesOut;
private File nodeTilesOut; private File nodeTilesOut;
private CompactLongSet positionSet; private CompactLongSet[] positionSets;
private HashMap<String, SrtmRaster> srtmmap; private HashMap<String, SrtmRaster> srtmmap;
private int lastSrtmLonIdx; private int lastSrtmLonIdx;
@ -82,7 +82,7 @@ public class PosUnifier extends MapCreatorBase
nodesOutStream = createOutStream( fileFromTemplate( nodefile, nodeTilesOut, "u5d" ) ); nodesOutStream = createOutStream( fileFromTemplate( nodefile, nodeTilesOut, "u5d" ) );
positionSet = new CompactLongSet(); positionSets = new CompactLongSet[2500];
} }
@Override @Override
@ -106,16 +106,29 @@ public class PosUnifier extends MapCreatorBase
nodesOutStream.close(); nodesOutStream.close();
} }
private boolean checkAdd( int lon, int lat )
{
int slot = ((lon%5000000)/100000)*50 + ((lat%5000000)/100000);
long id = ( (long) lon ) << 32 | lat;
CompactLongSet set = positionSets[slot];
if ( set == null )
{
positionSets[slot] = set = new CompactLongSet();
}
if ( !set.contains( id ) )
{
set.fastAdd( id );
return true;
}
return false;
}
private void findUniquePos( NodeData n ) private void findUniquePos( NodeData n )
{ {
int lon = n.ilon; if ( !checkAdd( n.ilon, n.ilat ) )
int lat = n.ilat;
long pid = ( (long) lon ) << 32 | lat; // id from position
if ( !positionSet.contains( pid ) )
{
positionSet.fastAdd( pid );
}
else
{ {
_findUniquePos( n ); _findUniquePos( n );
} }
@ -134,10 +147,8 @@ public class PosUnifier extends MapCreatorBase
{ {
int lon = n.ilon + lonsteps * londelta; int lon = n.ilon + lonsteps * londelta;
int lat = n.ilat + latsteps * latdelta; int lat = n.ilat + latsteps * latdelta;
long pid = ( (long) lon ) << 32 | lat; // id from position if ( checkAdd( lon, lat ) )
if ( !positionSet.contains( pid ) )
{ {
positionSet.fastAdd( pid );
n.ilon = lon; n.ilon = lon;
n.ilat = lat; n.ilat = lat;
return; return;