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]
16 private var capacity
: Int
18 private var keys
: NativeArray[Int]
19 private var values
: NativeArray[Int]
21 redef fun add
(value
: Int)
23 assert full
: _length
< (_capacity-1
)
30 redef fun remove
(value
: Int)
35 var last
= _values
[l
- 1]
36 var pos
= _keys
[value
]
43 redef fun has
(value
: Int): Bool
45 assert value
< _capacity
46 var pos
= _keys
[value
]
48 return _values
[pos
] == value
59 redef fun is_empty
: Bool
61 return not (_length
> 0)
69 redef fun iterator
: DummyIterator
71 return new DummyIterator(self)
74 private fun value_at
(pos
: Int): Int
82 _keys
= calloc_array
(capacity
)
83 _values
= calloc_array
(capacity
)
89 private var array
: DummyArray
95 return _array
.value_at
(_pos
)
100 return _pos
< _array
.length
103 redef fun next
do _pos
= _pos
+ 1 end
105 init(array
: DummyArray)