net.sf.zig_project.gpl.common.arrays
Interface ArraySizeSelector

All Known Implementing Classes:
DirectArraySizeSelector, ExponentialRatioArraySizeSelector, LinearArraySizeSelector, StuntedArraySizeSelector

public interface ArraySizeSelector

An ArraySizeSelector is a modular interface that recommends how large of a new array should be allocated for classes that need to maintain a dynamic array. The interface only provides a recommended size however, and classes using this interface are left with the task of allocation and duplication.

Version:
September 15, 2004
Author:
Frank Ziglar

Field Summary
static ArraySizeSelector DEFAULT
          The most generic selector, when indecisive about what type of selector to use.
 
Method Summary
 int grow(int current_size, int extra_room)
          When an array size is increased, this method will recommend a new size.
 

Field Detail

DEFAULT

public static final ArraySizeSelector DEFAULT
The most generic selector, when indecisive about what type of selector to use. For now, using an ExponentialRatioArraySizeSelector

Method Detail

grow

public int grow(int current_size,
                int extra_room)
When an array size is increased, this method will recommend a new size. Implementations are required to ensure that the returned value is always >= current_size+extra_room. This value will typically be larger than just the sum however, in order to minimized the number of times the array need be reallocated.

Parameters:
current_size - the length of the currently allocated array
extra_room - 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