memory squeezing pre-processor (link-identity)

This commit is contained in:
Arndt Brenschede 2014-12-23 18:00:23 +01:00
parent 8a6e601811
commit 176beba6f6
3 changed files with 61 additions and 40 deletions

View file

@ -17,11 +17,11 @@ public class OsmLinkP
/**
* The target is either the next link or the target node
*/
private OsmNodeP sourceNode;
private OsmNodeP targetNode;
protected OsmNodeP sourceNode;
protected OsmNodeP targetNode;
private OsmLinkP previous;
private OsmLinkP next;
protected OsmLinkP previous;
protected OsmLinkP next;
public OsmLinkP( OsmNodeP source, OsmNodeP target )
@ -30,6 +30,10 @@ public class OsmLinkP
targetNode = target;
}
protected OsmLinkP()
{
}
public final boolean counterLinkWritten( )
{
return descriptionBitmap == null;

View file

@ -9,7 +9,7 @@ import java.io.IOException;
import btools.util.ByteDataWriter;
public class OsmNodeP implements Comparable<OsmNodeP>
public class OsmNodeP extends OsmLinkP implements Comparable<OsmNodeP>
{
public static final int SIGNLON_BITMASK = 0x80;
public static final int SIGNLAT_BITMASK = 0x40;
@ -29,12 +29,6 @@ public class OsmNodeP implements Comparable<OsmNodeP>
public int ilon;
/**
* The links to other nodes
*/
public OsmLinkP firstlink = null;
/**
* The elevation
*/
@ -72,11 +66,36 @@ public class OsmNodeP implements Comparable<OsmNodeP>
}
// populate and return the inherited link, if available,
// else create a new one
public OsmLinkP createLink( OsmNodeP source )
{
if ( sourceNode == null && targetNode == null )
{
// inherited instance is available, use this
sourceNode = source;
targetNode = this;
source.addLink( this );
return this;
}
OsmLinkP link = new OsmLinkP( source, this );
addLink( link );
source.addLink( link );
return link;
}
// memory-squeezing-hack: OsmLinkP's "previous" also used as firstlink..
public void addLink( OsmLinkP link )
{
link.setNext( firstlink, this );
firstlink = link;
link.setNext( previous, this );
previous = link;
}
public OsmLinkP getFirstLink()
{
return sourceNode == null && targetNode == null ? previous : this;
}
public byte[] getNodeDecsription()
@ -96,7 +115,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
// hack: write node-desc as link tag (copy cycleway-bits)
byte[] nodeDescription = getNodeDecsription();
for( OsmLinkP link0 = firstlink; link0 != null; link0 = link0.getNext( this ) )
for( OsmLinkP link0 = getFirstLink(); link0 != null; link0 = link0.getNext( this ) )
{
int ilonref = ilon;
int ilatref = ilat;
@ -114,7 +133,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
break;
}
// next link is the one (of two), does does'nt point back
for( link = target.firstlink; link != null; link = link.getNext( target ) )
for( link = target.getFirstLink(); link != null; link = link.getNext( target ) )
{
if ( link.getTarget( target ) != origin ) break;
}
@ -130,7 +149,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
byte[] lastDescription = null;
while( link != null )
{
if ( link.descriptionBitmap == null && skipDetailBit == 0 ) throw new IllegalArgumentException( "missing way description...");
if ( link.descriptionBitmap == null && skipDetailBit == 0 ) throw new IllegalArgumentException( "missing way description...");
OsmNodeP target = link.getTarget( origin );
int tranferbit = target.isTransferNode() ? TRANSFERNODE_BITMASK : 0;
@ -139,9 +158,9 @@ public class OsmNodeP implements Comparable<OsmNodeP>
int writedescbit = 0;
if ( skipDetailBit == 0 ) // check if description changed
{
int inverseBitByteIndex = writeVarLength ? 0 : 7;
boolean inverseDirection = link.isReverse( origin );
byte[] ab = link.descriptionBitmap;
int inverseBitByteIndex = writeVarLength ? 0 : 7;
boolean inverseDirection = link.isReverse( origin );
byte[] ab = link.descriptionBitmap;
int abLen = ab.length;
int lastLen = lastDescription == null ? 0 : lastDescription.length;
boolean equalsCurrent = abLen == lastLen;
@ -151,16 +170,16 @@ public class OsmNodeP implements Comparable<OsmNodeP>
{
byte b = ab[i];
if ( i == inverseBitByteIndex && inverseDirection ) b ^= 1;
if ( b != lastDescription[i] ) { equalsCurrent = false; break; }
if ( b != lastDescription[i] ) { equalsCurrent = false; break; }
}
}
if ( !equalsCurrent )
{
writedescbit = WRITEDESC_BITMASK;
lastDescription = new byte[abLen];
System.arraycopy( ab, 0, lastDescription, 0 , abLen );
if ( inverseDirection ) lastDescription[inverseBitByteIndex] ^= 1;
}
if ( !equalsCurrent )
{
writedescbit = WRITEDESC_BITMASK;
lastDescription = new byte[abLen];
System.arraycopy( ab, 0, lastDescription, 0 , abLen );
if ( inverseDirection ) lastDescription[inverseBitByteIndex] ^= 1;
}
}
@ -197,7 +216,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
}
os2.writeVarLengthSigned( target.getSElev() -getSElev() );
// next link is the one (of two), does does'nt point back
for( link = target.firstlink; link != null; link = link.getNext( target ) )
for( link = target.getFirstLink(); link != null; link = link.getNext( target ) )
{
if ( link.getTarget( target ) != origin ) break;
}
@ -237,7 +256,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
{
int cnt = 0;
for( OsmLinkP link = firstlink; link != null; link = link.getNext( this ) )
for( OsmLinkP link = getFirstLink(); link != null; link = link.getNext( this ) )
{
cnt++;
}

View file

@ -181,10 +181,8 @@ public class WayLinker extends MapCreatorBase
n2 = nodesMap.get( nid );
if ( n1 != null && n2 != null && n1 != n2 )
{
OsmLinkP link = new OsmLinkP( n1, n2 );
OsmLinkP link = n2.createLink( n1 );
link.descriptionBitmap = description;
n1.addLink( link );
n2.addLink( link );
}
if ( n2 != null )
{
@ -214,7 +212,7 @@ public class WayLinker extends MapCreatorBase
LazyArrayOfLists<OsmNodeP> seglists = new LazyArrayOfLists<OsmNodeP>(nLonSegs*nLatSegs);
for( OsmNodeP n : nodesList )
{
if ( n == null || n.firstlink == null || n.isTransferNode() ) continue;
if ( n == null || n.getFirstLink() == null || n.isTransferNode() ) continue;
if ( n.ilon < minLon || n.ilon >= maxLon
|| n.ilat < minLat || n.ilat >= maxLat ) continue;
int lonIdx = (n.ilon-minLon)/1000000;