class DummyArray
super Set[Int]
- super ArrayCapable[Int]
private var capacity: Int
redef var length: Int
private var keys: NativeArray[Int]
init(capacity: Int)
do
_capacity = capacity
- _keys = calloc_array(capacity)
- _values = calloc_array(capacity)
+ _keys = new NativeArray[Int](capacity)
+ _values = new NativeArray[Int](capacity)
end
end
# assert a == b
class Array[E]
super AbstractArray[E]
- super ArrayCapable[E]
redef fun [](index)
do
var c = _capacity
if cap <= c then return
while c <= cap do c = c * 2 + 2
- var a = calloc_array(c)
+ var a = new NativeArray[E](c)
if _capacity > 0 then _items.copy_to(a, _length)
_items = a
_capacity = c
init with_capacity(cap: Int)
do
assert positive: cap >= 0
- _items = calloc_array(cap)
+ _items = new NativeArray[E](cap)
_capacity = cap
_length = 0
end
init filled_with(value: E, count: Int)
do
assert positive: count >= 0
- _items = calloc_array(count)
+ _items = new NativeArray[E](count)
_capacity = count
_length = count
var i = 0
# Native classes ##############################################################
-# Subclasses of this class can create native arrays
-interface ArrayCapable[E]
- # Get a new array of `size` elements.
- protected fun calloc_array(size: Int): NativeArray[E] is intern
-end
-
# Native Nit array
# Access are unchecked and it has a fixed size
# Not for public use: may become private.
# A HashCollection is an array of HashNode[K] indexed by the K hash value
private abstract class HashCollection[K: Object, N: HashNode[Object]]
- super ArrayCapable[nullable N]
private var array: nullable NativeArray[nullable N] = null # Used to store items
private var capacity: Int = 0 # Size of _array
_last_accessed_key = null
# get a new array
- var new_array = calloc_array(cap)
+ var new_array = new NativeArray[nullable N](cap)
_array = new_array
# clean the new array
# limitations under the License.
class Toto
- super ArrayCapable[Int]
+
fun toto
do
- var a = calloc_array(3)
+ var a = new NativeArray[Int](3)
a[0] = 10
a[1] = 20
a[2] = 30