com.carrotsearch.hppc
Class BoundedProportionalArraySizingStrategy

java.lang.Object
  extended by com.carrotsearch.hppc.BoundedProportionalArraySizingStrategy
All Implemented Interfaces:
ArraySizingStrategy

public final class BoundedProportionalArraySizingStrategy
extends java.lang.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
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.
 int maxGrowCount
          Maximum number of elements to grow, if capacity exceeded.
 int minGrowCount
          Minimum number of elements to grow, if capacity exceeded.
 
Constructor Summary
BoundedProportionalArraySizingStrategy()
          Create the default sizing strategy.
BoundedProportionalArraySizingStrategy(int minGrow, int maxGrow, float ratio)
          Create the sizing strategy with custom policies.
 
Method Summary
 int grow(int currentBufferLength, int elementsCount, int expectedAdditions)
          Grow according to growRatio, minGrowCount and maxGrowCount.
 int round(int capacity)
          No specific requirements in case of this strategy - the argument is returned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MIN_GROW_COUNT

public static final int DEFAULT_MIN_GROW_COUNT
Minimum grow count.

See Also:
Constant Field Values

DEFAULT_MAX_GROW_COUNT

public static final int DEFAULT_MAX_GROW_COUNT
Maximum grow count (unbounded).

See Also:
Constant Field Values

DEFAULT_GROW_RATIO

public static final float DEFAULT_GROW_RATIO
Default resize is by half the current buffer's size.

See Also:
Constant Field Values

minGrowCount

public final int minGrowCount
Minimum number of elements to grow, if capacity exceeded.


maxGrowCount

public final int maxGrowCount
Maximum number of elements to grow, if capacity exceeded.


growRatio

public final float growRatio
The 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 to 2.

Constructor Detail

BoundedProportionalArraySizingStrategy

public BoundedProportionalArraySizingStrategy()
Create the default sizing strategy.


BoundedProportionalArraySizingStrategy

public BoundedProportionalArraySizingStrategy(int minGrow,
                                              int maxGrow,
                                              float ratio)
Create the sizing strategy with custom policies.

Method Detail

grow

public int grow(int currentBufferLength,
                int elementsCount,
                int expectedAdditions)
Grow according to growRatio, minGrowCount and maxGrowCount.

Specified by:
grow in interface ArraySizingStrategy
Parameters:
currentBufferLength - Current size of the array (buffer). This number should comply with the strategy's policies (it is a result of initial rounding or further growths). It can also be zero, indicating the growth from an empty buffer.
elementsCount - Number of elements stored in the buffer.
expectedAdditions - Expected number of additions (resize hint).
Returns:
Must return a new size at least as big as to hold elementsCount + expectedAdditions.

round

public int round(int capacity)
No specific requirements in case of this strategy - the argument is returned.

Specified by:
round in interface ArraySizingStrategy


Copyright © 2011 Carrot Search s.c.. All Rights Reserved.