3594 |
|
* remaining number of elements of a skip list when advancing |
3595 |
|
* either across or down decreases by about 25%. To make this |
3596 |
|
* observation useful, we need to know initial size, which we |
3597 |
< |
* don't. But we use (1 << 2*levels) as a rough overestimate that |
3598 |
< |
* minimizes risk of prematurely zeroing out while splitting. |
3597 |
> |
* don't. But we can just use Integer.MAX_VALUE so that we |
3598 |
> |
* don't prematurely zero out while splitting. |
3599 |
|
*/ |
3600 |
|
static class CSLMSpliterator<K,V> { |
3601 |
|
final Comparator<? super K> comparator; |
3605 |
|
int est; // pseudo-size estimate |
3606 |
|
|
3607 |
|
CSLMSpliterator(ConcurrentSkipListMap<K,V> m) { |
3608 |
– |
HeadIndex<K,V> h; Node<K,V> p; int d, n; Index<K,V> hd; |
3608 |
|
this.comparator = m.comparator; |
3609 |
|
this.fence = null; |
3610 |
< |
for (;;) { // ensure h and n correspond to origin p |
3610 |
> |
for (;;) { // ensure h corresponds to origin p |
3611 |
> |
HeadIndex<K,V> h; Node<K,V> p; |
3612 |
|
Node<K,V> b = (h = m.head).node; |
3613 |
< |
if ((p = b.next) == null) { |
3614 |
< |
n = 0; |
3615 |
< |
break; |
3616 |
< |
} |
3617 |
< |
if (p.value != null) { |
3618 |
< |
n = (d = h.level << 1) >= 31 ? Integer.MAX_VALUE : 1 << d; |
3613 |
> |
if ((p = b.next) == null || p.value != null) { |
3614 |
> |
this.est = ((p == null) ? 0 : |
3615 |
> |
(p.next == null) ? 1 : Integer.MAX_VALUE); |
3616 |
> |
this.current = p; |
3617 |
> |
this.row = h; |
3618 |
|
break; |
3619 |
|
} |
3620 |
|
p.helpDelete(b, p.next); |
3621 |
|
} |
3623 |
– |
this.est = n; |
3624 |
– |
this.current = p; |
3625 |
– |
this.row = (h.right == null && (hd = h.down) != null) ? hd : h; |
3622 |
|
} |
3623 |
|
|
3624 |
|
CSLMSpliterator(Comparator<? super K> comparator, Index<K,V> row, |
3665 |
|
} |
3666 |
|
|
3667 |
|
@SuppressWarnings("unchecked") |
3668 |
< |
public KeySpliterator<K,V> trySplit() { |
3668 |
> |
public Spliterator<K> trySplit() { |
3669 |
|
Node<K,V> e; |
3670 |
|
Comparator<? super K> cmp = comparator; |
3671 |
|
K f = fence; |
3754 |
|
} |
3755 |
|
|
3756 |
|
@SuppressWarnings("unchecked") |
3757 |
< |
public ValueSpliterator<K,V> trySplit() { |
3757 |
> |
public Spliterator<V> trySplit() { |
3758 |
|
Node<K,V> e; |
3759 |
|
Comparator<? super K> cmp = comparator; |
3760 |
|
K f = fence; |
3841 |
|
} |
3842 |
|
|
3843 |
|
@SuppressWarnings("unchecked") |
3844 |
< |
public EntrySpliterator<K,V> trySplit() { |
3844 |
> |
public Spliterator<Map.Entry<K,V>> trySplit() { |
3845 |
|
Node<K,V> e; |
3846 |
|
Comparator<? super K> cmp = comparator; |
3847 |
|
K f = fence; |