Interface CapacityManagement

  • All Known Implementing Classes:
    BinaryHeap, ResizingArrayStorage, UnorderedCollection

    public interface CapacityManagement
    Control 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
      boolean ensureAdditionalCapacity​(int additionalCapacity)
      Ensures that the internal storage has room for at least the provided number of additional elements.
      boolean ensureCapacity​(int minCapacity)
      Ensures that the internal storage has room for at least the provided number of elements.
      void hintNextCapacity​(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:
        true iff the internal storage had to be resized, false otherwise.
      • 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 of size() + additionalCapacity.

        Parameters:
        additionalCapacity - the number of additional elements the storage should have room for.
        Returns:
        true iff the internal storage had to be resized, false otherwise.
      • 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.