SLArray
SLArray is a concrete, fixed-capacity, bounds-safe String array in the
SLeeLa collections library. It wraps the VM-managed native array primitive
(arrayNew/arrayGet/arraySet/arrayLength) behind a forgiving, bounds-
checked API. It requires no Generics and no new VM opcodes.
Unlike SLList (a growable list whose logical length tracks appends),
SLArray has a fixed logical length equal to its capacity: once
allocate(n) is called, every index 0 .. n-1 is addressable and starts as
null.
Naming note: the symbol
SLArraynow has a single definition, in thecollectionsfamily. The formercore.SLArray(which held no array storage) was renamed toSLCoreCellso thatSLArrayresolves unambiguously.
Operations
allocate(int n): (re-)allocatennull slots; a negativenis clamped to0.length()/empty(): number of slots / whether there are none.inBounds(int index): whetherindexaddresses a real slot.get(int index): slot value, ornullfor an out-of-range index (no trap).set(int index, String value): write a slot; returnsfalsewhen out of range.fill(String value): set every slot tovalue.clear(): set every slot back tonull.indexOf(String value)/contains(String value): linear search (matchesnull).reverse(): reverse the contents in place.copyTo(SLArray dest, int srcPos, int destPos, int length): copy a range into anotherSLArray, clamped so the call is always safe; returns the number of slots actually copied.toList(): produce an independentSLListwith the same values.
Indices are zero-based. Out-of-range reads return null and out-of-range
writes return false, rather than trapping, matching the forgiving contract
used across the collections family. This first version accepts Strings only.
Example
See SLArrayBasic for an exercise of
allocation, bounds behavior, fill/clear, search, reverse, range copy, and
conversion to SLList.