public final class BHSDCodec extends Codec
Codec.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.)
Codec.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 (Codec.BYTE1
, Codec.UNSIGNED5
) gives a clue as to the B value. Those that start with U
(Codec.UDELTA5
, Codec.UNSIGNED5
) are unsigned; otherwise, in most cases, they are signed. The presence of the
word Delta (Codec.DELTA5
, Codec.UDELTA5
) indicates a delta encoding is used.Constructor and Description |
---|
BHSDCodec(int b,
int h)
Constructs an unsigned, non-delta Codec with the given B and H values.
|
BHSDCodec(int b,
int h,
int s)
Constructs a non-delta Codec with the given B, H and S values.
|
BHSDCodec(int b,
int h,
int s,
int d)
Constructs a Codec with the given B, H, S and D values.
|
Modifier and Type | Method and Description |
---|---|
long |
cardinality()
Returns the cardinality of this codec; that is, the number of distinct values that it can contain.
|
int |
decode(InputStream in)
Decode a sequence of bytes from the given input stream, returning the value as a long.
|
int |
decode(InputStream in,
long last)
Decode a sequence of bytes from the given input stream, returning the value as a long.
|
int[] |
decodeInts(int n,
InputStream in)
Decodes a sequence of
n values from in . |
int[] |
decodeInts(int n,
InputStream in,
int firstValue)
Decodes a sequence of
n values from in . |
byte[] |
encode(int value)
Encode a single value into a sequence of bytes.
|
byte[] |
encode(int value,
int last)
Encode a single value into a sequence of bytes.
|
boolean |
encodes(long value)
True if this encoding can code the given value
|
boolean |
equals(Object o) |
int |
getB() |
int |
getH() |
int |
getL() |
int |
getS() |
int |
hashCode() |
boolean |
isDelta()
Returns true if this codec is a delta codec
|
boolean |
isSigned()
Returns true if this codec is a signed codec
|
long |
largest()
Returns the largest value that this codec can represent.
|
long |
smallest()
Returns the smallest value that this codec can represent.
|
String |
toString()
Returns the codec in the form (1,256) or (1,64,1,1).
|
public BHSDCodec(int b, int h)
b
- the maximum number of bytes that a value can be encoded as [1..5]h
- the radix of the encoding [1..256]public BHSDCodec(int b, int h, int s)
b
- the maximum number of bytes that a value can be encoded as [1..5]h
- the radix of the encoding [1..256]s
- whether the encoding represents signed numbers (s=0 is unsigned; s=1 is signed with 1s complement; s=2
is signed with ?)public BHSDCodec(int b, int h, int s, int d)
b
- the maximum number of bytes that a value can be encoded as [1..5]h
- the radix of the encoding [1..256]s
- whether the encoding represents signed numbers (s=0 is unsigned; s=1 is signed with 1s complement; s=2
is signed with ?)d
- whether this is a delta encoding (d=0 is non-delta; d=1 is delta)public long cardinality()
public int decode(InputStream in) throws IOException, Pack200Exception
Codec
decode
in class Codec
in
- the input stream to read fromIOException
- if there is a problem reading from the underlying input streamPack200Exception
- if the encoding is a delta encodingpublic int decode(InputStream in, long last) throws IOException, Pack200Exception
Codec
long last = 0; while (condition) { last = codec.decode(in, last); // do something with last }
decode
in class Codec
in
- the input stream to read fromlast
- the previous value read, which must be supplied if the codec is a delta encodingIOException
- if there is a problem reading from the underlying input streamPack200Exception
- if there is a problem decoding the value or that the value is invalidpublic int[] decodeInts(int n, InputStream in) throws IOException, Pack200Exception
Codec
n
values from in
. This should probably be used in most cases,
since some codecs (such as PopulationCodec
) only work when the number of values to be read is known.decodeInts
in class Codec
n
- the number of values to decodein
- the input stream to read fromint
values corresponding to values decodedIOException
- if there is a problem reading from the underlying input streamPack200Exception
- if there is a problem decoding the value or that the value is invalidpublic int[] decodeInts(int n, InputStream in, int firstValue) throws IOException, Pack200Exception
Codec
n
values from in
.decodeInts
in class Codec
n
- the number of values to decodein
- the input stream to read fromfirstValue
- the first value in the band if it has already been readint
values corresponding to values decoded, with firstValue as the first value
in the array.IOException
- if there is a problem reading from the underlying input streamPack200Exception
- if there is a problem decoding the value or that the value is invalidpublic boolean encodes(long value)
value
- the value to checktrue
if the encoding can encode this valuepublic byte[] encode(int value, int last) throws Pack200Exception
Codec
encode
in class Codec
value
- the value to encodelast
- the previous value encoded (for delta encodings)Pack200Exception
- TODOpublic byte[] encode(int value) throws Pack200Exception
Codec
encode
in class Codec
value
- the value to encodePack200Exception
- TODOpublic boolean isDelta()
public boolean isSigned()
public long largest()
public long smallest()
public String toString()
public int getB()
public int getH()
public int getS()
public int getL()
Copyright © 2002–2022 The Apache Software Foundation. All rights reserved.