-
Effekt Library
- resizable_array
- ResizableArray
- growFactor
- shrinkThreshold
- size
- resizableArray
- resizableArray
- boundsCheck
- unsafeGet
- get
- unsafeSet
- set
- unsafeSwap
- swap
- unsafeSetCapacity
- setCapacity
- maybeShrink
- ensureCapacity
- setResizing
- add
- popRight
- foreachIndex
- foreachIndex
- foreach
- foreach
- foreachIndexReversed
- foreachIndexReversed
- foreachReversed
- foreachReversed
- toList
- 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]}
- unsafeGet
[T] (arr: ResizableArray[T], index: Int): T / {}
- get
[T] (arr: ResizableArray[T], index: Int): T / {Exception[OutOfBounds]}
- unsafeSet
[T] (arr: ResizableArray[T], index: Int, value: T): Unit / {}
- set
[T] (arr: ResizableArray[T], index: Int, value: T): Unit / {Exception[OutOfBounds]}
- unsafeSwap
[T] (arr: ResizableArray[T], index1: Int, index2: Int): Unit / {}
- swap
[T] (arr: ResizableArray[T], index1: Int, index2: Int): Unit / {Exception[OutOfBounds]}
- unsafeSetCapacity
[T] (arr: ResizableArray[T], capacity: Int): Unit / {}
- setCapacity
[T] (arr: ResizableArray[T], capacity: Int): Unit / {Exception[OutOfBounds]}
- maybeShrink
[T] (arr: ResizableArray[T]): Unit / {}
- 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]}
- foreachIndex
[T] (arr: ResizableArray[T]) { body: (Int, T) => Unit }: Unit / {}
- foreachIndex
[T] (arr: ResizableArray[T]) { body: (Int, T){Control} => Unit }: Unit / {}
- foreach
[T] (arr: ResizableArray[T]) { body: (T) => Unit }: Unit / {}
- foreach
[T] (arr: ResizableArray[T]) { body: (T){Control} => Unit }: Unit / {}
- foreachIndexReversed
[T] (arr: ResizableArray[T]) { body: (Int, T){Control} => Unit }: Unit / {}
- foreachIndexReversed
[T] (arr: ResizableArray[T]) { body: (Int, T) => Unit }: Unit / {}
- foreachReversed
[T] (arr: ResizableArray[T]) { body: (T){Control} => Unit }: Unit / {}
- foreachReversed
[T] (arr: ResizableArray[T]) { body: (T) => Unit }: Unit / {}
- toList
[T] (arr: ResizableArray[T]): List[T] / {}
Example usage: examples/stdlib/resizable_array
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 array precondition: index is a valid index into the array O(1)
get the element at position index in the array O(1)
set the element at position index in the array precondition: index is a valid index into the array O(1)
set the element at position index in the array O(1)
swap the elements at the given positions in the array precondition: both are valid indices into the array O(1)
swap the elements at the given positions in the array O(1)
Change the dynamic to have exactly the given capacity precondition: given capacity is at least the size of the array O(n)
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