// Compressing floats is simple, because the only common pattern // is trailing zeroes. (Compare leading sign bits on ints.) // Since floats are left-justified, as opposed to right-justified // ints, we can bit-reverse them in order to take advantage of int // compression. Since bit reversal converts trailing zeroes to // leading zeroes, effect is better compression of those common // 32-bit float values, such as integers or integers divided by // powers of two, that have many trailing zeroes.
jfloat CompressedReadStream::read_float() { int rf = read_int(); int f = reverse_bits(rf); return jfloat_cast(f);
}
// The treatment of doubles is similar. We could bit-reverse each // entire 64-bit word, but it is almost as effective to bit-reverse // the individual halves. Since we are going to encode them // separately as 32-bit halves anyway, it seems slightly simpler // to reverse after splitting, and when reading reverse each // half before joining them together.
jdouble CompressedReadStream::read_double() {
jint rh = read_int();
jint rl = read_int();
jint h = reverse_bits(rh);
jint l = reverse_bits(rl); return jdouble_cast(jlong_from(h, l));
}
// A 64-bit long is encoded into distinct 32-bit halves. This saves // us from having to define a 64-bit encoding and is almost as // effective. A modified LEB128 could encode longs into 9 bytes, and // this technique maxes out at 10 bytes, so, if we didn't mind the // extra complexity of another coding system, we could process 64-bit // values as single units. But, the complexity does not seem // worthwhile.
jlong CompressedReadStream::read_long() {
jint low = read_signed_int();
jint high = read_signed_int(); return jlong_from(high, low);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.