# Package org.apache.lucene.util.packed

Packed integer arrays and streams.

See: Description

- Interface Summary
  Interface | Description
  --- | ---
  PackedInts.Decoder | A decoder for packed integers.
  PackedInts.Encoder | An encoder for packed integers.
  PackedInts.ReaderIterator | Run-once iterator interface, to decode previously saved PackedInts.

- Class Summary
  Class | Description
  --- | ---
  AbstractPagedMutable<T extends AbstractPagedMutable<T>> | Base implementation for `PagedMutable` and `PagedGrowableWriter`.
  BlockPackedReader | Provides random access to a stream written with `BlockPackedWriter`.
  BlockPackedReaderIterator | Reader for sequences of longs written with `BlockPackedWriter`.
  BlockPackedWriter | A writer for large sequences of longs.
  DirectMonotonicReader | Retrieves an instance previously written by `DirectMonotonicWriter`.
  DirectMonotonicReader.Meta | In-memory metadata that needs to be kept around for `DirectMonotonicReader` to read data from disk.
  DirectMonotonicWriter | Write monotonically-increasing sequences of integers.
  DirectReader | Retrieves an instance previously written by `DirectWriter`
  DirectWriter | Class for writing packed integers to be directly read from Directory.
  GrowableWriter | Implements `PackedInts.Mutable`, but grows the bit count of the underlying packed ints on-demand.
  MonotonicBlockPackedReader | Provides random access to a stream written with `MonotonicBlockPackedWriter`.
  MonotonicBlockPackedWriter | A writer for large monotonically increasing sequences of positive longs.
  PackedDataInput | A `DataInput` wrapper to read unaligned, variable-length packed integers.
  PackedDataOutput | A `DataOutput` wrapper to write unaligned, variable-length packed integers.
  PackedInts | Simplistic compression for array of unsigned long values.
  PackedInts.FormatAndBits | Simple class that holds a format and a number of bits per value.
  PackedInts.Mutable | A packed integer array that can be modified.
  PackedInts.NullReader | A `PackedInts.Reader` which has all its values equal to 0 (bitsPerValue = 0).
  PackedInts.Reader | A read-only random access array of positive integers.
  PackedInts.Writer | A write-once Writer.
  PackedLongValues | Utility class to compress integers into a `LongValues` instance.
  PackedLongValues.Builder | A Builder for a `PackedLongValues` instance.
  PagedGrowableWriter | A `PagedGrowableWriter`.
  PagedMutable | A `PagedMutable`.

- Enum Summary
  Enum | Description
  --- | ---
  PackedInts.Format | A format to write packed ints.

## Package org.apache.lucene.util.packed Description

Packed integer arrays and streams.

The packed package provides

- sequential and random access capable arrays of positive longs,
- routines for efficient serialization and deserialization of streams of packed integers.

The implementations provide different trade-offs between memory usage and access speed. The standard usage scenario is replacing large int or long arrays in order to reduce the memory footprint.

The main access point is the `PackedInts` factory.

### In-memory structures

- `PackedInts.Mutable`
  - Only supports positive longs.
  - Requires the number of bits per value to be known in advance.
  - Random-access for both writing and reading.
- `GrowableWriter`
  - Same as PackedInts.Mutable but grows the number of bits per values when needed.
  - Useful to build a PackedInts.Mutable from a read-once stream of longs.
- `PagedGrowableWriter`
  - Slices data into fixed-size blocks stored in GrowableWriters.
  - Supports more than 2B values.
  - You should use PackedLongValues instead if you don't need random write access.
- `PackedLongValues.deltaPackedBuilder(int, float)`
  - Can store any sequence of longs.
  - Compression is good when values are close to each other.
  - Supports random reads, but only sequential writes.
  - Can address up to 2^42 values.
- `PackedLongValues.packedBuilder(int, float)`
  - Same as deltaPackedBuilder but assumes values are 0-based.
- `PackedLongValues.monotonicBuilder(int, float)`
  - Same as deltaPackedBuilder except that compression is good when the stream is a succession of affine functions.

### Disk-based structures

- `PackedInts.Writer`, `PackedInts.Reader`, `PackedInts.ReaderIterator`
  - Only supports positive longs.
  - Requires the number of bits per value to be known in advance.
  - Supports both fast sequential access with low memory footprint with ReaderIterator and random-access by either loading values in memory or leaving them on disk with Reader.
- `BlockPackedWriter`, `BlockPackedReader`, `BlockPackedReaderIterator`
  - Splits the stream into fixed-size blocks.
  - Compression is good when values are close to each other.
  - Can address up to 2B * blockSize values.
- `MonotonicBlockPackedWriter`, `MonotonicBlockPackedReader`
  - Same as the non-monotonic variants except that compression is good when the stream is a succession of affine functions.
  - The reason why there is no sequential access is that if you need sequential access, you should rather delta-encode and use BlockPackedWriter.
- `PackedDataOutput`, `PackedDataInput`
  - Writes sequences of longs where each long can use any number of bits.

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