variable length tag descriptions (regtest glitches)

This commit is contained in:
Arndt 2014-05-31 09:44:22 +02:00
parent 1633ae78e3
commit 8368df6bcf
8 changed files with 54 additions and 54 deletions

View file

@ -103,7 +103,6 @@ final class OsmPath implements OsmLinkHolder
OsmTransferNode transferNode = link.decodeFirsttransfer(); OsmTransferNode transferNode = link.decodeFirsttransfer();
OsmNode targetNode = link.targetNode; OsmNode targetNode = link.targetNode;
byte[] lastDescription = null;
String lastMessage = null; String lastMessage = null;
for(;;) for(;;)
{ {
@ -132,15 +131,17 @@ final class OsmPath implements OsmLinkHolder
if ( description == null ) throw new IllegalArgumentException( "null description for class: " + transferNode.getClass() + "/" + link.getClass() + " counterlinkwritten=" + link.counterLinkWritten ); if ( description == null ) throw new IllegalArgumentException( "null description for class: " + transferNode.getClass() + "/" + link.getClass() + " counterlinkwritten=" + link.counterLinkWritten );
} }
rc.messageHandler.setCurrentPos( lon2, lat2 );
boolean sameData = rc.expctxWay.evaluate( link.counterLinkWritten, description, rc.messageHandler );
// if way description changed, store message // if way description changed, store message
if ( lastMessage != null && description != lastDescription ) if ( lastMessage != null && !sameData )
{ {
originElement.message = lastMessage; originElement.message = lastMessage;
linkdist = 0; linkdist = 0;
linkelevationcost = 0; linkelevationcost = 0;
linkturncost = 0; linkturncost = 0;
} }
lastDescription = description;
int dist = rc.calcDistance( lon1, lat1, lon2, lat2 ); int dist = rc.calcDistance( lon1, lat1, lon2, lat2 );
int elefactor = 250000; int elefactor = 250000;
@ -176,8 +177,6 @@ final class OsmPath implements OsmLinkHolder
linkdist += dist; linkdist += dist;
linkdisttotal += dist; linkdisttotal += dist;
rc.messageHandler.setCurrentPos( lon2, lat2 );
rc.expctxWay.evaluate( link instanceof OsmLinkReverse, description, rc.messageHandler );
// *** penalty for way-change // *** penalty for way-change
if ( origin.originElement != null ) if ( origin.originElement != null )
@ -261,7 +260,7 @@ final class OsmPath implements OsmLinkHolder
+ iCost + "\t" + iCost + "\t"
+ linkelevationcost + linkelevationcost
+ "\t" + linkturncost + "\t" + linkturncost
+ rc.expctxWay.getCsvDescription( description ); + rc.expctxWay.getCsvDescription( link.counterLinkWritten, description );
} }
if ( stopAtEndpoint ) if ( stopAtEndpoint )

View file

@ -296,7 +296,7 @@ public class RoutingEngine extends Thread
startLink.addLinkHolder( startPath ); startLink.addLinkHolder( startPath );
for( OsmLink link = n.firstlink; link != null; link = link.next ) for( OsmLink link = n.firstlink; link != null; link = link.next )
{ {
if ( link.counterLinkWritten ) continue; // reverse link not found if ( link.descriptionBitmap == null ) continue; // reverse link not found
OsmNode nextNode = link.targetNode; OsmNode nextNode = link.targetNode;
if ( nextNode.isHollow() ) continue; // border node? if ( nextNode.isHollow() ) continue; // border node?
if ( nextNode.firstlink == null ) continue; // don't care about dead ends if ( nextNode.firstlink == null ) continue; // don't care about dead ends
@ -346,7 +346,6 @@ public class RoutingEngine extends Thread
{ {
link.descriptionBitmap = rlink.descriptionBitmap; link.descriptionBitmap = rlink.descriptionBitmap;
link.firsttransferBytes = rlink.firsttransferBytes; link.firsttransferBytes = rlink.firsttransferBytes;
link.counterLinkWritten = false;
} }
} }
} }

View file

@ -208,16 +208,22 @@ public final class BExpressionContext
} }
} }
public String getCsvDescription( byte[] ab ) public String getCsvDescription( boolean inverseDirection, byte[] ab )
{ {
StringBuilder sb = new StringBuilder( 200 ); int inverseBitByteIndex = readVarLength ? 0 : 7;
decode( lookupData, ab ); int abLen = ab.length;
for( int inum = 0; inum < lookupValues.size(); inum++ ) // loop over lookup names byte[] ab_copy = new byte[abLen];
{ System.arraycopy( ab, 0, ab_copy, 0 , abLen );
BExpressionLookupValue[] va = lookupValues.get(inum); if ( inverseDirection ) ab_copy[inverseBitByteIndex] ^= 1;
sb.append( '\t' ).append( va[lookupData[inum]].toString() );
} StringBuilder sb = new StringBuilder( 200 );
return sb.toString(); decode( lookupData, ab_copy );
for( int inum = 0; inum < lookupValues.size(); inum++ ) // loop over lookup names
{
BExpressionLookupValue[] va = lookupValues.get(inum);
sb.append( '\t' ).append( va[lookupData[inum]].toString() );
}
return sb.toString();
} }
public String getCsvHeader() public String getCsvHeader()
@ -327,12 +333,15 @@ public final class BExpressionContext
public void evaluate( boolean inverseDirection, byte[] ab, BExpressionReceiver receiver ) /**
* evaluates the data in the given byte array
*
* @return true if the data is equivilant to the last calls data
*/
public boolean evaluate( boolean inverseDirection, byte[] ab, BExpressionReceiver receiver )
{ {
int inverseBitByteIndex = readVarLength ? 0 : 7; int inverseBitByteIndex = readVarLength ? 0 : 7;
_receiver = receiver;
int abLen = ab.length; int abLen = ab.length;
boolean equalsCurrent = currentHashBucket >= 0 && abLen == currentByteArray.length; boolean equalsCurrent = currentHashBucket >= 0 && abLen == currentByteArray.length;
if ( equalsCurrent ) if ( equalsCurrent )
@ -348,7 +357,7 @@ public final class BExpressionContext
if ( equalsCurrent ) if ( equalsCurrent )
{ {
return; return true;
} }
else else
{ {
@ -371,11 +380,13 @@ public final class BExpressionContext
if ( abBucket[i] != currentByteArray[i] ) { hashBucketEquals = false; break; } if ( abBucket[i] != currentByteArray[i] ) { hashBucketEquals = false; break; }
} }
} }
if ( hashBucketEquals ) return; if ( hashBucketEquals ) return false;
_arrayBitmap[currentHashBucket] = currentByteArray; _arrayBitmap[currentHashBucket] = currentByteArray;
decode( lookupData, ab ); _receiver = receiver;
decode( lookupData, currentByteArray );
evaluate( lookupData ); evaluate( lookupData );
_arrayCostfactor[currentHashBucket] = variableData[costfactorIdx]; _arrayCostfactor[currentHashBucket] = variableData[costfactorIdx];
@ -384,6 +395,7 @@ public final class BExpressionContext
_arrayNodeAccessGranted[currentHashBucket] = variableData[nodeaccessgrantedIdx]; _arrayNodeAccessGranted[currentHashBucket] = variableData[nodeaccessgrantedIdx];
_receiver = null; _receiver = null;
return false;
} }
public void dumpStatistics() public void dumpStatistics()

View file

@ -83,7 +83,7 @@ public class WayLinker extends MapCreatorBase
creationTimeStamp = System.currentTimeMillis(); creationTimeStamp = System.currentTimeMillis();
abUnifier = new ByteArrayUnifier( 16384 ); abUnifier = new ByteArrayUnifier( 16384, false );
// then process all segments // then process all segments
new WayIterator( this, true ).processDir( wayTilesIn, ".wt5" ); new WayIterator( this, true ).processDir( wayTilesIn, ".wt5" );

View file

@ -1,11 +0,0 @@
/**
* Dummy child of OsmLink just to encode the reverse-bit
*
* @author ab
*/
package btools.mapaccess;
public class OsmLinkReverse extends OsmLink
{
}

View file

@ -240,12 +240,12 @@ public class OsmNode implements OsmPos
// compute the reverse link // compute the reverse link
if ( !link.counterLinkWritten ) if ( !link.counterLinkWritten )
{ {
OsmLink rlink = new OsmLinkReverse(); OsmLink rlink = new OsmLink();
byte[] linkDescriptionBitmap = link.descriptionBitmap;
rlink.ilonOrigin = tn.ilon; rlink.ilonOrigin = tn.ilon;
rlink.ilatOrigin = tn.ilat; rlink.ilatOrigin = tn.ilat;
rlink.targetNode = this; rlink.targetNode = this;
rlink.descriptionBitmap = link.descriptionBitmap; // default for no transfer-nodes rlink.descriptionBitmap = linkDescriptionBitmap; // default for no transfer-nodes
OsmTransferNode previous = null; OsmTransferNode previous = null;
OsmTransferNode rtrans = null; OsmTransferNode rtrans = null;
for( OsmTransferNode trans = firstTransferNode; trans != null; trans = trans.next ) for( OsmTransferNode trans = firstTransferNode; trans != null; trans = trans.next )
@ -263,7 +263,7 @@ public class OsmNode implements OsmPos
rtrans.ilat = trans.ilat; rtrans.ilat = trans.ilat;
rtrans.selev = trans.selev; rtrans.selev = trans.selev;
rtrans.next = previous; rtrans.next = previous;
rtrans.descriptionBitmap = trans.descriptionBitmap; rtrans.descriptionBitmap = linkDescriptionBitmap;
previous = rtrans; previous = rtrans;
} }
rlink.encodeFirsttransfer(rtrans); rlink.encodeFirsttransfer(rtrans);
@ -332,17 +332,6 @@ public class OsmNode implements OsmPos
} }
} }
// mark the link to the given node as written,
// don't want to write the counter-direction
// in full details
public void markLinkWritten( OsmNode t )
{
for( OsmLink link = firstlink; link != null; link = link.next )
{
if ( link.targetNode == t) link.counterLinkWritten = true;
}
}
public OsmLink getReverseLink( int lon, int lat ) public OsmLink getReverseLink( int lon, int lat )
{ {
for( OsmLink rlink = firstreverse; rlink != null; rlink = rlink.next ) for( OsmLink rlink = firstreverse; rlink != null; rlink = rlink.next )

View file

@ -13,7 +13,7 @@ public final class OsmNodesMap
{ {
private HashMap<Long,OsmNode> hmap = new HashMap<Long,OsmNode>(); private HashMap<Long,OsmNode> hmap = new HashMap<Long,OsmNode>();
private ByteArrayUnifier abUnifier = new ByteArrayUnifier( 16384 ); private ByteArrayUnifier abUnifier = new ByteArrayUnifier( 16384, false );
public ByteArrayUnifier getByteArrayUnifier() public ByteArrayUnifier getByteArrayUnifier()
{ {

View file

@ -3,12 +3,14 @@ package btools.util;
public final class ByteArrayUnifier public final class ByteArrayUnifier
{ {
private byte[][] byteArrayCache; private byte[][] byteArrayCache;
private int[] crcCrosscheck;
private int size; private int size;
public ByteArrayUnifier( int size ) public ByteArrayUnifier( int size, boolean validateImmutability )
{ {
this.size = size; this.size = size;
byteArrayCache = new byte[size][]; byteArrayCache = new byte[size][];
if ( validateImmutability ) crcCrosscheck = new int[size];
} }
/** /**
@ -20,7 +22,7 @@ public final class ByteArrayUnifier
*/ */
public byte[] unify( byte[] ab ) public byte[] unify( byte[] ab )
{ {
int n = ab.length; int n = ab.length;
int crc = Crc32.crc( ab, 0, n ); int crc = Crc32.crc( ab, 0, n );
int idx = (crc & 0xfffffff) % size; int idx = (crc & 0xfffffff) % size;
byte[] abc = byteArrayCache[idx]; byte[] abc = byteArrayCache[idx];
@ -34,6 +36,16 @@ public final class ByteArrayUnifier
} }
if ( i == n ) return abc; if ( i == n ) return abc;
} }
if ( crcCrosscheck != null )
{
if ( byteArrayCache[idx] != null )
{
byte[] abold = byteArrayCache[idx];
int crcold = Crc32.crc( abold, 0, abold.length );
if ( crcold != crcCrosscheck[idx] ) throw new IllegalArgumentException( "ByteArrayUnifier: immutablity validation failed!" );
}
crcCrosscheck[idx] = crc;
}
byteArrayCache[idx] = ab; byteArrayCache[idx] = ab;
return ab; return ab;
} }