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 private var capacity
: Int
17 private var keys
: NativeArray[Int]
18 private var values
: NativeArray[Int]
20 redef fun add
(value
: Int)
22 assert full
: _length
< (_capacity-1
)
29 redef fun remove
(value
: Int)
34 var last
= _values
[l
- 1]
35 var pos
= _keys
[value
]
42 redef fun has
(value
: Int): Bool
44 assert value
< _capacity
45 var pos
= _keys
[value
]
47 return _values
[pos
] == value
58 redef fun is_empty
: Bool
60 return not (_length
> 0)
68 redef fun iterator
: DummyIterator
70 return new DummyIterator(self)
73 private fun value_at
(pos
: Int): Int
81 _keys
= new NativeArray[Int](capacity
)
82 _values
= new NativeArray[Int](capacity
)
88 private var array
: DummyArray
94 return _array
.value_at
(_pos
)
99 return _pos
< _array
.length
102 redef fun next
do _pos
= _pos
+ 1 end
104 init(array
: DummyArray)