From 2cec35f3ccb19c461ff927d29c66a8bcbe4ef971 Mon Sep 17 00:00:00 2001 From: Arndt Date: Fri, 28 Aug 2015 17:49:35 +0200 Subject: [PATCH] removed old format support --- .../java/btools/router/RoutingEngine.java | 2 +- .../expressions/BExpressionContext.java | 81 ++----------------- .../expressions/BExpressionMetaData.java | 7 -- .../main/java/btools/mapcreator/OsmNodeP.java | 8 +- .../java/btools/mapcreator/WayLinker.java | 4 +- .../java/btools/mapaccess/MicroCache.java | 32 ++------ .../java/btools/mapaccess/NodesCache.java | 6 +- .../main/java/btools/mapaccess/OsmNode.java | 50 +++--------- .../java/btools/mapaccess/PhysicalFile.java | 2 +- misc/profiles2/lookups.dat | 1 - 10 files changed, 35 insertions(+), 158 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index e892281..99f395d 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -529,7 +529,7 @@ public class RoutingEngine extends Thread { nodesMap = new OsmNodesMap(); BExpressionContext ctx = routingContext.expctxWay; - nodesCache = new NodesCache(segmentDir, nodesMap, ctx.meta.lookupVersion, ctx.meta.lookupMinorVersion, ctx.meta.readVarLength, routingContext.carMode, routingContext.forceSecondaryData, nodesCache ); + nodesCache = new NodesCache(segmentDir, nodesMap, ctx.meta.lookupVersion, ctx.meta.lookupMinorVersion, routingContext.carMode, routingContext.forceSecondaryData, nodesCache ); } private OsmNode getStartNode( long startId ) diff --git a/brouter-expressions/src/main/java/btools/expressions/BExpressionContext.java b/brouter-expressions/src/main/java/btools/expressions/BExpressionContext.java index 10d6da7..3d4df10 100644 --- a/brouter-expressions/src/main/java/btools/expressions/BExpressionContext.java +++ b/brouter-expressions/src/main/java/btools/expressions/BExpressionContext.java @@ -123,8 +123,6 @@ public abstract class BExpressionContext public byte[] encode( int[] ld ) { - if ( !meta.readVarLength ) return encodeFix( ld ); - // start with first bit hardwired ("reversedirection") BitCoderContext ctx = new BitCoderContext( abBuf ); ctx.encodeBit( ld[0] != 0 ); @@ -170,36 +168,6 @@ public abstract class BExpressionContext return ab; } - /** - * encode lookup data to a 64-bit word - */ - public byte[] encodeFix( int[] ld ) - { - long w = 0; - for( int inum = 0; inum < lookupValues.size(); inum++ ) // loop over lookup names - { - int n = lookupValues.get(inum).length - 1; - int d = ld[inum]; - if ( n == 2 ) { n = 1; d = d == 2 ? 1 : 0; } // 1-bit encoding for booleans - - while( n != 0 ) { n >>= 1; w <<= 1; } - w |= (long)d; - } - if ( w == 0) return null; - - byte[] ab = new byte[8]; - int aboffset = 0; - ab[aboffset++] = (byte)( (w >> 56) & 0xff ); - ab[aboffset++] = (byte)( (w >> 48) & 0xff ); - ab[aboffset++] = (byte)( (w >> 40) & 0xff ); - ab[aboffset++] = (byte)( (w >> 32) & 0xff ); - ab[aboffset++] = (byte)( (w >> 24) & 0xff ); - ab[aboffset++] = (byte)( (w >> 16) & 0xff ); - ab[aboffset++] = (byte)( (w >> 8) & 0xff ); - ab[aboffset++] = (byte)( (w ) & 0xff ); - return ab; - } - /** * decode byte array to internal lookup data @@ -215,8 +183,6 @@ public abstract class BExpressionContext */ private void decode( int[] ld, boolean inverseDirection, byte[] ab ) { - if ( !meta.readVarLength ) { decodeFix( ld, ab ); return; } - BitCoderContext ctx = new BitCoderContext(ab); // start with first bit hardwired ("reversedirection") @@ -241,36 +207,6 @@ public abstract class BExpressionContext while( inum < ld.length ) ld[inum++] = 0; } - /** - * decode old, 64-bit-fixed-length format - */ - public void decodeFix( int[] ld, byte[] ab ) - { - int idx = 0; - long i7 = ab[idx++]& 0xff; - long i6 = ab[idx++]& 0xff; - long i5 = ab[idx++]& 0xff; - long i4 = ab[idx++]& 0xff; - long i3 = ab[idx++]& 0xff; - long i2 = ab[idx++]& 0xff; - long i1 = ab[idx++]& 0xff; - long i0 = ab[idx++]& 0xff; - long w = (i7 << 56) + (i6 << 48) + (i5 << 40) + (i4 << 32) + (i3 << 24) + (i2 << 16) + (i1 << 8) + i0; - - for( int inum = lookupValues.size()-1; inum >= 0; inum-- ) // loop over lookup names - { - int nv = lookupValues.get(inum).length; - int n = nv == 3 ? 1 : nv-1; // 1-bit encoding for booleans - int m = 0; - long ww = w; - while( n != 0 ) { n >>= 1; ww >>= 1; m = m<<1 | 1; } - int d = (int)(w & m); - if ( nv == 3 && d == 1 ) d = 2; // 1-bit encoding for booleans - ld[inum] = d; - w = ww; - } - } - public String getKeyValueDescription( boolean inverseDirection, byte[] ab ) { StringBuilder sb = new StringBuilder( 200 ); @@ -300,17 +236,14 @@ public abstract class BExpressionContext int idx = name.indexOf( ';' ); if ( idx >= 0 ) name = name.substring( 0, idx ); - if ( meta.readVarLength ) + if ( !fixTagsWritten ) { - if ( !fixTagsWritten ) - { - fixTagsWritten = true; - if ( "way".equals( context ) ) addLookupValue( "reversedirection", "yes", null ); - else if ( "node".equals( context ) ) addLookupValue( "nodeaccessgranted", "yes", null ); - } - if ( "reversedirection".equals( name ) ) return; // this is hardcoded - if ( "nodeaccessgranted".equals( name ) ) return; // this is hardcoded + fixTagsWritten = true; + if ( "way".equals( context ) ) addLookupValue( "reversedirection", "yes", null ); + else if ( "node".equals( context ) ) addLookupValue( "nodeaccessgranted", "yes", null ); } + if ( "reversedirection".equals( name ) ) return; // this is hardcoded + if ( "nodeaccessgranted".equals( name ) ) return; // this is hardcoded BExpressionLookupValue newValue = addLookupValue( name, value, null ); // add aliases @@ -351,7 +284,7 @@ public abstract class BExpressionContext requests ++; lookupDataValid = false; // this is an assertion for a nasty pifall - int inverseBitByteIndex = meta.readVarLength ? 0 : 7; + int inverseBitByteIndex = 0; // calc hash bucket from crc int lastHashBucket = currentHashBucket; diff --git a/brouter-expressions/src/main/java/btools/expressions/BExpressionMetaData.java b/brouter-expressions/src/main/java/btools/expressions/BExpressionMetaData.java index d50c498..477de29 100644 --- a/brouter-expressions/src/main/java/btools/expressions/BExpressionMetaData.java +++ b/brouter-expressions/src/main/java/btools/expressions/BExpressionMetaData.java @@ -26,11 +26,9 @@ public final class BExpressionMetaData private static final String CONTEXT_TAG = "---context:"; private static final String VERSION_TAG = "---lookupversion:"; private static final String MINOR_VERSION_TAG = "---minorversion:"; - private static final String VARLENGTH_TAG = "---readvarlength"; public short lookupVersion = -1; public short lookupMinorVersion = -1; - public boolean readVarLength = false; private HashMap listeners = new HashMap(); @@ -68,11 +66,6 @@ public final class BExpressionMetaData lookupMinorVersion = Short.parseShort( line.substring( MINOR_VERSION_TAG.length() ) ); continue; } - if ( line.startsWith( VARLENGTH_TAG ) ) - { - readVarLength = true; - continue; - } if ( ctx != null ) ctx.parseMetaLine( line ); } br.close(); diff --git a/brouter-map-creator/src/main/java/btools/mapcreator/OsmNodeP.java b/brouter-map-creator/src/main/java/btools/mapcreator/OsmNodeP.java index a95c53f..cdbf73f 100644 --- a/brouter-map-creator/src/main/java/btools/mapcreator/OsmNodeP.java +++ b/brouter-map-creator/src/main/java/btools/mapcreator/OsmNodeP.java @@ -101,7 +101,7 @@ public class OsmNodeP extends OsmLinkP implements Comparable return null; } - public void writeNodeData( ByteDataWriter os, boolean writeVarLength, byte[] abBuf ) throws IOException + public void writeNodeData( ByteDataWriter os, byte[] abBuf ) throws IOException { int lonIdx = ilon/62500; int latIdx = ilat/62500; @@ -156,7 +156,7 @@ public class OsmNodeP extends OsmLinkP implements Comparable int writedescbit = 0; if ( skipDetailBit == 0 ) // check if description changed { - int inverseBitByteIndex = writeVarLength ? 0 : 7; + int inverseBitByteIndex = 0; boolean inverseDirection = link.isReverse( origin ); byte[] ab = link.descriptionBitmap; int abLen = ab.length; @@ -196,12 +196,12 @@ public class OsmNodeP extends OsmLinkP implements Comparable if ( writedescbit != 0 ) { // write the way description, code direction into the first bit - if ( writeVarLength ) os2.writeByte( lastDescription.length ); + os2.writeByte( lastDescription.length ); os2.write( lastDescription ); } if ( nodedescbit != 0 ) { - if ( writeVarLength ) os2.writeByte( nodeDescription.length ); + os2.writeByte( nodeDescription.length ); os2.write( nodeDescription ); nodeDescription = null; } diff --git a/brouter-map-creator/src/main/java/btools/mapcreator/WayLinker.java b/brouter-map-creator/src/main/java/btools/mapcreator/WayLinker.java index fca9173..a1d3f02 100644 --- a/brouter-map-creator/src/main/java/btools/mapcreator/WayLinker.java +++ b/brouter-map-creator/src/main/java/btools/mapcreator/WayLinker.java @@ -49,7 +49,6 @@ public class WayLinker extends MapCreatorBase private CompactLongSet borderSet; private short lookupVersion; private short lookupMinorVersion; - private boolean writeVarLength; private long creationTimeStamp; @@ -97,7 +96,6 @@ public class WayLinker extends MapCreatorBase lookupVersion = meta.lookupVersion; lookupMinorVersion = meta.lookupMinorVersion; - writeVarLength = meta.readVarLength; expctxWay.parseFile( profileFile, "global" ); expctxNode.parseFile( profileFile, "global" ); @@ -302,7 +300,7 @@ public class WayLinker extends MapCreatorBase for( int ni=0; ni size / 2 ) // garbage collection diff --git a/brouter-mapaccess/src/main/java/btools/mapaccess/NodesCache.java b/brouter-mapaccess/src/main/java/btools/mapaccess/NodesCache.java index a531fa4..034ff4c 100644 --- a/brouter-mapaccess/src/main/java/btools/mapaccess/NodesCache.java +++ b/brouter-mapaccess/src/main/java/btools/mapaccess/NodesCache.java @@ -19,7 +19,6 @@ public final class NodesCache private OsmNodesMap nodesMap; private int lookupVersion; private int lookupMinorVersion; - private boolean readVarLength; private boolean carMode; private boolean forceSecondaryData; private String currentFileName; @@ -40,13 +39,12 @@ public final class NodesCache private boolean garbageCollectionEnabled = false; - public NodesCache( String segmentDir, OsmNodesMap nodesMap, int lookupVersion, int minorVersion, boolean varLen, boolean carMode, boolean forceSecondaryData, NodesCache oldCache ) + public NodesCache( String segmentDir, OsmNodesMap nodesMap, int lookupVersion, int minorVersion, boolean carMode, boolean forceSecondaryData, NodesCache oldCache ) { this.segmentDir = new File( segmentDir ); this.nodesMap = nodesMap; this.lookupVersion = lookupVersion; this.lookupMinorVersion = minorVersion; - this.readVarLength = varLen; this.carMode = carMode; this.forceSecondaryData = forceSecondaryData; @@ -177,7 +175,7 @@ public final class NodesCache checkEnableCacheCleaning(); - segment = new MicroCache( osmf, lonIdx80, latIdx80, iobuffer, readVarLength ); + segment = new MicroCache( osmf, lonIdx80, latIdx80, iobuffer ); cacheSum += segment.getDataSize(); osmf.microCaches[subIdx] = segment; segmentList.add( segment ); diff --git a/brouter-mapaccess/src/main/java/btools/mapaccess/OsmNode.java b/brouter-mapaccess/src/main/java/btools/mapaccess/OsmNode.java index d607068..9e539d5 100644 --- a/brouter-mapaccess/src/main/java/btools/mapaccess/OsmNode.java +++ b/brouter-mapaccess/src/main/java/btools/mapaccess/OsmNode.java @@ -105,7 +105,7 @@ public class OsmNode implements OsmPos } - public void parseNodeBody( MicroCache is, OsmNodesMap hollowNodes, DistanceChecker dc, boolean readVarLength ) + public void parseNodeBody( MicroCache is, OsmNodesMap hollowNodes, DistanceChecker dc ) { ByteArrayUnifier abUnifier = hollowNodes.getByteArrayUnifier(); @@ -116,9 +116,6 @@ public class OsmNode implements OsmPos OsmLink firstHollowLink = firstlink; firstlink = null; - int lonIdx = ilon/62500; - int latIdx = ilat/62500; - while( is.hasMoreData() ) { int ilonref = ilon; @@ -133,44 +130,24 @@ public class OsmNode implements OsmPos for(;;) { int bitField = is.readByte(); - if ( readVarLength ) - { - int dlon = is.readVarLengthUnsigned(); - int dlat = is.readVarLengthUnsigned(); - if ( (bitField & SIGNLON_BITMASK) != 0 ) { dlon = -dlon;} - if ( (bitField & SIGNLAT_BITMASK) != 0 ) { dlat = -dlat;} - linklon = ilonref + dlon; - linklat = ilatref + dlat; - ilonref = linklon; - ilatref = linklat; - } - else - { - if ( (bitField & EXTERNAL_BITMASK) != 0 ) - { - // full position for external target - linklon = is.readInt(); - linklat = is.readInt(); - } - else - { - // reduced position for internal target - linklon = is.readShort(); - linklat = is.readShort(); - linklon += lonIdx*62500 + 31250; - linklat += latIdx*62500 + 31250; - } - } + int dlon = is.readVarLengthUnsigned(); + int dlat = is.readVarLengthUnsigned(); + if ( (bitField & SIGNLON_BITMASK) != 0 ) { dlon = -dlon;} + if ( (bitField & SIGNLAT_BITMASK) != 0 ) { dlat = -dlat;} + linklon = ilonref + dlon; + linklat = ilatref + dlat; + ilonref = linklon; + ilatref = linklat; // read variable length or old 8 byte fixed, and ensure that 8 bytes is only fixed if ( (bitField & WRITEDESC_BITMASK ) != 0 ) { - byte[] ab = new byte[readVarLength ? is.readByte() : 8 ]; + byte[] ab = new byte[is.readByte()]; is.readFully( ab ); description = abUnifier.unify( ab ); } if ( (bitField & NODEDESC_BITMASK ) != 0 ) { - byte[] ab = new byte[readVarLength ? is.readByte() : 8 ]; + byte[] ab = new byte[is.readByte()]; is.readFully( ab ); nodeDescription = abUnifier.unify( ab ); } @@ -198,7 +175,7 @@ public class OsmNode implements OsmPos trans.ilon = linklon; trans.ilat = linklat; trans.descriptionBitmap = description; - trans.selev = readVarLength ? (short)(selev + is.readVarLengthSigned()) : is.readShort(); + trans.selev = (short)(selev + is.readVarLengthSigned()); if ( lastTransferNode == null ) { firstTransferNode = trans; @@ -248,7 +225,6 @@ public class OsmNode implements OsmPos OsmNode t = l.targetNode; if ( t.ilon == linklon && t.ilat == linklat ) { -System.out.println( "found target in hollow links: " + t.getIdFromPos() ); tn = t; break; } @@ -265,8 +241,6 @@ System.out.println( "found target in hollow links: " + t.getIdFromPos() ); hollowNodes.put( targetNodeId, tn ); } -System.out.println( "registering : " + getIdFromPos() + " at hollow " + tn.getIdFromPos() ); - OsmLink hollowLink = new OsmLink(); hollowLink.targetNode = this; tn.addLink( hollowLink ); // make us known at the hollow link diff --git a/brouter-mapaccess/src/main/java/btools/mapaccess/PhysicalFile.java b/brouter-mapaccess/src/main/java/btools/mapaccess/PhysicalFile.java index 8ecaa77..7fd85ad 100644 --- a/brouter-mapaccess/src/main/java/btools/mapaccess/PhysicalFile.java +++ b/brouter-mapaccess/src/main/java/btools/mapaccess/PhysicalFile.java @@ -39,7 +39,7 @@ final public class PhysicalFile if ( osmf.microCaches != null ) for( int lonIdx80=0; lonIdx80<80; lonIdx80++ ) for( int latIdx80=0; latIdx80<80; latIdx80++ ) - new MicroCache( osmf, lonIdx80, latIdx80, iobuffer, true ); // TODO: readVarLength ? + new MicroCache( osmf, lonIdx80, latIdx80, iobuffer ); } } catch( IllegalArgumentException iae ) diff --git a/misc/profiles2/lookups.dat b/misc/profiles2/lookups.dat index 8f9b0dd..ff5ed3b 100644 --- a/misc/profiles2/lookups.dat +++ b/misc/profiles2/lookups.dat @@ -1,6 +1,5 @@ ---lookupversion:10 ---minorversion:5 ----readvarlength ---context:way