1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2008 Floréal Morandat <morandat@lirmm.fr>
5 # This file is free software, which comes along with NIT. This software is
6 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
8 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
9 # is kept unaltered, and a notification of the changes is added.
10 # You are allowed to redistribute it and sell it, alone or is a part of
15 super ArrayCapable[Int]
18 redef fun length
do return _length
19 var _keys
: NativeArray[Int]
20 var _values
: NativeArray[Int]
22 redef fun add
(value
: Int)
24 assert full
: _length
< (_capacity-1
)
31 redef fun remove
(value
: Int)
36 var last
= _values
[l
- 1]
37 var pos
= _keys
[value
]
44 redef fun has
(value
: Int): Bool
46 assert value
< _capacity
47 var pos
= _keys
[value
]
49 return _values
[pos
] == value
60 redef fun is_empty
: Bool
62 return not (_length
> 0)
70 redef fun iterator
: DummyIterator
72 return new DummyIterator(self)
75 private fun value_at
(pos
: Int): Int
83 _keys
= calloc_array
(capacity
)
84 _values
= calloc_array
(capacity
)
90 var _array
: DummyArray
96 return _array
.value_at
(_pos
)
101 return _pos
< _array
.length
104 redef fun next
do _pos
= _pos
+ 1 end
106 init(array
: DummyArray)