Class PlaModel

java.lang.Object
com.carrotsearch.hppc.PlaModel
All Implemented Interfaces:
Accountable

public class PlaModel extends Object implements Accountable
Optimal Piecewise Linear Approximation Model for KType keys.

Learns a mapping that returns a position for a KType key which is at most epsilon away from the correct one in a sorted list of keys. It is optimal and piecewise because it learns the minimum number of epsilon-approximate segments.

The PLA-model consists of a sequence segments. A segment s is a triple (key,slope,intercept) that indexes a range of keys through the function fs(k) = k × slope + intercept, which provides an epsilon-approximation of the position of the key k.

  • Constructor Details

    • PlaModel

      public PlaModel(int epsilon)
      Creates an optimal PLA-model with the provided epsilon precision.
      Parameters:
      epsilon - must be greater than or equal to 0.
  • Method Details

    • setEpsilon

      public void setEpsilon(int epsilon)
      Sets epsilon precision which must be greater than or equal to 0.
    • addKey

      public void addKey(double key, int index, PlaModel.SegmentConsumer segmentConsumer)
      Adds a key to this PLA-model. The keys must be provided in a strictly increasing sequence. That is, the key must be greater than the previous key.
      Parameters:
      index - The index of the key in the sorted key list.
      segmentConsumer - The consumer to call when a new segment is built in the PLA-model.
    • finish

      public void finish(PlaModel.SegmentConsumer segmentConsumer)
      Finishes the PLA-model construction. Declares that no additional keys will be added. Builds the last segment and calls the provided PlaModel.SegmentConsumer.
    • ramBytesAllocated

      public long ramBytesAllocated()
      Description copied from interface: Accountable
      Allocated memory estimation
      Specified by:
      ramBytesAllocated in interface Accountable
      Returns:
      Ram allocated in bytes
    • ramBytesUsed

      public long ramBytesUsed()
      Description copied from interface: Accountable
      Bytes that is actually been used
      Specified by:
      ramBytesUsed in interface Accountable
      Returns:
      Ram used in bytes