addAll

open override fun addAll(elements: Collection<E>): Boolean

Add all elements from the given collection while preserving the sorted-by-weight invariant.

Behavior:

  • Each element’s weight is computed via the configured weighter.

  • Elements with out-of-bounds weights are skipped and not added.

  • Valid elements are collected, internally sorted by their weight in non-decreasing order, and then merged into the current list so that overall order is preserved.

The method returns true if at least one element was successfully inserted.

Notes:

  • The final list remains globally sorted by weight after the operation.

  • Insertions are stable for elements with equal weights (existing items remain before newly added ones).

  • Complexity: O(m log m + n) for m new elements and n existing items in the list (due to sorting and merging).

Return

true if the list changed as a result, false otherwise

Parameters

elements

collection of elements to add


open override fun addAll(index: Int, elements: Collection<E>): Boolean

Insert a contiguous block of elements at index.

Preconditions checked before mutation:

  • index must be a valid insertion index.

  • None of the elements' weights may be out of the configured bounds.

  • The computed weights for the block must be non-decreasing internally (block must be sorted).

  • The first weight in the block must be >= weight at index - 1 (if index 0).

  • The last weight in the block must be <= weight at index (if index < size).

If any condition fails the method returns false and the list is unchanged.

Return

true if elements were inserted, false otherwise

Parameters

index

insertion index

elements

collection of elements for the block

Throws