envzn
0.8 · beta · not released

Library / Collections / Sequences / SortedList

CLASSIMPLEMENTS Cloneable, Collection<T>

SortedList

Defines the SortedList[T] class per ENVZN_CONSTITUTION §SortedList (L703–716).

Fields 1

int32 length

Constructors 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 boolean
reads
METHOD size() RETURNS int64
reads

Number of elements currently stored. Read-only, O(1).

MODIFY METHOD clear() RETURNS void
modifies
MODIFY METHOD insert(T value) RETURNS STATUS
modifies

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 STATUS
modifies

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 boolean
reads

CONTAINS / REMOVE — short-circuit on Comparable order

MODIFY METHOD remove(REFERENCE T value) RETURNS boolean
modifies

Remove the first element equal to value. Returns TRUE if a match was found and removed, FALSE otherwise.

METHOD peekFirst() RETURNS | REFERENCE T
reads

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 T
reads
MODIFY METHOD popFirst() RETURNS | T
modifies
MODIFY METHOD popLast() RETURNS | T
modifies