Module com.carrotsearch.hppc
Package com.carrotsearch.hppc
Class BoundedProportionalArraySizingStrategy
java.lang.Object
com.carrotsearch.hppc.BoundedProportionalArraySizingStrategy
- All Implemented Interfaces:
Accountable,ArraySizingStrategy
public final class BoundedProportionalArraySizingStrategy
extends Object
implements ArraySizingStrategy
Array resizing proportional to the current buffer size, optionally kept within the given minimum
and maximum growth limits. Java's
ArrayList uses:
minGrow = 1 maxGrow = Integer.MAX_VALUE (unbounded) growRatio = 1.5f
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatDefault resize is by half the current buffer's size.static final BoundedProportionalArraySizingStrategyInstance ofBoundedProportionalArraySizingStrategywith default values.static final intMaximum grow count (unbounded).static final intMinimum grow count.final floatThe current buffer length is multiplied by this ratio to get the first estimate for the new size.static final intMaximum allocable array length (approximately the largest positive integer decreased by the array's object header).final intMaximum number of elements to grow, if limit exceeded.final intMinimum number of elements to grow, if limit exceeded. -
Constructor Summary
ConstructorsConstructorDescriptionCreate the default sizing strategy.BoundedProportionalArraySizingStrategy(int minGrow, int maxGrow, float ratio) Create the sizing strategy with custom policies. -
Method Summary
Modifier and TypeMethodDescriptionintgrow(int currentBufferLength, int elementsCount, int expectedAdditions) longAllocated memory estimationlongBytes that is actually been used
-
Field Details
-
DEFAULT_INSTANCE
Instance ofBoundedProportionalArraySizingStrategywith default values. -
MAX_ARRAY_LENGTH
public static final int MAX_ARRAY_LENGTHMaximum allocable array length (approximately the largest positive integer decreased by the array's object header).- See Also:
-
DEFAULT_MIN_GROW_COUNT
public static final int DEFAULT_MIN_GROW_COUNTMinimum grow count.- See Also:
-
DEFAULT_MAX_GROW_COUNT
public static final int DEFAULT_MAX_GROW_COUNTMaximum grow count (unbounded).- See Also:
-
DEFAULT_GROW_RATIO
public static final float DEFAULT_GROW_RATIODefault resize is by half the current buffer's size.- See Also:
-
minGrowCount
public final int minGrowCountMinimum number of elements to grow, if limit exceeded. -
maxGrowCount
public final int maxGrowCountMaximum number of elements to grow, if limit exceeded. -
growRatio
public final float growRatioThe current buffer length is multiplied by this ratio to get the first estimate for the new size. To double the size of the current buffer, for example, set to2.
-
-
Constructor Details
-
BoundedProportionalArraySizingStrategy
public BoundedProportionalArraySizingStrategy()Create the default sizing strategy. -
BoundedProportionalArraySizingStrategy
public BoundedProportionalArraySizingStrategy(int minGrow, int maxGrow, float ratio) Create the sizing strategy with custom policies.- Parameters:
minGrow- Minimum number of elements to grow by when expanding.maxGrow- Maximum number of elements to grow by when expanding.ratio- The ratio of expansion compared to the previous buffer size.
-
-
Method Details
-
grow
public int grow(int currentBufferLength, int elementsCount, int expectedAdditions) - Specified by:
growin interfaceArraySizingStrategy- Parameters:
currentBufferLength- The current length of the buffer.elementsCount- The number of elements stored in the buffer.expectedAdditions- The number of expected additions to the buffer.- Returns:
- New buffer size.
-
ramBytesAllocated
public long ramBytesAllocated()Description copied from interface:AccountableAllocated memory estimation- Specified by:
ramBytesAllocatedin interfaceAccountable- Returns:
- Ram allocated in bytes
-
ramBytesUsed
public long ramBytesUsed()Description copied from interface:AccountableBytes that is actually been used- Specified by:
ramBytesUsedin interfaceAccountable- Returns:
- Ram used in bytes
-