From 8c15a1d16f84bd5bb0b98d0a3db31995d6ad394e Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Tue, 10 Sep 2019 00:18:03 +0200 Subject: [PATCH] proof of concept delta-rd5 --- .../main/java/btools/codec/MicroCache2.java | 1 + .../java/btools/mapaccess/Rd5DiffTool.java | 42 ++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/brouter-codec/src/main/java/btools/codec/MicroCache2.java b/brouter-codec/src/main/java/btools/codec/MicroCache2.java index 5c2bc83..8cd8f30 100644 --- a/brouter-codec/src/main/java/btools/codec/MicroCache2.java +++ b/brouter-codec/src/main/java/btools/codec/MicroCache2.java @@ -91,6 +91,7 @@ public final class MicroCache2 extends MicroCache if ( featureId == 13 ) { fapos[n] = aboffset; + validBits[ n >> 5 ] |= 1 << n; // mark dummy-node valid continue; // empty node escape (delta files only) } while( featureId != 0 ) diff --git a/brouter-mapaccess/src/main/java/btools/mapaccess/Rd5DiffTool.java b/brouter-mapaccess/src/main/java/btools/mapaccess/Rd5DiffTool.java index 937fd51..f6d5bee 100644 --- a/brouter-mapaccess/src/main/java/btools/mapaccess/Rd5DiffTool.java +++ b/brouter-mapaccess/src/main/java/btools/mapaccess/Rd5DiffTool.java @@ -30,8 +30,10 @@ final public class Rd5DiffTool int nodesTotal = 0; int nodesDiff = 0; + int diffedTiles = 0; long bytesDiff = 0L; + long diffedTileSize = 0L; PhysicalFile pf1 = null; PhysicalFile pf2 = null; @@ -67,11 +69,6 @@ final public class Rd5DiffTool nodesTotal += mc2.getSize(); - if ( latIdx == 15 ) - { - // System.out.println( "hier!" ); - } - if ( mc.getSize() > 0 ) { int len = mc.encodeMicroCache( abBuf1 ); @@ -80,20 +77,37 @@ final public class Rd5DiffTool bytesDiff += len; nodesDiff += mc.getSize(); + diffedTiles++; + diffedTileSize += mc2.size(); - // cross-check the encoding: re-instantiate the cache + // cross-check the encoding: decode again MicroCache mcCheck = new MicroCache2( new StatCoderContext( bytes ), new DataBuffers( null ), lonIdxDiv, latIdxDiv, div, null, null ); - - // ..and check if still the same + + // due to link-order ambiguity, for decoded we can only compare node-count and datasize if ( mc.size() != mcCheck.size() ) { - // mc.compareWith finds link-ordering differences, - // so we compare only if there's also a size missmatch... + throw new IllegalArgumentException( "re-decoded data-size mismatch!" ); + } + if ( mc.getSize() != mcCheck.getSize() ) + { + throw new IllegalArgumentException( "re-decoded node-count mismatch!" ); + } - String diffMessage = mc.compareWith( mcCheck ); - if ( diffMessage != null ) + // .... so re-encode again + int len2 = mcCheck.encodeMicroCache( abBuf1 ); + byte[] bytes2 = new byte[len2]; + System.arraycopy( abBuf1, 0, bytes2, 0, len2 ); + + // and here we can compare byte-by-byte + if ( len != len2 ) + { + throw new IllegalArgumentException( "decoded size mismatch!" ); + } + for( int i=0; i