1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2008 Floréal Morandat <morandat@lirmm.fr>
4 # Copyright 2014 Alexandre Terrasa <alexandre@moz-code.org>
6 # This file is free software, which comes along with NIT. This software is
7 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
9 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
10 # is kept unaltered, and a notification of the changes is added.
11 # You are allowed to redistribute it and sell it, alone or is a part of
14 # A `Set` that contains only integers.
17 private var capacity
: Int
19 private var keys
: NativeArray[Int]
20 private 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
80 # initialize a new DummyArray with `capacity`.
81 init(capacity
: Int) is old_style_init
do
83 _keys
= new NativeArray[Int](capacity
)
84 _values
= new NativeArray[Int](capacity
)
88 # An iterator over a `DummyArray`.
91 private var array
: DummyArray
97 return _array
.value_at
(_pos
)
100 redef fun is_ok
: Bool
102 return _pos
< _array
.length
105 redef fun next
do _pos
= _pos
+ 1 end
107 # Initialize an iterator for `array`.
108 init(array
: DummyArray) is old_style_init
do