org.apache.lucene.util.packed

## Class MonotonicBlockPackedWriter

- java.lang.Object
- - org.apache.lucene.util.packed.MonotonicBlockPackedWriter

-     public final class MonotonicBlockPackedWriter
      extends Object

  A writer for large monotonically increasing sequences of positive longs.

  The sequence is divided into fixed-size blocks and for each block, values are modeled after a linear function f: x → A × x + B. The block encodes deltas from the expected values computed from this function using as few bits as possible.

  Format:

  - <BLock>BlockCount
  - BlockCount: ⌈ ValueCount / BlockSize ⌉
  - Block: <Header, (Ints)>
  - Header: <B, A, BitsPerValue>
  - B: the B from f: x → A × x + B using a `zig-zag encoded` `vLong`
  - A: the A from f: x → A × x + B encoded using `Float.floatToIntBits(float)` on `4 bytes`
  - BitsPerValue: a `variable-length int`
  - Ints: if BitsPerValue is `0`, then there is nothing to read and all values perfectly match the result of the function. Otherwise, these are the `packed` deltas from the expected value (computed from the function) using exactly BitsPerValue bits per value.
  See Also:
    `MonotonicBlockPackedReader`
  NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected byte[]` | `blocks`
    `protected boolean` | `finished`
    `protected int` | `off`
    `protected long` | `ord`
    `protected DataOutput` | `out`
    `protected long[]` | `values`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MonotonicBlockPackedWriter(DataOutput out, int blockSize)` Sole constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(long l)` Append a new long.
    `void` | `finish()` Flush all buffered data to disk.
    `protected void` | `flush()`
    `long` | `ord()` Return the number of values which have been added.
    `void` | `reset(DataOutput out)` Reset this writer to wrap `out`.
    `protected void` | `writeValues(int bitsRequired)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### out

          protected DataOutput out

    - #### values

          protected final long[] values

    - #### blocks

          protected byte[] blocks

    - #### off

          protected int off

    - #### ord

          protected long ord

    - #### finished

          protected boolean finished

  - ### Constructor Detail

    - #### MonotonicBlockPackedWriter

          public MonotonicBlockPackedWriter(DataOutput out,
                                            int blockSize)

      Sole constructor.
      Parameters:
        `blockSize` - the number of values of a single block, must be a power of 2

  - ### Method Detail

    - #### add

          public void add(long l)
                   throws IOException

      Append a new long.
      Throws:
        `IOException`

    - #### flush

          protected void flush()
                        throws IOException

      Throws:
        `IOException`

    - #### reset

          public void reset(DataOutput out)

      Reset this writer to wrap `out`. The block size remains unchanged.

    - #### finish

          public void finish()
                      throws IOException

      Flush all buffered data to disk. This instance is not usable anymore after this method has been called until `reset(DataOutput)` has been called.
      Throws:
        `IOException`

    - #### ord

          public long ord()

      Return the number of values which have been added.

    - #### writeValues

          protected final void writeValues(int bitsRequired)
                                    throws IOException

      Throws:
        `IOException`

Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.