|
ContentsBasic methodsdata T a Type of lists. new :: () -> <Proc> ArrayList.T a Constructs a new list. add :: ArrayList.T a -> a -> <Proc> () Adds an element to the list. remove :: ArrayList.T a -> Integer -> <Proc> a Removes the i:th element of the list and returns it. Indexing starts from zero. get :: ArrayList.T a -> Integer -> <Proc> a Gets the i:th element of the list. Indexing starts from zero. length :: ArrayList.T a -> <Proc> Integer The current length of the list. contains :: ArrayList.T a -> a -> <Proc> Boolean Returns Iterationiter :: (a -> <b> ()) -> ArrayList.T a -> <Proc,b> () Iterates through the list. The elements added during the iteration are also iterated. The length is re-read before every step, so appending to the list from inside the
function extends the iteration instead of failing or being ignored. That makes
this usable as a worklist loop, and also means the iteration does not terminate if
the function always appends. Example:
The for :: ArrayList.T a -> (a -> <b> ()) -> <Proc,b> ()
mapInPlace :: (a -> <b> a) -> ArrayList.T a -> <Proc,b> ArrayList.T a Replaces every element of the list by the result of applying the element to the given function. The given list is mutated and the very same list is returned; the result is not a copy, so the return value can be ignored. Unlike Examples:
Only the two original elements are mapped here, even though the list grows to four:
popUntilEmpty :: ArrayList.T a -> (a -> <b> ()) -> <Proc,b> () Pops the last element of the list until list becomes empty. Elements are consumed from the end of the list, so this is a LIFO worklist drain, not a front-to-back traversal: the function is called with the elements in reverse order and the list is left empty. Because the last element is re-read on every step, the function may push more work onto the list. Note the argument order, which is the reverse of Example:
Undocumented entitiesaddAll :: ArrayList.T a -> [a] -> <Proc> () Adds all elements of the given list to the end of the list. freeze :: ArrayList.T a -> <Proc> [a] Converts the mutable list into an immutable one without copying the underlying data. This only changes how the structure is treated by the SCL type system; it is an O(1) operation, not a copy. The original mutable list must not be used anymore after this. The result aliases the original: it is the same object, only retyped. Every
subsequent mutation of the mutable list is visible through the supposedly
immutable one, as the example shows. That is why the original must be dropped.
This module has no copying counterpart; Example:
fromList :: [a] -> <Proc> ArrayList.T a Creates a new mutable list containing the elements of the given immutable list. newC :: Integer -> <Proc> ArrayList.T a Constructs a new list with initial capacity. set :: ArrayList.T a -> Integer -> a -> <Proc> a Sets the i:th element of the list and returns the element that was there before. Indexing starts from zero. ( Example:
|