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();
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 )

View file

@ -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;

View file

@ -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<String,BExpressionContext> listeners = new HashMap<String,BExpressionContext>();
@ -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();

View file

@ -101,7 +101,7 @@ public class OsmNodeP extends OsmLinkP implements Comparable<OsmNodeP>
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<OsmNodeP>
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<OsmNodeP>
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;
}

View file

@ -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<subList.size(); ni++ )
{
OsmNodeP n = subList.get(ni);
n.writeNodeData( dos, writeVarLength, abBuf );
n.writeNodeData( dos, abBuf );
}
byte[] subBytes = dos.toByteArray();
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 p2size; // next power of 2 of size
private boolean readVarLength;
// the object parsing position and length
private int aboffsetEnd;
@ -31,11 +29,9 @@ final class MicroCache extends ByteDataReader
boolean virgin = true;
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 );
this.readVarLength = readVarLength;
int lonDegree = lonIdx80/80;
int latDegree = latIdx80/80;
@ -67,30 +63,16 @@ final class MicroCache extends ByteDataReader
{
int ilon = 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;
nbytes += bodySize;
}
if ( readVarLength ) // new format crc
int crc = Crc32.crc( ab, 0, aboffset );
if ( crc != readInt() )
{
int crc = Crc32.crc( ab, 0, aboffset );
if ( crc != readInt() )
{
throw new IOException( "checkum error" );
}
throw new IOException( "checkum error" );
}
// new array with only net data
@ -111,7 +93,7 @@ final class MicroCache extends ByteDataReader
long nodeId = ((long)ilon)<<32 | ilat;
faid[i] = nodeId;
int bodySize = readVarLength ? readVarLengthUnsigned() : readInt();
int bodySize = readVarLengthUnsigned();
fapos[i] = noffset;
System.arraycopy( ab, aboffset, nab, noffset, bodySize );
aboffset += bodySize;
@ -189,7 +171,7 @@ final class MicroCache extends ByteDataReader
long id = node.getIdFromPos();
if ( getAndClear( id ) )
{
node.parseNodeBody( this, nodesMap, dc, readVarLength );
node.parseNodeBody( this, nodesMap, dc );
}
if ( doCollect && delcount > size / 2 ) // garbage collection

View file

@ -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 );

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();
@ -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

View file

@ -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 )

View file

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