model: intro `MModule::first_real_mmodule` to get the first non-fictive module
[nit.git] / lib / dummy_array.nit
index 46297ea..9061e53 100644 (file)
@@ -1,22 +1,23 @@
 # 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;
-# without  even  the implied warranty of  MERCHANTABILITY or  FITNESS FOR A 
+# without  even  the implied warranty of  MERCHANTABILITY or  FITNESS FOR A
 # PARTICULAR PURPOSE.  You can modify it is you want,  provided this header
 # is kept unaltered, and a notification of the changes is added.
 # 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
-special Set[Int]
-special ArrayCapable[Int]
-       var _capacity: Int 
-       redef readable var _length: Int 
-       var _keys: NativeArray[Int]
-       var _values: NativeArray[Int]
+       super Set[Int]
+       private var capacity: Int
+       redef var length: Int
+       private var keys: NativeArray[Int]
+       private var values: NativeArray[Int]
 
        redef fun add(value: Int)
        do
@@ -76,18 +77,19 @@ special ArrayCapable[Int]
                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
-special Iterator[Int]
-       var _array: DummyArray
-       var _pos: Int
+       super Iterator[Int]
+       private var array: DummyArray
+       private var pos: Int
 
        redef fun item: Int
        do
@@ -102,8 +104,8 @@ special Iterator[Int]
 
        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