Top Description Inners Fields Constructors Methods
com.carrotsearch.hppc

public Class PlaModel

extends Object
implements Accountable
Class Inheritance
All Implemented Interfaces
com.carrotsearch.hppc.Accountable
Imports
java.util.Arrays

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
PlaModel.Point

Re-usable mutable (x,y) point.

private static class
PlaModel.PointList

List of mutable Point.

public static interface
PlaModel.SegmentConsumer

Consumer notified when a new segment is built by the PlaModel.

private static class
PlaModel.Slope

Re-usable mutable (dx,dy) slope.

Field Summary

Modifier and TypeField and Description
private int
epsilon

Epsilon precision of the PLA-model.

private double
firstKey

First key of the current segment.

private static final int
INITIAL_CAPACITY

Initial capacity of the lower and upper point lists.

private final PlaModel.PointList
lower

Ordered list of lower points for the current segment.

private int
lowerStart

Index of the first lower point to compare to.

private int
numPointsInHull

Number of points in the convex hull for the current segment.

private final PlaModel.Point
private final PlaModel.Point
private double
previousKey

Previous key used to check that keys are added in strictly increasing sequence.

private final PlaModel.Point[]
rect

Enclosing rectangle for the current segment.

private final PlaModel.Slope
private final PlaModel.Slope
private final PlaModel.Slope
private final PlaModel.Slope
private final PlaModel.Slope
private final PlaModel.PointList
upper

Ordered list of upper points for the current segment.

private int
upperStart

Index of the first upper point to compare to.

Constructor Summary

AccessConstructor and Description
public
PlaModel(int
must be greater than or equal to 0.
epsilon
)

Creates an optimal PLA-model with the provided epsilon precision.

Method Summary

Modifier and TypeMethod and Description
private int
addEpsilon(int index)

public void
addKey(double key, int
The index of the key in the sorted key list.
index
,
PlaModel.SegmentConsumer
The consumer to call when a new segment is built in the PLA-model.
segmentConsumer
)

Adds a key to this PLA-model.

private static double
public void
finish(PlaModel.SegmentConsumer segmentConsumer)

Finishes the PLA-model construction.

private void
public long
public long
ramBytesUsed()

Implements com.carrotsearch.hppc.Accountable.ramBytesUsed.

Bytes that is actually been used

private void
public void
setEpsilon(int epsilon)

Sets epsilon precision which must be greater than or equal to 0.

private int
subtractEpsilon(int index)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

epsilonback to summary
private int epsilon

Epsilon precision of the PLA-model.

firstKeyback to summary
private double firstKey

First key of the current segment.

INITIAL_CAPACITYback to summary
private static final int INITIAL_CAPACITY

Initial capacity of the lower and upper point lists.

lowerback to summary
private final PlaModel.PointList lower

Ordered list of lower points for the current segment. Inside the list, allocated points are re-used.

lowerStartback to summary
private int lowerStart

Index of the first lower point to compare to.

numPointsInHullback to summary
private int numPointsInHull

Number of points in the convex hull for the current segment.

point1back to summary
private final PlaModel.Point point1
point2back to summary
private final PlaModel.Point point2
previousKeyback to summary
private double previousKey

Previous key used to check that keys are added in strictly increasing sequence.

rectback to summary
private final PlaModel.Point[] rect

Enclosing rectangle for the current segment.

slope1back to summary
private final PlaModel.Slope slope1
slope2back to summary
private final PlaModel.Slope slope2
slopeMaxback to summary
private final PlaModel.Slope slopeMax
slopeMinback to summary
private final PlaModel.Slope slopeMin
slopeTmpback to summary
private final PlaModel.Slope slopeTmp
upperback to summary
private final PlaModel.PointList upper

Ordered list of upper points for the current segment. Inside the list, allocated points are re-used.

upperStartback to summary
private int upperStart

Index of the first upper point to compare to.

Constructor Detail

PlaModelback to summary
public PlaModel(int epsilon)

Creates an optimal PLA-model with the provided epsilon precision.

Parameters
epsilon:int

must be greater than or equal to 0.

Method Detail

addEpsilonback to summary
private int addEpsilon(int index)
addKeyback to summary
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:int

The index of the key in the sorted key list.

segmentConsumer:PlaModel.SegmentConsumer

The consumer to call when a new segment is built in the PLA-model.

crossback to summary
private static double cross(PlaModel.Point o, PlaModel.Point a, PlaModel.Point b)
finishback to summary
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 SegmentConsumer.

produceSegmentback to summary
private void produceSegment(PlaModel.SegmentConsumer segmentConsumer)
ramBytesAllocatedback to summary
public long ramBytesAllocated()

Implements com.carrotsearch.hppc.Accountable.ramBytesAllocated.

Doc from com.carrotsearch.hppc.Accountable.ramBytesAllocated.

Allocated memory estimation

Returns:long

Ram allocated in bytes

Annotations
@Override
ramBytesUsedback to summary
public long ramBytesUsed()

Implements com.carrotsearch.hppc.Accountable.ramBytesUsed.

Doc from com.carrotsearch.hppc.Accountable.ramBytesUsed.

Bytes that is actually been used

Returns:long

Ram used in bytes

Annotations
@Override
resetback to summary
private void reset()
setEpsilonback to summary
public void setEpsilon(int epsilon)

Sets epsilon precision which must be greater than or equal to 0.

subtractEpsilonback to summary
private int subtractEpsilon(int index)
com.carrotsearch.hppc back to summary

private Class PlaModel.Point

extends Object
Class Inheritance

Re-usable mutable (x,y) point.

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv double
x

pack-priv long
y

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv PlaModel.Point
set(double x, long y)

pack-priv PlaModel.Point
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

RAM_BYTES_ALLOCATEDback to summary
pack-priv static final int RAM_BYTES_ALLOCATED
xback to summary
pack-priv double x
yback to summary
pack-priv long y

Constructor Detail

Pointback to summary
private Point()

Method Detail

setback to summary
pack-priv PlaModel.Point set(double x, long y)
setback to summary
pack-priv PlaModel.Point set(PlaModel.Point p)
com.carrotsearch.hppc back to summary

private Class PlaModel.PointList

extends Object
implements Accountable
Class Inheritance
All Implemented Interfaces
com.carrotsearch.hppc.Accountable

List of mutable Point. Re-uses allocated points instead of creating new instances.

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv PlaModel.Point[]
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv
PointList(int initialCapacity)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
pack-priv void
clearFrom(int end)

pack-priv PlaModel.Point
get(int index)

public long
public long
ramBytesUsed()

Implements com.carrotsearch.hppc.Accountable.ramBytesUsed.

Bytes that is actually been used

pack-priv int
size()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

numAllocatedback to summary
pack-priv int numAllocated
pointsback to summary
pack-priv PlaModel.Point[] points
sizeback to summary
pack-priv int size

Constructor Detail

PointListback to summary
pack-priv PointList(int initialCapacity)

Method Detail

addback to summary
pack-priv void add(PlaModel.Point point)
clearback to summary
pack-priv void clear()
clearFromback to summary
pack-priv void clearFrom(int end)
getback to summary
pack-priv PlaModel.Point get(int index)
ramBytesAllocatedback to summary
public long ramBytesAllocated()

Implements com.carrotsearch.hppc.Accountable.ramBytesAllocated.

Doc from com.carrotsearch.hppc.Accountable.ramBytesAllocated.

Allocated memory estimation

Returns:long

Ram allocated in bytes

Annotations
@Override
ramBytesUsedback to summary
public long ramBytesUsed()

Implements com.carrotsearch.hppc.Accountable.ramBytesUsed.

Doc from com.carrotsearch.hppc.Accountable.ramBytesUsed.

Bytes that is actually been used

Returns:long

Ram used in bytes

Annotations
@Override
sizeback to summary
pack-priv int size()
com.carrotsearch.hppc back to summary

public Interface PlaModel.SegmentConsumer

Known Direct Implementers
com.carrotsearch.hppc.IntPgmIndex.IntBuilder, com.carrotsearch.hppc.DoublePgmIndex.DoubleBuilder, com.carrotsearch.hppc.LongPgmIndex.LongBuilder, com.carrotsearch.hppc.FloatPgmIndex.FloatBuilder

Consumer notified when a new segment is built by the PlaModel.

Method Summary

Modifier and TypeMethod and Description
public void
accept(double
The first key of the segment.
firstKey
,
double
The segment slope.
slope
,
long
The segment intercept.
intercept
)

Consumes a new segment.

Method Detail

acceptback to summary
public void accept(double firstKey, double slope, long intercept)

Consumes a new segment. The segment is defined by the epsilon-approximation function fs(k) = k × slope + intercept.

Parameters
firstKey:double

The first key of the segment.

slope:double

The segment slope.

intercept:long

The segment intercept.

com.carrotsearch.hppc back to summary

private Class PlaModel.Slope

extends Object
Class Inheritance

Re-usable mutable (dx,dy) slope.

Field Summary

Modifier and TypeField and Description
pack-priv double
pack-priv long
pack-priv static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static double
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv void
pack-priv PlaModel.Slope
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dxback to summary
pack-priv double dx
dyback to summary
pack-priv long dy
RAM_BYTES_ALLOCATEDback to summary
pack-priv static final int RAM_BYTES_ALLOCATED

Constructor Detail

Slopeback to summary
private Slope()

Method Detail

asDoubleback to summary
pack-priv static double asDouble(PlaModel.Point p1, PlaModel.Point p2)
isEqualback to summary
pack-priv boolean isEqual(PlaModel.Slope s)
isGreaterThanback to summary
pack-priv boolean isGreaterThan(PlaModel.Slope s)
isLessThanback to summary
pack-priv boolean isLessThan(PlaModel.Slope s)
setback to summary
pack-priv void set(PlaModel.Slope s)
setback to summary
pack-priv PlaModel.Slope set(PlaModel.Point p1, PlaModel.Point p2)