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
)
34 if not value
isa Int then return
37 var last
= _values
[l
- 1]
38 var pos
= _keys
[value
]
47 if not value
isa Int then return false
48 assert value
< _capacity
49 var pos
= _keys
[value
]
51 return _values
[pos
] == value
62 redef fun is_empty
: Bool
64 return not (_length
> 0)
72 redef fun iterator
: DummyIterator
74 return new DummyIterator(self)
77 private fun value_at
(pos
: Int): Int
82 # initialize a new DummyArray with `capacity`.
83 init(capacity
: Int) is old_style_init
do
85 _keys
= new NativeArray[Int](capacity
)
86 _values
= new NativeArray[Int](capacity
)
90 # An iterator over a `DummyArray`.
93 private var array
: DummyArray
99 return _array
.value_at
(_pos
)
102 redef fun is_ok
: Bool
104 return _pos
< _array
.length
107 redef fun next
do _pos
= _pos
+ 1 end
109 # Initialize an iterator for `array`.
110 init(array
: DummyArray) is old_style_init
do