set

open operator override fun set(index: Int, element: E): E

Replace the element at index with element, updating its weight as computed by weighter.

Preconditions:

  • index must be valid.

  • new weight must be within bounds.

  • new weight must be >= left neighbor weight (if present) and <= right neighbor weight (if present).

If these checks fail, an IllegalStateException is thrown and the list remains unchanged.

Return

the previous element at index

Parameters

index

index to replace

element

new element

Throws

if new weight is out of bounds or violates neighboring order

Complexity: O(1) for update.