Library / Collections / Sequences / SortedList
SortedList
Defines the SortedList[T] class per ENVZN_CONSTITUTION §SortedList (L703–716).
Fields 1
int32 lengthConstructors 1
INIT()Methods 13
METHOD clone() RETURNS SortedList[T]reads
Hand-written clone() — AUTO refused for the same cascade
reason as Queue / Stack / Deque / LinkedList: the synthesis
walker can't see T's Cloneable status from this instantiation
site through the LinkedList[T] composition. Walk the
underlying LinkedList's iterator and append a deep clone of
each element. Sort order is preserved because the source list
is already sorted and we visit front-to-back; we use
data->append (which adds to tail) rather than going through
SortedList.add's per-insert binary scan.
METHOD iterator() RETURNS LinkedListIterator[T]reads
ITERATOR — delegate to LinkedList's BidirectionalIterator
The element order is insertion order, which by the order
invariant is also ascending. Callers iterate front-to-back
for ascending traversal; back-to-front via previous() for
descending.
METHOD isEmpty() RETURNS booleanreads
METHOD size() RETURNS int64reads
Number of elements currently stored. Read-only, O(1).
MODIFY METHOD clear() RETURNS voidmodifies
MODIFY METHOD insert(T value) RETURNS STATUSmodifies
INSERT
Walks the iterator to find the first position where
value->isLessThan(elem) becomes TRUE — that's where value
belongs in the sorted order. The iterator is held in a
nested block so it drops (releasing the mutation lock on
_data) before the call to _data->insertAt.
Insert value at the position that keeps the list sorted.
Per §10.2 the bare-named form consumes the source —
value is moved into the list. The walk reads value for
comparison (read-only, doesn't consume) before the final
.data->insertAt call which performs the move.
MODIFY METHOD insertCopy(REFERENCE T value) RETURNS STATUSmodifies
Deep-copy form of insert. value stays valid for the caller;
the clone is the one moved into the list.
METHOD contains(REFERENCE T value) RETURNS booleanreads
CONTAINS / REMOVE — short-circuit on Comparable order
MODIFY METHOD remove(REFERENCE T value) RETURNS booleanmodifies
Remove the first element equal to value. Returns TRUE if
a match was found and removed, FALSE otherwise.
METHOD peekFirst() RETURNS | REFERENCE Treads
FRONT / BACK ACCESS — convenience wrappers over LinkedList
peekFirst returns the smallest element; peekLast the largest. popFirst / popLast remove and return them. All four are O(1) by virtue of LinkedList's existing front/back operations.
METHOD peekLast() RETURNS | REFERENCE Treads
MODIFY METHOD popFirst() RETURNS | Tmodifies
MODIFY METHOD popLast() RETURNS | Tmodifies