removed old format support

This commit is contained in:
Arndt 2015-08-28 17:49:35 +02:00
parent 87fe904e7b
commit 2cec35f3cc
10 changed files with 35 additions and 158 deletions

View file

@ -529,7 +529,7 @@ public class RoutingEngine extends Thread
{ {
nodesMap = new OsmNodesMap(); nodesMap = new OsmNodesMap();
BExpressionContext ctx = routingContext.expctxWay; 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 ) private OsmNode getStartNode( long startId )

View file

@ -123,8 +123,6 @@ public abstract class BExpressionContext
public byte[] encode( int[] ld ) public byte[] encode( int[] ld )
{ {
if ( !meta.readVarLength ) return encodeFix( ld );
// start with first bit hardwired ("reversedirection") // start with first bit hardwired ("reversedirection")
BitCoderContext ctx = new BitCoderContext( abBuf ); BitCoderContext ctx = new BitCoderContext( abBuf );
ctx.encodeBit( ld[0] != 0 ); ctx.encodeBit( ld[0] != 0 );
@ -170,36 +168,6 @@ public abstract class BExpressionContext
return ab; 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 * decode byte array to internal lookup data
@ -215,8 +183,6 @@ public abstract class BExpressionContext
*/ */
private void decode( int[] ld, boolean inverseDirection, byte[] ab ) private void decode( int[] ld, boolean inverseDirection, byte[] ab )
{ {
if ( !meta.readVarLength ) { decodeFix( ld, ab ); return; }
BitCoderContext ctx = new BitCoderContext(ab); BitCoderContext ctx = new BitCoderContext(ab);
// start with first bit hardwired ("reversedirection") // start with first bit hardwired ("reversedirection")
@ -241,36 +207,6 @@ public abstract class BExpressionContext
while( inum < ld.length ) ld[inum++] = 0; 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 ) public String getKeyValueDescription( boolean inverseDirection, byte[] ab )
{ {
StringBuilder sb = new StringBuilder( 200 ); StringBuilder sb = new StringBuilder( 200 );
@ -300,8 +236,6 @@ public abstract class BExpressionContext
int idx = name.indexOf( ';' ); int idx = name.indexOf( ';' );
if ( idx >= 0 ) name = name.substring( 0, idx ); if ( idx >= 0 ) name = name.substring( 0, idx );
if ( meta.readVarLength )
{
if ( !fixTagsWritten ) if ( !fixTagsWritten )
{ {
fixTagsWritten = true; fixTagsWritten = true;
@ -310,7 +244,6 @@ public abstract class BExpressionContext
} }
if ( "reversedirection".equals( name ) ) return; // this is hardcoded if ( "reversedirection".equals( name ) ) return; // this is hardcoded
if ( "nodeaccessgranted".equals( name ) ) return; // this is hardcoded if ( "nodeaccessgranted".equals( name ) ) return; // this is hardcoded
}
BExpressionLookupValue newValue = addLookupValue( name, value, null ); BExpressionLookupValue newValue = addLookupValue( name, value, null );
// add aliases // add aliases
@ -351,7 +284,7 @@ public abstract class BExpressionContext
requests ++; requests ++;
lookupDataValid = false; // this is an assertion for a nasty pifall lookupDataValid = false; // this is an assertion for a nasty pifall
int inverseBitByteIndex = meta.readVarLength ? 0 : 7; int inverseBitByteIndex = 0;
// calc hash bucket from crc // calc hash bucket from crc
int lastHashBucket = currentHashBucket; int lastHashBucket = currentHashBucket;

View file

@ -26,11 +26,9 @@ public final class BExpressionMetaData
private static final String CONTEXT_TAG = "---context:"; private static final String CONTEXT_TAG = "---context:";
private static final String VERSION_TAG = "---lookupversion:"; private static final String VERSION_TAG = "---lookupversion:";
private static final String MINOR_VERSION_TAG = "---minorversion:"; private static final String MINOR_VERSION_TAG = "---minorversion:";
private static final String VARLENGTH_TAG = "---readvarlength";
public short lookupVersion = -1; public short lookupVersion = -1;
public short lookupMinorVersion = -1; public short lookupMinorVersion = -1;
public boolean readVarLength = false;
private HashMap<String,BExpressionContext> listeners = new HashMap<String,BExpressionContext>(); private HashMap<String,BExpressionContext> listeners = new HashMap<String,BExpressionContext>();
@ -68,11 +66,6 @@ public final class BExpressionMetaData
lookupMinorVersion = Short.parseShort( line.substring( MINOR_VERSION_TAG.length() ) ); lookupMinorVersion = Short.parseShort( line.substring( MINOR_VERSION_TAG.length() ) );
continue; continue;
} }
if ( line.startsWith( VARLENGTH_TAG ) )
{
readVarLength = true;
continue;
}
if ( ctx != null ) ctx.parseMetaLine( line ); if ( ctx != null ) ctx.parseMetaLine( line );
} }
br.close(); br.close();

View file

@ -101,7 +101,7 @@ public class OsmNodeP extends OsmLinkP implements Comparable<OsmNodeP>
return null; 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 lonIdx = ilon/62500;
int latIdx = ilat/62500; int latIdx = ilat/62500;
@ -156,7 +156,7 @@ public class OsmNodeP extends OsmLinkP implements Comparable<OsmNodeP>
int writedescbit = 0; int writedescbit = 0;
if ( skipDetailBit == 0 ) // check if description changed if ( skipDetailBit == 0 ) // check if description changed
{ {
int inverseBitByteIndex = writeVarLength ? 0 : 7; int inverseBitByteIndex = 0;
boolean inverseDirection = link.isReverse( origin ); boolean inverseDirection = link.isReverse( origin );
byte[] ab = link.descriptionBitmap; byte[] ab = link.descriptionBitmap;
int abLen = ab.length; int abLen = ab.length;
@ -196,12 +196,12 @@ public class OsmNodeP extends OsmLinkP implements Comparable<OsmNodeP>
if ( writedescbit != 0 ) if ( writedescbit != 0 )
{ {
// write the way description, code direction into the first bit // write the way description, code direction into the first bit
if ( writeVarLength ) os2.writeByte( lastDescription.length ); os2.writeByte( lastDescription.length );
os2.write( lastDescription ); os2.write( lastDescription );
} }
if ( nodedescbit != 0 ) if ( nodedescbit != 0 )
{ {
if ( writeVarLength ) os2.writeByte( nodeDescription.length ); os2.writeByte( nodeDescription.length );
os2.write( nodeDescription ); os2.write( nodeDescription );
nodeDescription = null; nodeDescription = null;
} }

View file

@ -49,7 +49,6 @@ public class WayLinker extends MapCreatorBase
private CompactLongSet borderSet; private CompactLongSet borderSet;
private short lookupVersion; private short lookupVersion;
private short lookupMinorVersion; private short lookupMinorVersion;
private boolean writeVarLength;
private long creationTimeStamp; private long creationTimeStamp;
@ -97,7 +96,6 @@ public class WayLinker extends MapCreatorBase
lookupVersion = meta.lookupVersion; lookupVersion = meta.lookupVersion;
lookupMinorVersion = meta.lookupMinorVersion; lookupMinorVersion = meta.lookupMinorVersion;
writeVarLength = meta.readVarLength;
expctxWay.parseFile( profileFile, "global" ); expctxWay.parseFile( profileFile, "global" );
expctxNode.parseFile( profileFile, "global" ); expctxNode.parseFile( profileFile, "global" );
@ -302,7 +300,7 @@ public class WayLinker extends MapCreatorBase
for( int ni=0; ni<subList.size(); ni++ ) for( int ni=0; ni<subList.size(); ni++ )
{ {
OsmNodeP n = subList.get(ni); OsmNodeP n = subList.get(ni);
n.writeNodeData( dos, writeVarLength, abBuf ); n.writeNodeData( dos, abBuf );
} }
byte[] subBytes = dos.toByteArray(); byte[] subBytes = dos.toByteArray();
pos += subBytes.length + 4; // reserve 4 bytes for crc pos += subBytes.length + 4; // reserve 4 bytes for crc

View file

@ -21,8 +21,6 @@ final class MicroCache extends ByteDataReader
private int delbytes = 0; private int delbytes = 0;
private int p2size; // next power of 2 of size private int p2size; // next power of 2 of size
private boolean readVarLength;
// the object parsing position and length // the object parsing position and length
private int aboffsetEnd; private int aboffsetEnd;
@ -31,11 +29,9 @@ final class MicroCache extends ByteDataReader
boolean virgin = true; boolean virgin = true;
boolean ghost = false; boolean ghost = false;
public MicroCache( OsmFile segfile, int lonIdx80, int latIdx80, byte[] iobuffer, boolean readVarLength ) throws Exception public MicroCache( OsmFile segfile, int lonIdx80, int latIdx80, byte[] iobuffer ) throws Exception
{ {
super( null ); super( null );
this.readVarLength = readVarLength;
int lonDegree = lonIdx80/80; int lonDegree = lonIdx80/80;
int latDegree = latIdx80/80; int latDegree = latIdx80/80;
@ -67,31 +63,17 @@ final class MicroCache extends ByteDataReader
{ {
int ilon = readShort(); int ilon = readShort();
int ilat = readShort(); int ilat = readShort();
int bodySize = readVarLength ? readVarLengthUnsigned() : readInt(); int bodySize = readVarLengthUnsigned();
// kack for the old format crc
if ( !readVarLength && ilon == Short.MAX_VALUE && ilat == Short.MAX_VALUE )
{
int crc = Crc32.crc( ab, 0, aboffset-8 ); // old format crc
if ( crc != readInt() )
{
throw new IOException( "checkum-error" );
}
size = i;
break;
}
aboffset += bodySize; aboffset += bodySize;
nbytes += bodySize; nbytes += bodySize;
} }
if ( readVarLength ) // new format crc
{
int crc = Crc32.crc( ab, 0, aboffset ); int crc = Crc32.crc( ab, 0, aboffset );
if ( crc != readInt() ) if ( crc != readInt() )
{ {
throw new IOException( "checkum error" ); throw new IOException( "checkum error" );
} }
}
// new array with only net data // new array with only net data
byte[] nab = new byte[nbytes]; byte[] nab = new byte[nbytes];
@ -111,7 +93,7 @@ final class MicroCache extends ByteDataReader
long nodeId = ((long)ilon)<<32 | ilat; long nodeId = ((long)ilon)<<32 | ilat;
faid[i] = nodeId; faid[i] = nodeId;
int bodySize = readVarLength ? readVarLengthUnsigned() : readInt(); int bodySize = readVarLengthUnsigned();
fapos[i] = noffset; fapos[i] = noffset;
System.arraycopy( ab, aboffset, nab, noffset, bodySize ); System.arraycopy( ab, aboffset, nab, noffset, bodySize );
aboffset += bodySize; aboffset += bodySize;
@ -189,7 +171,7 @@ final class MicroCache extends ByteDataReader
long id = node.getIdFromPos(); long id = node.getIdFromPos();
if ( getAndClear( id ) ) if ( getAndClear( id ) )
{ {
node.parseNodeBody( this, nodesMap, dc, readVarLength ); node.parseNodeBody( this, nodesMap, dc );
} }
if ( doCollect && delcount > size / 2 ) // garbage collection if ( doCollect && delcount > size / 2 ) // garbage collection

View file

@ -19,7 +19,6 @@ public final class NodesCache
private OsmNodesMap nodesMap; private OsmNodesMap nodesMap;
private int lookupVersion; private int lookupVersion;
private int lookupMinorVersion; private int lookupMinorVersion;
private boolean readVarLength;
private boolean carMode; private boolean carMode;
private boolean forceSecondaryData; private boolean forceSecondaryData;
private String currentFileName; private String currentFileName;
@ -40,13 +39,12 @@ public final class NodesCache
private boolean garbageCollectionEnabled = false; 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.segmentDir = new File( segmentDir );
this.nodesMap = nodesMap; this.nodesMap = nodesMap;
this.lookupVersion = lookupVersion; this.lookupVersion = lookupVersion;
this.lookupMinorVersion = minorVersion; this.lookupMinorVersion = minorVersion;
this.readVarLength = varLen;
this.carMode = carMode; this.carMode = carMode;
this.forceSecondaryData = forceSecondaryData; this.forceSecondaryData = forceSecondaryData;
@ -177,7 +175,7 @@ public final class NodesCache
checkEnableCacheCleaning(); checkEnableCacheCleaning();
segment = new MicroCache( osmf, lonIdx80, latIdx80, iobuffer, readVarLength ); segment = new MicroCache( osmf, lonIdx80, latIdx80, iobuffer );
cacheSum += segment.getDataSize(); cacheSum += segment.getDataSize();
osmf.microCaches[subIdx] = segment; osmf.microCaches[subIdx] = segment;
segmentList.add( segment ); segmentList.add( segment );

View file

@ -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(); ByteArrayUnifier abUnifier = hollowNodes.getByteArrayUnifier();
@ -116,9 +116,6 @@ public class OsmNode implements OsmPos
OsmLink firstHollowLink = firstlink; OsmLink firstHollowLink = firstlink;
firstlink = null; firstlink = null;
int lonIdx = ilon/62500;
int latIdx = ilat/62500;
while( is.hasMoreData() ) while( is.hasMoreData() )
{ {
int ilonref = ilon; int ilonref = ilon;
@ -133,8 +130,6 @@ public class OsmNode implements OsmPos
for(;;) for(;;)
{ {
int bitField = is.readByte(); int bitField = is.readByte();
if ( readVarLength )
{
int dlon = is.readVarLengthUnsigned(); int dlon = is.readVarLengthUnsigned();
int dlat = is.readVarLengthUnsigned(); int dlat = is.readVarLengthUnsigned();
if ( (bitField & SIGNLON_BITMASK) != 0 ) { dlon = -dlon;} if ( (bitField & SIGNLON_BITMASK) != 0 ) { dlon = -dlon;}
@ -143,34 +138,16 @@ public class OsmNode implements OsmPos
linklat = ilatref + dlat; linklat = ilatref + dlat;
ilonref = linklon; ilonref = linklon;
ilatref = linklat; 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;
}
}
// read variable length or old 8 byte fixed, and ensure that 8 bytes is only fixed // read variable length or old 8 byte fixed, and ensure that 8 bytes is only fixed
if ( (bitField & WRITEDESC_BITMASK ) != 0 ) if ( (bitField & WRITEDESC_BITMASK ) != 0 )
{ {
byte[] ab = new byte[readVarLength ? is.readByte() : 8 ]; byte[] ab = new byte[is.readByte()];
is.readFully( ab ); is.readFully( ab );
description = abUnifier.unify( ab ); description = abUnifier.unify( ab );
} }
if ( (bitField & NODEDESC_BITMASK ) != 0 ) if ( (bitField & NODEDESC_BITMASK ) != 0 )
{ {
byte[] ab = new byte[readVarLength ? is.readByte() : 8 ]; byte[] ab = new byte[is.readByte()];
is.readFully( ab ); is.readFully( ab );
nodeDescription = abUnifier.unify( ab ); nodeDescription = abUnifier.unify( ab );
} }
@ -198,7 +175,7 @@ public class OsmNode implements OsmPos
trans.ilon = linklon; trans.ilon = linklon;
trans.ilat = linklat; trans.ilat = linklat;
trans.descriptionBitmap = description; trans.descriptionBitmap = description;
trans.selev = readVarLength ? (short)(selev + is.readVarLengthSigned()) : is.readShort(); trans.selev = (short)(selev + is.readVarLengthSigned());
if ( lastTransferNode == null ) if ( lastTransferNode == null )
{ {
firstTransferNode = trans; firstTransferNode = trans;
@ -248,7 +225,6 @@ public class OsmNode implements OsmPos
OsmNode t = l.targetNode; OsmNode t = l.targetNode;
if ( t.ilon == linklon && t.ilat == linklat ) if ( t.ilon == linklon && t.ilat == linklat )
{ {
System.out.println( "found target in hollow links: " + t.getIdFromPos() );
tn = t; tn = t;
break; break;
} }
@ -265,8 +241,6 @@ System.out.println( "found target in hollow links: " + t.getIdFromPos() );
hollowNodes.put( targetNodeId, tn ); hollowNodes.put( targetNodeId, tn );
} }
System.out.println( "registering : " + getIdFromPos() + " at hollow " + tn.getIdFromPos() );
OsmLink hollowLink = new OsmLink(); OsmLink hollowLink = new OsmLink();
hollowLink.targetNode = this; hollowLink.targetNode = this;
tn.addLink( hollowLink ); // make us known at the hollow link tn.addLink( hollowLink ); // make us known at the hollow link

View file

@ -39,7 +39,7 @@ final public class PhysicalFile
if ( osmf.microCaches != null ) if ( osmf.microCaches != null )
for( int lonIdx80=0; lonIdx80<80; lonIdx80++ ) for( int lonIdx80=0; lonIdx80<80; lonIdx80++ )
for( int latIdx80=0; latIdx80<80; latIdx80++ ) 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 ) catch( IllegalArgumentException iae )

View file

@ -1,6 +1,5 @@
---lookupversion:10 ---lookupversion:10
---minorversion:5 ---minorversion:5
---readvarlength
---context:way ---context:way