4444 * </li>
4545 * </ul>
4646 *
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
4949 * (non-effective) encoding schemes in a backward-compatible way.
5050 *
5151 * 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.
5454 *
5555 * Of course, decoding follows the opposite order with respect to encoding.
5656 */
57- public class ES87TSDBDocValuesEncoder {
57+ public class TSDBDocValuesEncoder {
5858 private final DocValuesForUtil forUtil ;
59+ private final int numericBlockSize ;
5960
60- public ES87TSDBDocValuesEncoder () {
61- this .forUtil = new DocValuesForUtil ();
61+ public TSDBDocValuesEncoder (int numericBlockSize ) {
62+ this .forUtil = new DocValuesForUtil (numericBlockSize );
63+ this .numericBlockSize = numericBlockSize ;
6264 }
6365
6466 /**
@@ -68,7 +70,7 @@ public ES87TSDBDocValuesEncoder() {
6870 private void deltaEncode (int token , int tokenBits , long [] in , DataOutput out ) throws IOException {
6971 int gts = 0 ;
7072 int lts = 0 ;
71- for (int i = 1 ; i < ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ; ++i ) {
73+ for (int i = 1 ; i < numericBlockSize ; ++i ) {
7274 if (in [i ] > in [i - 1 ]) {
7375 gts ++;
7476 } else if (in [i ] < in [i - 1 ]) {
@@ -79,7 +81,7 @@ private void deltaEncode(int token, int tokenBits, long[] in, DataOutput out) th
7981 final boolean doDeltaCompression = (gts == 0 && lts >= 2 ) || (lts == 0 && gts >= 2 );
8082 long first = 0 ;
8183 if (doDeltaCompression ) {
82- for (int i = ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE - 1 ; i > 0 ; --i ) {
84+ for (int i = numericBlockSize - 1 ; i > 0 ; --i ) {
8385 in [i ] -= in [i - 1 ];
8486 }
8587 // 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
115117 }
116118
117119 if (min != 0 ) {
118- for (int i = 0 ; i < ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ; ++i ) {
120+ for (int i = 0 ; i < numericBlockSize ; ++i ) {
119121 in [i ] -= min ;
120122 }
121123 token = (token << 1 ) | 0x01 ;
@@ -143,7 +145,7 @@ private void gcdEncode(int token, int tokenBits, long[] in, DataOutput out) thro
143145 }
144146 final boolean doGcdCompression = Long .compareUnsigned (gcd , 1 ) > 0 ;
145147 if (doGcdCompression ) {
146- for (int i = 0 ; i < ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ; ++i ) {
148+ for (int i = 0 ; i < numericBlockSize ; ++i ) {
147149 in [i ] /= gcd ;
148150 }
149151 token = (token << 1 ) | 0x01 ;
@@ -174,7 +176,7 @@ private void forEncode(int token, int tokenBits, long[] in, DataOutput out) thro
174176 * Encode the given longs using a combination of delta-coding, GCD factorization and bit packing.
175177 */
176178 void encode (long [] in , DataOutput out ) throws IOException {
177- assert in .length == ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ;
179+ assert in .length == numericBlockSize ;
178180
179181 deltaEncode (0 , 0 , in , out );
180182 }
@@ -192,7 +194,7 @@ void encode(long[] in, DataOutput out) throws IOException {
192194 * </ul>
193195 */
194196 void encodeOrdinals (long [] in , DataOutput out , int bitsPerOrd ) throws IOException {
195- assert in .length == ES87TSDBDocValuesFormat . NUMERIC_BLOCK_SIZE ;
197+ assert in .length == numericBlockSize ;
196198 int numRuns = 1 ;
197199 long firstValue = in [0 ];
198200 long previousValue = firstValue ;
@@ -259,7 +261,7 @@ void encodeOrdinals(long[] in, DataOutput out, int bitsPerOrd) throws IOExceptio
259261 }
260262
261263 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 ;
263265
264266 long v1 = in .readVLong ();
265267 int encoding = Long .numberOfTrailingZeros (~v1 );
@@ -275,7 +277,7 @@ void decodeOrdinals(DataInput in, long[] out, int bitsPerOrd) throws IOException
275277 Arrays .fill (out , runLen , out .length , v2 );
276278 } else if (encoding == 2 ) {
277279 // bit-packed
278- DocValuesForUtil .decode (bitsPerOrd , in , out );
280+ forUtil .decode (bitsPerOrd , in , out );
279281 } else if (encoding == 3 ) {
280282 // cycle encoding
281283 int cycleLength = (int ) v1 ;
@@ -293,13 +295,13 @@ void decodeOrdinals(DataInput in, long[] out, int bitsPerOrd) throws IOException
293295
294296 /** Decode longs that have been encoded with {@link #encode}. */
295297 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 ;
297299
298300 final int token = in .readVInt ();
299301 final int bitsPerValue = token >>> 3 ;
300302
301303 if (bitsPerValue != 0 ) {
302- DocValuesForUtil .decode (bitsPerValue , in , out );
304+ forUtil .decode (bitsPerValue , in , out );
303305 } else {
304306 Arrays .fill (out , 0L );
305307 }
@@ -330,21 +332,21 @@ void decode(DataInput in, long[] out) throws IOException {
330332 }
331333
332334 // 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 ) {
335337 arr [i ] *= m ;
336338 }
337339 }
338340
339341 // 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 ) {
342344 arr [i ] += min ;
343345 }
344346 }
345347
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 ) {
348350 arr [i ] += arr [i - 1 ];
349351 }
350352 }
0 commit comments