44
44
* </li>
45
45
* </ul>
46
46
*
47
- * Notice that encoding and decoding are written in a nested way, for instance {@link ES87TSDBDocValuesEncoder #deltaEncode} calling
48
- * {@link ES87TSDBDocValuesEncoder #removeOffset} and so on. This allows us to easily introduce new encoding schemes or remove existing
47
+ * Notice that encoding and decoding are written in a nested way, for instance {@link TSDBDocValuesEncoder #deltaEncode} calling
48
+ * {@link TSDBDocValuesEncoder #removeOffset} and so on. This allows us to easily introduce new encoding schemes or remove existing
49
49
* (non-effective) encoding schemes in a backward-compatible way.
50
50
*
51
51
* A token is used as a bitmask to represent which encoding is applied and allows us to detect the applied encoding scheme at decoding time.
54
54
*
55
55
* Of course, decoding follows the opposite order with respect to encoding.
56
56
*/
57
- public class ES87TSDBDocValuesEncoder {
57
+ public class TSDBDocValuesEncoder {
58
58
private final DocValuesForUtil forUtil ;
59
+ private final int numericBlockSize ;
59
60
60
- public ES87TSDBDocValuesEncoder () {
61
- this .forUtil = new DocValuesForUtil ();
61
+ public TSDBDocValuesEncoder (int numericBlockSize ) {
62
+ this .forUtil = new DocValuesForUtil (numericBlockSize );
63
+ this .numericBlockSize = numericBlockSize ;
62
64
}
63
65
64
66
/**
@@ -68,7 +70,7 @@ public ES87TSDBDocValuesEncoder() {
68
70
private void deltaEncode (int token , int tokenBits , long [] in , DataOutput out ) throws IOException {
69
71
int gts = 0 ;
70
72
int lts = 0 ;
71
- for (int i = 1 ; i < ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ; ++i ) {
73
+ for (int i = 1 ; i < numericBlockSize ; ++i ) {
72
74
if (in [i ] > in [i - 1 ]) {
73
75
gts ++;
74
76
} else if (in [i ] < in [i - 1 ]) {
@@ -79,7 +81,7 @@ private void deltaEncode(int token, int tokenBits, long[] in, DataOutput out) th
79
81
final boolean doDeltaCompression = (gts == 0 && lts >= 2 ) || (lts == 0 && gts >= 2 );
80
82
long first = 0 ;
81
83
if (doDeltaCompression ) {
82
- for (int i = ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE - 1 ; i > 0 ; --i ) {
84
+ for (int i = numericBlockSize - 1 ; i > 0 ; --i ) {
83
85
in [i ] -= in [i - 1 ];
84
86
}
85
87
// Avoid setting in[0] to 0 in case there is a minimum interval between
@@ -115,7 +117,7 @@ private void removeOffset(int token, int tokenBits, long[] in, DataOutput out) t
115
117
}
116
118
117
119
if (min != 0 ) {
118
- for (int i = 0 ; i < ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ; ++i ) {
120
+ for (int i = 0 ; i < numericBlockSize ; ++i ) {
119
121
in [i ] -= min ;
120
122
}
121
123
token = (token << 1 ) | 0x01 ;
@@ -143,7 +145,7 @@ private void gcdEncode(int token, int tokenBits, long[] in, DataOutput out) thro
143
145
}
144
146
final boolean doGcdCompression = Long .compareUnsigned (gcd , 1 ) > 0 ;
145
147
if (doGcdCompression ) {
146
- for (int i = 0 ; i < ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ; ++i ) {
148
+ for (int i = 0 ; i < numericBlockSize ; ++i ) {
147
149
in [i ] /= gcd ;
148
150
}
149
151
token = (token << 1 ) | 0x01 ;
@@ -174,7 +176,7 @@ private void forEncode(int token, int tokenBits, long[] in, DataOutput out) thro
174
176
* Encode the given longs using a combination of delta-coding, GCD factorization and bit packing.
175
177
*/
176
178
void encode (long [] in , DataOutput out ) throws IOException {
177
- assert in .length == ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ;
179
+ assert in .length == numericBlockSize ;
178
180
179
181
deltaEncode (0 , 0 , in , out );
180
182
}
@@ -192,7 +194,7 @@ void encode(long[] in, DataOutput out) throws IOException {
192
194
* </ul>
193
195
*/
194
196
void encodeOrdinals (long [] in , DataOutput out , int bitsPerOrd ) throws IOException {
195
- assert in .length == ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ;
197
+ assert in .length == numericBlockSize ;
196
198
int numRuns = 1 ;
197
199
long firstValue = in [0 ];
198
200
long previousValue = firstValue ;
@@ -259,7 +261,7 @@ void encodeOrdinals(long[] in, DataOutput out, int bitsPerOrd) throws IOExceptio
259
261
}
260
262
261
263
void decodeOrdinals (DataInput in , long [] out , int bitsPerOrd ) throws IOException {
262
- assert out .length == ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE : out .length ;
264
+ assert out .length == numericBlockSize : out .length ;
263
265
264
266
long v1 = in .readVLong ();
265
267
int encoding = Long .numberOfTrailingZeros (~v1 );
@@ -293,7 +295,7 @@ void decodeOrdinals(DataInput in, long[] out, int bitsPerOrd) throws IOException
293
295
294
296
/** Decode longs that have been encoded with {@link #encode}. */
295
297
void decode (DataInput in , long [] out ) throws IOException {
296
- assert out .length == ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE : out .length ;
298
+ assert out .length == numericBlockSize : out .length ;
297
299
298
300
final int token = in .readVInt ();
299
301
final int bitsPerValue = token >>> 3 ;
@@ -330,21 +332,21 @@ void decode(DataInput in, long[] out) throws IOException {
330
332
}
331
333
332
334
// this loop should auto-vectorize
333
- private static void mul (long [] arr , long m ) {
334
- for (int i = 0 ; i < ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ; ++i ) {
335
+ private void mul (long [] arr , long m ) {
336
+ for (int i = 0 ; i < numericBlockSize ; ++i ) {
335
337
arr [i ] *= m ;
336
338
}
337
339
}
338
340
339
341
// this loop should auto-vectorize
340
- private static void add (long [] arr , long min ) {
341
- for (int i = 0 ; i < ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ; ++i ) {
342
+ private void add (long [] arr , long min ) {
343
+ for (int i = 0 ; i < numericBlockSize ; ++i ) {
342
344
arr [i ] += min ;
343
345
}
344
346
}
345
347
346
- private static void deltaDecode (long [] arr ) {
347
- for (int i = 1 ; i < ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ; ++i ) {
348
+ private void deltaDecode (long [] arr ) {
349
+ for (int i = 1 ; i < numericBlockSize ; ++i ) {
348
350
arr [i ] += arr [i - 1 ];
349
351
}
350
352
}
0 commit comments