Merge: Basename fix
[nit.git] / lib / dummy_array.nit
index 21da4bd..85440b4 100644 (file)
@@ -1,6 +1,7 @@
 # This file is part of NIT ( http://www.nitlanguage.org ).
 #
 # Copyright 2008 Floréal Morandat <morandat@lirmm.fr>
+# Copyright 2014 Alexandre Terrasa <alexandre@moz-code.org>
 #
 # This file is free software, which comes along with NIT.  This software is
 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
@@ -10,9 +11,9 @@
 # You  are  allowed  to  redistribute it and sell it, alone or is a part of
 # another product.
 
+# A `Set` that contains only integers.
 class DummyArray
        super Set[Int]
-       super ArrayCapable[Int]
        private var capacity: Int
        redef var length: Int
        private var keys: NativeArray[Int]
@@ -27,9 +28,10 @@ class DummyArray
                _length = l + 1
        end
 
-       redef fun remove(value: Int)
+       redef fun remove(value)
        do
                assert not is_empty
+               if not value isa Int then return
                var l = _length
                if l > 1 then
                        var last = _values[l - 1]
@@ -40,8 +42,9 @@ class DummyArray
                _length = l - 1
        end
 
-       redef fun has(value: Int): Bool
+       redef fun has(value)
        do
+               if not value isa Int then return false
                assert value < _capacity
                var pos = _keys[value]
                if pos < _length then
@@ -76,14 +79,15 @@ class DummyArray
                return _values[pos]
        end
 
-       init(capacity: Int)
-       do
+       # initialize a new DummyArray with `capacity`.
+       init(capacity: Int) is old_style_init do
                _capacity = capacity
-               _keys = calloc_array(capacity)
-               _values = calloc_array(capacity)
+               _keys = new NativeArray[Int](capacity)
+               _values = new NativeArray[Int](capacity)
        end
 end
 
+# An iterator over a `DummyArray`.
 class DummyIterator
        super Iterator[Int]
        private var array: DummyArray
@@ -102,8 +106,8 @@ class DummyIterator
 
        redef fun next do _pos = _pos + 1 end
 
-       init(array: DummyArray)
-       do
+       # Initialize an iterator for `array`.
+       init(array: DummyArray) is old_style_init do
                _pos = 0
                _array = array
        end