net.sf.zig_project.gpl.common.arrays
Class LinearArraySizeSelector

java.lang.Object
  extended bynet.sf.zig_project.gpl.common.arrays.LinearArraySizeSelector
All Implemented Interfaces:
ArraySizeSelector

public class LinearArraySizeSelector
extends Object
implements ArraySizeSelector

A LinearArraySizeSelector recommends that an array be resized based on it's current size, multipled by a constant scalar value.

Version:
September 15, 2004
Author:
Frank Ziglar

Field Summary
 
Fields inherited from interface net.sf.zig_project.gpl.common.arrays.ArraySizeSelector
DEFAULT
 
Constructor Summary
LinearArraySizeSelector(float f)
          Constructs a Linear Selector based on the provided ratio.
 
Method Summary
 int grow(int n, int rm)
          Recommends that the array grow by the set proportion.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinearArraySizeSelector

public LinearArraySizeSelector(float f)
Constructs a Linear Selector based on the provided ratio. If the ratio is < 1.0, it is considered a growth rate, and recommendations are increased by that proportion. Otherwise, the array is scaled by that proportion directly.

Parameters:
f - the scalar to base recomendations on
Throws:
IllegalArgumentException - if f < 0.0
Method Detail

grow

public int grow(int n,
                int rm)
Recommends that the array grow by the set proportion. However, if more room is required, it only recommends that the array size be incremented by the required room.

Specified by:
grow in interface ArraySizeSelector
Parameters:
n - the length of the currently allocated array
rm - an estimate of the number of elements that need to be added to the array before the size is reconsidered.
Returns:
the total recommended size for a new array