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

View file

@ -9,7 +9,7 @@ import java.io.IOException;
import btools.util.ByteDataWriter; 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 SIGNLON_BITMASK = 0x80;
public static final int SIGNLAT_BITMASK = 0x40; public static final int SIGNLAT_BITMASK = 0x40;
@ -29,12 +29,6 @@ public class OsmNodeP implements Comparable<OsmNodeP>
public int ilon; public int ilon;
/**
* The links to other nodes
*/
public OsmLinkP firstlink = null;
/** /**
* The elevation * 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 ) public void addLink( OsmLinkP link )
{ {
link.setNext( firstlink, this ); link.setNext( previous, this );
firstlink = link; previous = link;
}
public OsmLinkP getFirstLink()
{
return sourceNode == null && targetNode == null ? previous : this;
} }
public byte[] getNodeDecsription() public byte[] getNodeDecsription()
@ -96,7 +115,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
// hack: write node-desc as link tag (copy cycleway-bits) // hack: write node-desc as link tag (copy cycleway-bits)
byte[] nodeDescription = getNodeDecsription(); 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 ilonref = ilon;
int ilatref = ilat; int ilatref = ilat;
@ -114,7 +133,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
break; break;
} }
// next link is the one (of two), does does'nt point back // 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; if ( link.getTarget( target ) != origin ) break;
} }
@ -197,7 +216,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
} }
os2.writeVarLengthSigned( target.getSElev() -getSElev() ); os2.writeVarLengthSigned( target.getSElev() -getSElev() );
// next link is the one (of two), does does'nt point back // 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; if ( link.getTarget( target ) != origin ) break;
} }
@ -237,7 +256,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
{ {
int cnt = 0; int cnt = 0;
for( OsmLinkP link = firstlink; link != null; link = link.getNext( this ) ) for( OsmLinkP link = getFirstLink(); link != null; link = link.getNext( this ) )
{ {
cnt++; cnt++;
} }

View file

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