371 interface Iterator {
372 boolean hasNext();
373 int nextInt();
374 int previousInt();
375 void jump(final int fromElement);
376 }
377
378 private class KeyIteratorImpl implements Iterator {
379 Entry prev;
380
381 Entry next;
382
383 Entry curr;
384
385 int index = 0;
386
387 KeyIteratorImpl() {
388 next = firstEntry;
389 }
390
391 KeyIteratorImpl(final int k) {
392 if ((next = locateKey(k)) != null) {
393 if (next.key <= k) {
394 prev = next;
395 next = next.next();
396 }
397 else prev = next.prev();
398 }
399 }
400
401 private Entry locateKey(final int k) {
402 Entry e = root, last = root;
403 int cmp = 0;
404 while (e != null && (cmp = Integer.compare(k, e.key)) != 0) {
405 last = e;
406 e = cmp < 0 ? e.left() : e.right();
407 }
408 return cmp == 0 ? e : last;
409 }
410
|
371 interface Iterator {
372 boolean hasNext();
373 int nextInt();
374 int previousInt();
375 void jump(final int fromElement);
376 }
377
378 private class KeyIteratorImpl implements Iterator {
379 Entry prev;
380
381 Entry next;
382
383 Entry curr;
384
385 int index = 0;
386
387 KeyIteratorImpl() {
388 next = firstEntry;
389 }
390
391 @SuppressWarnings("initialization")
392 KeyIteratorImpl(final int k) {
393 if ((next = locateKey(k)) != null) {
394 if (next.key <= k) {
395 prev = next;
396 next = next.next();
397 }
398 else prev = next.prev();
399 }
400 }
401
402 private Entry locateKey(final int k) {
403 Entry e = root, last = root;
404 int cmp = 0;
405 while (e != null && (cmp = Integer.compare(k, e.key)) != 0) {
406 last = e;
407 e = cmp < 0 ? e.left() : e.right();
408 }
409 return cmp == 0 ? e : last;
410 }
411
|