public final class BoundedProportionalArraySizingStrategy extends java.lang.Object implements ArraySizingStrategy
ArrayList
uses:
minGrow = 1 maxGrow = Integer.MAX_VALUE (unbounded) growRatio = 1.5f
Modifier and Type | Field and Description |
---|---|
static float |
DEFAULT_GROW_RATIO
Default resize is by half the current buffer's size.
|
static int |
DEFAULT_MAX_GROW_COUNT
Maximum grow count (unbounded).
|
static int |
DEFAULT_MIN_GROW_COUNT
Minimum grow count.
|
float |
growRatio
The current buffer length is multiplied by this ratio to get the first
estimate for the new size.
|
static int |
MAX_ARRAY_LENGTH
Maximum allocable array length (approximately the largest positive integer
decreased by the array's object header).
|
int |
maxGrowCount
Maximum number of elements to grow, if limit exceeded.
|
int |
minGrowCount
Minimum number of elements to grow, if limit exceeded.
|
Constructor and Description |
---|
BoundedProportionalArraySizingStrategy()
Create the default sizing strategy.
|
BoundedProportionalArraySizingStrategy(int minGrow,
int maxGrow,
float ratio)
Create the sizing strategy with custom policies.
|
Modifier and Type | Method and Description |
---|---|
int |
grow(int currentBufferLength,
int elementsCount,
int expectedAdditions)
|
public static final int MAX_ARRAY_LENGTH
public static final int DEFAULT_MIN_GROW_COUNT
public static final int DEFAULT_MAX_GROW_COUNT
public static final float DEFAULT_GROW_RATIO
public final int minGrowCount
public final int maxGrowCount
public final float growRatio
2
.public BoundedProportionalArraySizingStrategy()
public BoundedProportionalArraySizingStrategy(int minGrow, int maxGrow, float ratio)
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.public int grow(int currentBufferLength, int elementsCount, int expectedAdditions)
grow
in interface ArraySizingStrategy
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.Copyright © 2015 Carrot Search s.c.. All Rights Reserved.