-
Effekt Library
- resizable_array
- ResizableArray
- growFactor
- shrinkThreshold
- size
- resizableArray
- resizableArray
- boundsCheck
- get
- set
- swap
- setCapacity
- maybeShrink
- ensureCapacity
- setResizing
- add
- popRight
- foreach
- foreach
- foreachIndex
- foreachIndex
- foreachReversed
- foreachReversed
- foreachIndexReversed
- foreachIndexReversed
- toList
- each
- feed
- collect
- returning
- collect
- resizable_array Jump to source: libraries/common/resizable_array.effekt
- ResizableArray
[T] (rawSizePtr: Ref[Int], rawContentPtr: Ref[Array[T]]) - growFactor
- shrinkThreshold
- size
[T] (arr: ResizableArray[T]) - resizableArray
[T] (capacity: Int): ResizableArray[T] / {} - resizableArray
[T]: ResizableArray[T] / {} - boundsCheck
[T] (arr: ResizableArray[T], index: Int): Unit / {Exception[OutOfBounds]} - get
[T] (arr: ResizableArray[T], index: Int): T / {Exception[OutOfBounds]} - set
[T] (arr: ResizableArray[T], index: Int, value: T): Unit / {Exception[OutOfBounds]} - swap
[T] (arr: ResizableArray[T], index1: Int, index2: Int): Unit / {Exception[OutOfBounds]} - setCapacity
[T] (arr: ResizableArray[T], capacity: Int): Unit / {Exception[OutOfBounds]} - maybeShrink
[T] (arr: ResizableArray[T]): Unit / {Exception[OutOfBounds]} - ensureCapacity
[T] (arr: ResizableArray[T], capacity: Int): Unit / {Exception[OutOfBounds]} - setResizing
[T] (arr: ResizableArray[T], index: Int, value: T): Unit / {Exception[OutOfBounds]} - add
[T] (arr: ResizableArray[T], value: T): Int / {} - popRight
[T] (arr: ResizableArray[T]): T / {Exception[OutOfBounds]} - foreach
[T] (arr: ResizableArray[T]) { action: (T) => Unit }: Unit / {} - foreach
[T] (arr: ResizableArray[T]) { action: (T){Label} => Unit }: Unit / {} - foreachIndex
[T] (arr: ResizableArray[T]) { action: (Int, T) => Unit }: Unit / {} - foreachIndex
[T] (arr: ResizableArray[T]) { action: (Int, T){Label} => Unit }: Unit / {} - foreachReversed
[T] (arr: ResizableArray[T]) { action: (T) => Unit }: Unit / {} - foreachReversed
[T] (arr: ResizableArray[T]) { action: (T){Label} => Unit }: Unit / {} - foreachIndexReversed
[T] (arr: ResizableArray[T]) { action: (Int, T) => Unit }: Unit / {} - foreachIndexReversed
[T] (arr: ResizableArray[T]) { action: (Int, T){Label} => Unit }: Unit / {} - toList
[T] (arr: ResizableArray[T]): List[T] / {} - each
[T] (arr: ResizableArray[T]): Unit / {emit[T]} - feed
[R, T] (arr: ResizableArray[T]) { reader: => R / {read[T]} }: R / {} - collect
[T] { stream: => Unit / {emit[T]} }: ResizableArray[T] / {} - returning
- collect
[T, R] { stream: => R / {emit[T]} }: Tuple2[R, ResizableArray[T]] / {}
Example usage: examples/stdlib/resizable_array
A resizable array, implemented as a wrapper around a mutable array and a size field.
Factor by which to grow the capacity when it becomes too small
shrink array when size / capacity falls below this threshold should be < 1/growFactor
Number of elements in the dynamic array O(1)
Allocate a new, empty dynamic array with given initial capacity
Allocate a new, empty dynamic array
Throw an OutOfBounds exception if index is not a valid index into arr
Get the element at position `index` in the resizable array `arr` O(1)
Set the element at position `index` in the resizable array `arr` to `value` O(1)
Swap the elements at the given positions in the resizable array `arr` O(1)
Change the resizable array to have exactly the given capacity. This only changes the size of the backing array, not the `size`. O(n)
If the shrinkThreshold is reached, shrink by growFactor, otherwise do nothing O(n)
Makes sure capacity is at least the given one O(given capacity - current capacity) amortized, O(n) worst case // TODO ?
Set the value at given position, resizing if necessary Note: New elements might be uninitialized!!! O(max(1,index - n)) amortized, O(n) worst case if index > capacity
Add a new element at the end of the resizable array. Return the index of the new element O(1) amortized, O(n) worst case
Remove and return the rightmost element in the resizable array. O(1) amortized, O(n) worst case
Traverse the resizable array `arr`, applying the given action on every element.
Traverse the resizable array `arr`, applying the given action on every element, providing a `label` for `break`/`continue`.
Traverse the resizable array `arr`, applying the given action on every element and its (zero-based) index.
Traverse the resizable array `arr`, applying the given action on every element and its (zero-based) index, providing a `label` for `break`/`continue`.
Traverse the resizable array `arr` in reverse order, applying the given action on every element.
Traverse the resizable array `arr` in reverse order, applying the given action on every element, providing a `label` for `break`/`continue`.
Traverse the resizable array `arr` in reverse order, applying the given action on every element and its (zero-based) index.
Traverse the resizable array `arr` in reverse order, applying the given action on every element and its (zero-based) index, providing a `label` for `break`/`continue`.
Create a new list from a given resizable array `arr`.
Turns `arr` into a producer of a push stream by emitting each contained value from 0 to length - 1.
Connects `arr` as a producer to a given pull stream `reader` acting as a consumer.
Collects elements emitted by a push stream producer `stream` into a new resizable array, discarding the result of the producer.
Collects elements emitted by a push stream producer `stream` into a new resizable array, returning the result of the producer as well as the collected array.