Interface CapacityManagement
-
- All Known Implementing Classes:
BinaryHeap,ResizingArrayStorage,UnorderedCollection
public interface CapacityManagementControl interface for collections supporting a capacity management, i.e., reserving space in advance in order to avoid repeated reallocations.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanensureAdditionalCapacity(int additionalCapacity)Ensures that the internal storage has room for at least the provided number of additional elements.booleanensureCapacity(int minCapacity)Ensures that the internal storage has room for at least the provided number of elements.voidhintNextCapacity(int nextCapacityHint)Gives a hint regarding the capacity that should be reserved when resizing the internal storage for the next time.
-
-
-
Method Detail
-
ensureCapacity
boolean ensureCapacity(int minCapacity)
Ensures that the internal storage has room for at least the provided number of elements.- Parameters:
minCapacity- the minimal number of elements the storage should have room for.- Returns:
trueiff the internal storage had to be resized,falseotherwise.
-
ensureAdditionalCapacity
boolean ensureAdditionalCapacity(int additionalCapacity)
Ensures that the internal storage has room for at least the provided number of additional elements.Calling this method is equivalent to calling the above
ensureCapacity(int)with an argument ofsize() + additionalCapacity.- Parameters:
additionalCapacity- the number of additional elements the storage should have room for.- Returns:
trueiff the internal storage had to be resized,falseotherwise.
-
hintNextCapacity
void hintNextCapacity(int nextCapacityHint)
Gives a hint regarding the capacity that should be reserved when resizing the internal storage for the next time. This method acts like a "lazy"ensureCapacity(int), i.e. it reserves the specified capacity at the time the next resizing of the internal storage is performed.This method is useful when a not too imprecise upper bound on the elements that will in consequence be added is known. Since the actual number of elements added may be lower than the specified upper bound, a resizing that would have been performed by
ensureCapacity(int)might not be necessary.- Parameters:
nextCapacityHint- the next capacity hint.
-
-