fixed java-8 glitch in preprocessing (thanx Markus)
This commit is contained in:
parent
99147635cd
commit
ccf2eb28d3
1 changed files with 18 additions and 12 deletions
|
@ -1,5 +1,6 @@
|
||||||
package btools.codec;
|
package btools.codec;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.PriorityQueue;
|
import java.util.PriorityQueue;
|
||||||
|
|
||||||
|
@ -7,10 +8,10 @@ import btools.util.BitCoderContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encoder/Decoder for way-/node-descriptions
|
* Encoder/Decoder for way-/node-descriptions
|
||||||
*
|
*
|
||||||
* It detects identical descriptions and sorts them
|
* It detects identical descriptions and sorts them
|
||||||
* into a huffman-tree according to their frequencies
|
* into a huffman-tree according to their frequencies
|
||||||
*
|
*
|
||||||
* Adapted for 3-pass encoding (counters -> statistics -> encoding )
|
* Adapted for 3-pass encoding (counters -> statistics -> encoding )
|
||||||
* but doesn't do anything at pass1
|
* but doesn't do anything at pass1
|
||||||
*/
|
*/
|
||||||
|
@ -61,7 +62,8 @@ public final class TagValueCoder
|
||||||
{
|
{
|
||||||
if ( ++pass == 3 )
|
if ( ++pass == 3 )
|
||||||
{
|
{
|
||||||
PriorityQueue<TagValueSet> queue = new PriorityQueue<TagValueSet>( identityMap.values() );
|
PriorityQueue<TagValueSet> queue = new PriorityQueue<TagValueSet>(2*identityMap.size(), new TagValueSet.FrequencyComparator());
|
||||||
|
queue.addAll(identityMap.values());
|
||||||
while (queue.size() > 1)
|
while (queue.size() > 1)
|
||||||
{
|
{
|
||||||
TagValueSet node = new TagValueSet();
|
TagValueSet node = new TagValueSet();
|
||||||
|
@ -131,7 +133,7 @@ public final class TagValueCoder
|
||||||
public Object child2;
|
public Object child2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class TagValueSet implements Comparable<TagValueSet>
|
public static final class TagValueSet
|
||||||
{
|
{
|
||||||
public byte[] data;
|
public byte[] data;
|
||||||
public int frequency;
|
public int frequency;
|
||||||
|
@ -222,14 +224,18 @@ public final class TagValueCoder
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static class FrequencyComparator implements Comparator<TagValueSet>
|
||||||
public int compareTo( TagValueSet tvs )
|
|
||||||
{
|
{
|
||||||
if ( frequency < tvs.frequency )
|
|
||||||
return -1;
|
@Override
|
||||||
if ( frequency > tvs.frequency )
|
public int compare(TagValueSet tvs1, TagValueSet tvs2) {
|
||||||
return 1;
|
if ( tvs1.frequency < tvs2.frequency )
|
||||||
return 0;
|
return -1;
|
||||||
|
if ( tvs1.frequency > tvs2.frequency )
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue