SortedListX<T extends Object> extension

Useful extension functions for sorted Lists.

on

Methods

mergeSorted<K>(Iterable<T>? other, {required K key(T item), required Comparator<T> compare, T update(T original, T updated)?}) List<T>

Available on List<T>, provided by the SortedListX extension

Merges this list with other via an O(N+M) two-pointer pass, with duplicates deduplicated by key.
sortedInsert(T element, {required Comparator<T> compare}) List<T>

Available on List<T>, provided by the SortedListX extension

Inserts element into this sorted list at the correct position.
sortedUpsert<K>(T element, {required K key(T item), T update(T original, T updated)?, required Comparator<T> compare}) List<T>

Available on List<T>, provided by the SortedListX extension

Inserts or replaces element in this sorted list by key.
sortedUpsertAt(int existingIndex, T element, {required Comparator<T> compare, T update(T original, T updated)?}) List<T>

Available on List<T>, provided by the SortedListX extension

Like sortedUpsert but with the existing-element index pre-supplied by the caller — useful when the caller already has the index from another scan (e.g. an oldMessage lookup in the same code path). Avoids the duplicate O(N) indexWhere that sortedUpsert would otherwise run.