MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / iterator

Method iterator

JSAT/src/jsat/utils/IntSet.java:247–290  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

245
246
247 @Override
248 public Iterator<Integer> iterator()
249 {
250 final IntSet parentRef = this;
251
252 //find the first starting inded
253 int START = 0;
254 while (START < status.length && status[START] != OCCUPIED)
255 START++;
256 if (START == status.length)
257 return Collections.emptyIterator();
258 final int startPos = START;
259
260 return new Iterator<Integer>()
261 {
262 int pos = startPos;
263 int prevPos = -1;
264
265 @Override
266 public boolean hasNext()
267 {
268 return pos < status.length;
269 }
270
271 @Override
272 public Integer next()
273 {
274 //final int make so that object remains good after we call next again
275 final int oldPos = prevPos = pos++;
276 //find next
277 while (pos < status.length && status[pos] != OCCUPIED)
278 pos++;
279 //and return new object
280 return keys[oldPos];
281 }
282
283 @Override
284 public void remove()
285 {
286 //its ok to just call remove b/c nothing is re-ordered when we remove an element, we just set the status to DELETED
287 parentRef.remove(keys[prevPos]);
288 }
289 };
290 }
291
292 @Override
293 public int size()

Callers 2

testIteratorMethod · 0.95
xiSteepClusterExtractMethod · 0.95

Calls

no outgoing calls

Tested by 1

testIteratorMethod · 0.76