A BHSD codec is configured with four parameters:
BYTE1, B is 1 (each byte takes a maximum of 1 byte).n is multiplied by H^<sup>n</sup>. So the number 1234
may be represented as the sequence 4 3 2 1 with a radix (H) of 10. Note that other permutations are also possible; 43 2 1 will also encode 1234. The
co-parameter L is defined as 256-H. This is important because only the last value in a sequence may be < L; all prior values must be > L.1 1 1 1 1 will represent the sequence 1 2 3 4 5. For this reason, the codec supports two variants of decode; one
with and one without a last parameter. If the codec is a non-delta encoding, then the
value is ignored if passed. If the codec is a delta encoding, it is a run-time error to call the value without the extra parameter, and the previous value
should be returned. (It was designed this way to support multi-threaded access without requiring a new instance of the Codec to be cloned for each use.)
Codecs are notated as (B,H,S,D) and either D or S,D may be omitted if zero. Thus BYTE1 is denoted (1,256,0,0) or (1,256). The toString()
method prints out the condensed form of the encoding. Often, the last character in the name (BYTE1, UNSIGNED5) gives a clue as to the B
value. Those that start with U (UDELTA5, UNSIGNED5) are unsigned; otherwise, in most cases, they are signed. The presence of the word Delta
(DELTA5, UDELTA5) indicates a delta encoding is used.
| Modifier and Type | Field and Description |
|---|---|
| private final int | b
The maximum number of bytes in each coding word. |
| private long | |
| private final int | d
Whether delta encoding is used (0=false,1=true). |
| private final int | h
The radix of the encoding. |
| private final int | l
The co-parameter of h; 256-h. |
| private final long | |
| private final long[] | powers
radix^i powers |
| private final int | s
Represents signed numbers or not, 0 (unsigned), 1 (signed, one's complement) or 2 (signed, two's complement). |
| private final long |
| Access | Constructor and Description |
|---|---|
| public | BHSDCodec(final int
the maximum number of bytes that a value can be encoded as [1..5] b, final int the radix of the encoding [1..256] h)Constructs an unsigned, non-delta Codec with the given B and H values. |
| public | BHSDCodec(final int
the maximum number of bytes that a value can be encoded as [1..5] b, final int the radix of the encoding [1..256] h, final int whether the encoding represents signed numbers (s=0 is unsigned; s=1 is signed with 1s complement; s=2 is signed with ?) s)Constructs a non-delta Codec with the given B, H and S values. |
| public | BHSDCodec(final int
the maximum number of bytes that a value can be encoded as [1..5] b, final int the radix of the encoding [1..256] h, final int whether the encoding represents signed numbers (s=0 is unsigned; s=1 is signed with 1s complement; s=2 is signed with ?) s, final int whether this is a delta encoding (d=0 is non-delta; d=1 is delta) d)Constructs a Codec with the given B, H, S and D values. |
| Modifier and Type | Method and Description |
|---|---|
| private long | |
| private long | |
| public long | Returns: the cardinality of this codecReturns the cardinality of this codec; that is, the number of distinct values that it can contain. |
| public int | decode(final InputStream
the input stream to read from in)Implements abstract org. |
| public int | decode(final InputStream
the input stream to read from in, final long the previous value read, which must be supplied if the codec is a delta encoding last)Implements abstract org. |
| public int[] | decodeInts(final int
the number of values to decode n, final InputStream the input stream to read from in)Overrides org. n values from in.
|
| public int[] | decodeInts(final int
the number of values to decode n, final InputStream the input stream to read from in, final int the first value in the band if it has already been read firstValue)Overrides org. n values from in.
|
| public byte[] | encode(final int
the value to encode value)Implements abstract org. |
| public byte[] | encode(final int
the value to encode value, final int the previous value encoded (for delta encodings) last)Implements abstract org. |
| public boolean | Returns: true if the encoding can encode this valuethe value to check value)True if this encoding can code the given value |
| public boolean | equals(final Object
the reference object with which to compare. o)Overrides java. |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public boolean | |
| public boolean | |
| public long | Returns: the largest value that this codec can represent.Returns the largest value that this codec can represent. |
| public long | Returns: the smallest value that this codec can represent.Returns the smallest value that this codec can represent. |
| public String |
| b | back to summary |
|---|---|
| private final int b The maximum number of bytes in each coding word. B must be a value between [1..5]. For a pass-through coding (where each byte is encoded as itself, aka
| |
| cardinality | back to summary |
|---|---|
| private long cardinality | |
| d | back to summary |
|---|---|
| private final int d Whether delta encoding is used (0=false,1=true). | |
| h | back to summary |
|---|---|
| private final int h The radix of the encoding. | |
| l | back to summary |
|---|---|
| private final int l The co-parameter of h; 256-h. | |
| largest | back to summary |
|---|---|
| private final long largest | |
| powers | back to summary |
|---|---|
| private final long[] powers radix^i powers | |
| s | back to summary |
|---|---|
| private final int s Represents signed numbers or not, 0 (unsigned), 1 (signed, one's complement) or 2 (signed, two's complement). | |
| smallest | back to summary |
|---|---|
| private final long smallest | |
| BHSDCodec | back to summary |
|---|---|
| public BHSDCodec(final int b, final int h) Constructs an unsigned, non-delta Codec with the given B and H values.
| |
| BHSDCodec | back to summary |
|---|---|
| public BHSDCodec(final int b, final int h, final int s) Constructs a non-delta Codec with the given B, H and S values.
| |
| BHSDCodec | back to summary |
|---|---|
| public BHSDCodec(final int b, final int h, final int s, final int d) Constructs a Codec with the given B, H, S and D values.
| |
| calculateLargest | back to summary |
|---|---|
| private long calculateLargest() | |
| calculateSmallest | back to summary |
|---|---|
| private long calculateSmallest() | |
| cardinality | back to summary |
|---|---|
| public long cardinality() Returns the cardinality of this codec; that is, the number of distinct values that it can contain.
| |
| decode | back to summary |
|---|---|
| public int decode(final InputStream in) throws IOException, Pack200Exception Implements abstract org. Doc from org. Decodes a sequence of bytes from the given input stream, returning the value as a long. Note that this method can only be applied for non-delta encodings.
| |
| decode | back to summary |
|---|---|
| public int decode(final InputStream in, final long last) throws IOException, Pack200Exception Implements abstract org. Doc from org. Decodes a sequence of bytes from the given input stream, returning the value as a long. If this encoding is a delta encoding (d=1) then the previous value must be passed in as a parameter. If it is a non-delta encoding, then it does not matter what value is passed in, so it makes sense for the value to be passed in by default using code similar to:
long last = 0;
while (condition) {
last = codec.decode(in, last);
// do something with last
}
| |
| decodeInts | back to summary |
|---|---|
| public int[] decodeInts(final int n, final InputStream in) throws IOException, Pack200Exception Overrides org. Doc from org. Decodes a sequence of
| |
| decodeInts | back to summary |
|---|---|
| public int[] decodeInts(final int n, final InputStream in, final int firstValue) throws IOException, Pack200Exception Overrides org. Doc from org. Decodes a sequence of
| |
| encode | back to summary |
|---|---|
| public byte[] encode(final int value) throws Pack200Exception Implements abstract org. Doc from org. Encodes a single value into a sequence of bytes. Note that this method can only be used for non-delta encodings.
| |
| encode | back to summary |
|---|---|
| public byte[] encode(final int value, final int last) throws Pack200Exception Implements abstract org. Doc from org. Encodes a single value into a sequence of bytes.
| |
| encodes | back to summary |
|---|---|
| public boolean encodes(final long value) True if this encoding can code the given value
| |
| equals | back to summary |
|---|---|
| public boolean equals(final Object o) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| getB | back to summary |
|---|---|
| public int getB() Gets the B.
| |
| getH | back to summary |
|---|---|
| public int getH() Gets the H.
| |
| getL | back to summary |
|---|---|
| public int getL() Gets the L.
| |
| getS | back to summary |
|---|---|
| public int getS() Gets the S.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isDelta | back to summary |
|---|---|
| public boolean isDelta() Returns true if this codec is a delta codec
| |
| isSigned | back to summary |
|---|---|
| public boolean isSigned() Returns true if this codec is a signed codec
| |
| largest | back to summary |
|---|---|
| public long largest() Returns the largest value that this codec can represent.
| |
| smallest | back to summary |
|---|---|
| public long smallest() Returns the smallest value that this codec can represent.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns the codec in the form (1,256) or (1,64,1,1). Note that trailing zero fields are not shown.
| |