org.hd.d.pg2k.svrCore
Class Compact7BitString.StaticDictionary

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.Compact7BitString.StaticDictionary
Enclosing class:
Compact7BitString

public static final class Compact7BitString.StaticDictionary
extends java.lang.Object

Immutable static dictionary to improve in-memory compression. It is not permitted to serialise as-is a Compact7BitString that is using one of these so as to prevent decompression errors/ambiguities.


Field Summary
private  java.util.concurrent.ConcurrentMap<java.lang.String,Tuple.Pair<java.util.concurrent.atomic.AtomicInteger,java.util.concurrent.atomic.AtomicInteger>> _uncompEarlyTokens
          Thread-safe map from text of uncompressed token (close to start of input) to count and summed-position of the token; non-null iff LOG_STATS is true.
private static int FIRST_VIRTUAL_OFFSET
          First (numerically most positive) "virtual" offset used by the static dictionary; strictly negative.
static int MAX_TOKENS
          The maximum number of simple tokens for the static dictionary; strictly positive.
 java.lang.String name
          The name of this dictionary, never null.
 java.util.List<java.lang.String> tokens
          The immutable (non-empty) list of unique, best-first tokens; never null nor empty.
private  java.util.HashMap<java.lang.String,java.lang.Integer> virtualOffsets
          Virtual offsets of tokens in static dictionary; never null nor empty.
 
Constructor Summary
Compact7BitString.StaticDictionary(java.lang.String name, java.util.List<java.lang.String> tokens)
          Create an instance of a static dictionary.
 
Method Summary
 void dumpStats(java.io.PrintStream out)
          Dump stats (if any) to the given (non-null) stream.
 boolean equals(java.lang.Object obj)
          Only equal if all non-stats fields are.
 int hashCode()
          We don't expect to have to distinguish other than on name in practice, but we use the table size too.
 boolean isStatsEnabled()
          Returns true if stats-collecting is enabled.
 void resetStats()
          Resets the stats (if any) being recorded for this dictionary.
 java.lang.String toString()
          Human-readable summary: including the dictionary name; never null.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_TOKENS

public static final int MAX_TOKENS
The maximum number of simple tokens for the static dictionary; strictly positive.

See Also:
Constant Field Values

FIRST_VIRTUAL_OFFSET

private static final int FIRST_VIRTUAL_OFFSET
First (numerically most positive) "virtual" offset used by the static dictionary; strictly negative. We start at -2 to avoid conflict with -1 used to escape/start an MTM sequence.

See Also:
Constant Field Values

name

public final java.lang.String name
The name of this dictionary, never null.


tokens

public final java.util.List<java.lang.String> tokens
The immutable (non-empty) list of unique, best-first tokens; never null nor empty.


virtualOffsets

private final java.util.HashMap<java.lang.String,java.lang.Integer> virtualOffsets
Virtual offsets of tokens in static dictionary; never null nor empty. Logically immutable.

Kept private because it is faster to keep it unwrapped and mutable.


_uncompEarlyTokens

private final java.util.concurrent.ConcurrentMap<java.lang.String,Tuple.Pair<java.util.concurrent.atomic.AtomicInteger,java.util.concurrent.atomic.AtomicInteger>> _uncompEarlyTokens
Thread-safe map from text of uncompressed token (close to start of input) to count and summed-position of the token; non-null iff LOG_STATS is true. Updated when attempting to compress String data.

This map is for early tokens of length 2 or more characters, ie that we might be able to compress better using a static dictionary.

This is kept for statistical purposes.

Only the first occurrence of each token in each compress/input is counted.

Constructor Detail

Compact7BitString.StaticDictionary

public Compact7BitString.StaticDictionary(java.lang.String name,
                                          java.util.List<java.lang.String> tokens)
Create an instance of a static dictionary.

Parameters:
name - dictionary name; must not be null
tokens - unique tokens, non-null, best first, each of length > 1, non-empty, no longer than MAX_TOKENS
Method Detail

toString

public java.lang.String toString()
Human-readable summary: including the dictionary name; never null.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Only equal if all non-stats fields are.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
We don't expect to have to distinguish other than on name in practice, but we use the table size too.

Overrides:
hashCode in class java.lang.Object

isStatsEnabled

public boolean isStatsEnabled()
Returns true if stats-collecting is enabled.


resetStats

public void resetStats()
Resets the stats (if any) being recorded for this dictionary.


dumpStats

public void dumpStats(java.io.PrintStream out)
Dump stats (if any) to the given (non-null) stream. This dumps the stats of compressions against this dictionary instance.

Parameters:
out - never null

DHD Multimedia Gallery V1.60.69

Copyright (c) 1996-2012, Damon Hart-Davis. All rights reserved.