Skip to content

Commit 2674205

Browse files
committed
Pulled out more steppers.
This time: BitSet, FlatHashTable, HashTable, and immutable sets and maps (trie-based).
1 parent 66756d1 commit 2674205

File tree

6 files changed

+372
-307
lines changed

6 files changed

+372
-307
lines changed

src/main/scala/scala/compat/java8/StepConverters.scala

Lines changed: 0 additions & 307 deletions
Original file line numberDiff line numberDiff line change
@@ -32,313 +32,6 @@ package converterImpls {
3232
def nextLong() = if (proxied ne null) proxied.nextStep else underlying.next
3333
}
3434

35-
private[java8] class StepsAnyFlatHashTable[A](_underlying: Array[AnyRef], _i0: Int, _iN: Int)
36-
extends StepsLikeGapped[A, StepsAnyFlatHashTable[A]](_underlying, _i0, _iN) {
37-
def next() = if (currentEntry eq null) throwNSEE else { val ans = currentEntry.asInstanceOf[A]; currentEntry = null; ans }
38-
def semiclone(half: Int) = new StepsAnyFlatHashTable[A](underlying, i0, half)
39-
}
40-
41-
private[java8] class StepsDoubleFlatHashTable(_underlying: Array[AnyRef], _i0: Int, _iN: Int)
42-
extends StepsDoubleLikeGapped[StepsDoubleFlatHashTable](_underlying, _i0, _iN) {
43-
def nextDouble() = if (currentEntry eq null) throwNSEE else { val ans = currentEntry.asInstanceOf[Double]; currentEntry = null; ans }
44-
def semiclone(half: Int) = new StepsDoubleFlatHashTable(underlying, i0, half)
45-
}
46-
47-
private[java8] class StepsIntFlatHashTable(_underlying: Array[AnyRef], _i0: Int, _iN: Int)
48-
extends StepsIntLikeGapped[StepsIntFlatHashTable](_underlying, _i0, _iN) {
49-
def nextInt() = if (currentEntry eq null) throwNSEE else { val ans = currentEntry.asInstanceOf[Int]; currentEntry = null; ans }
50-
def semiclone(half: Int) = new StepsIntFlatHashTable(underlying, i0, half)
51-
}
52-
53-
private[java8] class StepsLongFlatHashTable(_underlying: Array[AnyRef], _i0: Int, _iN: Int)
54-
extends StepsLongLikeGapped[StepsLongFlatHashTable](_underlying, _i0, _iN) {
55-
def nextLong() = if (currentEntry eq null) throwNSEE else { val ans = currentEntry.asInstanceOf[Long]; currentEntry = null; ans }
56-
def semiclone(half: Int) = new StepsLongFlatHashTable(underlying, i0, half)
57-
}
58-
59-
private[java8] class StepsAnyHashTableKey[K, HE <: collection.mutable.HashEntry[K, HE]](_underlying: Array[collection.mutable.HashEntry[K, HE]], _i0: Int, _iN: Int)
60-
extends StepsLikeGapped[K, StepsAnyHashTableKey[K, HE]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
61-
def next() = if (currentEntry eq null) throwNSEE else { val ans = currentEntry.asInstanceOf[HE].key; currentEntry = currentEntry.asInstanceOf[HE].next; ans }
62-
def semiclone(half: Int) = new StepsAnyHashTableKey[K, HE](underlying.asInstanceOf[Array[collection.mutable.HashEntry[K, HE]]], i0, half)
63-
}
64-
65-
private[java8] class StepsDoubleHashTableKey[HE <: collection.mutable.HashEntry[Double, HE]](_underlying: Array[collection.mutable.HashEntry[Double, HE]], _i0: Int, _iN: Int)
66-
extends StepsDoubleLikeGapped[StepsDoubleHashTableKey[HE]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
67-
def nextDouble() = if (currentEntry eq null) throwNSEE else { val ans = currentEntry.asInstanceOf[HE].key; currentEntry = currentEntry.asInstanceOf[HE].next; ans }
68-
def semiclone(half: Int) = new StepsDoubleHashTableKey[HE](underlying.asInstanceOf[Array[collection.mutable.HashEntry[Double, HE]]], i0, half)
69-
}
70-
71-
private[java8] class StepsIntHashTableKey[HE <: collection.mutable.HashEntry[Int, HE]](_underlying: Array[collection.mutable.HashEntry[Int, HE]], _i0: Int, _iN: Int)
72-
extends StepsIntLikeGapped[StepsIntHashTableKey[HE]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
73-
def nextInt() = if (currentEntry eq null) throwNSEE else { val ans = currentEntry.asInstanceOf[HE].key; currentEntry = currentEntry.asInstanceOf[HE].next; ans }
74-
def semiclone(half: Int) = new StepsIntHashTableKey[HE](underlying.asInstanceOf[Array[collection.mutable.HashEntry[Int, HE]]], i0, half)
75-
}
76-
77-
private[java8] class StepsLongHashTableKey[HE <: collection.mutable.HashEntry[Long, HE]](_underlying: Array[collection.mutable.HashEntry[Long, HE]], _i0: Int, _iN: Int)
78-
extends StepsLongLikeGapped[StepsLongHashTableKey[HE]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
79-
def nextLong() = if (currentEntry eq null) throwNSEE else { val ans = currentEntry.asInstanceOf[HE].key; currentEntry = currentEntry.asInstanceOf[HE].next; ans }
80-
def semiclone(half: Int) = new StepsLongHashTableKey[HE](underlying.asInstanceOf[Array[collection.mutable.HashEntry[Long, HE]]], i0, half)
81-
}
82-
83-
private[java8] class StepsAnyDefaultHashTable[K, V](_underlying: Array[collection.mutable.HashEntry[K, collection.mutable.DefaultEntry[K, V]]], _i0: Int, _iN: Int)
84-
extends StepsLikeGapped[(K, V), StepsAnyDefaultHashTable[K, V]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
85-
def next() =
86-
if (currentEntry eq null) throwNSEE
87-
else { val de = currentEntry.asInstanceOf[collection.mutable.DefaultEntry[K, V]]; currentEntry = de.next; (de.key, de.value) }
88-
def semiclone(half: Int) =
89-
new StepsAnyDefaultHashTable[K, V](underlying.asInstanceOf[Array[collection.mutable.HashEntry[K, collection.mutable.DefaultEntry[K, V]]]], i0, half)
90-
}
91-
92-
private[java8] class StepsAnyDefaultHashTableValue[K, V](_underlying: Array[collection.mutable.HashEntry[K, collection.mutable.DefaultEntry[K, V]]], _i0: Int, _iN: Int)
93-
extends StepsLikeGapped[V, StepsAnyDefaultHashTableValue[K, V]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
94-
def next() =
95-
if (currentEntry eq null) throwNSEE
96-
else { val de = currentEntry.asInstanceOf[collection.mutable.DefaultEntry[K, V]]; currentEntry = de.next; de.value }
97-
def semiclone(half: Int) =
98-
new StepsAnyDefaultHashTableValue[K, V](underlying.asInstanceOf[Array[collection.mutable.HashEntry[K, collection.mutable.DefaultEntry[K, V]]]], i0, half)
99-
}
100-
101-
private[java8] class StepsDoubleDefaultHashTableValue[K](_underlying: Array[collection.mutable.HashEntry[K, collection.mutable.DefaultEntry[K, Double]]], _i0: Int, _iN: Int)
102-
extends StepsDoubleLikeGapped[StepsDoubleDefaultHashTableValue[K]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
103-
def nextDouble() =
104-
if (currentEntry eq null) throwNSEE
105-
else { val de = currentEntry.asInstanceOf[collection.mutable.DefaultEntry[K, Double]]; currentEntry = de.next; de.value }
106-
def semiclone(half: Int) =
107-
new StepsDoubleDefaultHashTableValue[K](underlying.asInstanceOf[Array[collection.mutable.HashEntry[K, collection.mutable.DefaultEntry[K, Double]]]], i0, half)
108-
}
109-
110-
private[java8] class StepsIntDefaultHashTableValue[K](_underlying: Array[collection.mutable.HashEntry[K, collection.mutable.DefaultEntry[K, Int]]], _i0: Int, _iN: Int)
111-
extends StepsIntLikeGapped[StepsIntDefaultHashTableValue[K]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
112-
def nextInt() =
113-
if (currentEntry eq null) throwNSEE
114-
else { val de = currentEntry.asInstanceOf[collection.mutable.DefaultEntry[K, Int]]; currentEntry = de.next; de.value }
115-
def semiclone(half: Int) =
116-
new StepsIntDefaultHashTableValue[K](underlying.asInstanceOf[Array[collection.mutable.HashEntry[K, collection.mutable.DefaultEntry[K, Int]]]], i0, half)
117-
}
118-
119-
private[java8] class StepsLongDefaultHashTableValue[K](_underlying: Array[collection.mutable.HashEntry[K, collection.mutable.DefaultEntry[K, Long]]], _i0: Int, _iN: Int)
120-
extends StepsLongLikeGapped[StepsLongDefaultHashTableValue[K]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
121-
def nextLong() =
122-
if (currentEntry eq null) throwNSEE
123-
else { val de = currentEntry.asInstanceOf[collection.mutable.DefaultEntry[K, Long]]; currentEntry = de.next; de.value }
124-
def semiclone(half: Int) =
125-
new StepsLongDefaultHashTableValue[K](underlying.asInstanceOf[Array[collection.mutable.HashEntry[K, collection.mutable.DefaultEntry[K, Long]]]], i0, half)
126-
}
127-
128-
private[java8] class StepsAnyLinkedHashTable[K, V](_underlying: Array[collection.mutable.HashEntry[K, collection.mutable.LinkedEntry[K, V]]], _i0: Int, _iN: Int)
129-
extends StepsLikeGapped[(K, V), StepsAnyLinkedHashTable[K, V]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
130-
def next() =
131-
if (currentEntry eq null) throwNSEE
132-
else { val de = currentEntry.asInstanceOf[collection.mutable.LinkedEntry[K, V]]; currentEntry = de.next; (de.key, de.value) }
133-
def semiclone(half: Int) =
134-
new StepsAnyLinkedHashTable[K, V](underlying.asInstanceOf[Array[collection.mutable.HashEntry[K, collection.mutable.LinkedEntry[K, V]]]], i0, half)
135-
}
136-
137-
private[java8] class StepsAnyLinkedHashTableValue[K, V](_underlying: Array[collection.mutable.HashEntry[K, collection.mutable.LinkedEntry[K, V]]], _i0: Int, _iN: Int)
138-
extends StepsLikeGapped[V, StepsAnyLinkedHashTableValue[K, V]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
139-
def next() =
140-
if (currentEntry eq null) throwNSEE
141-
else { val de = currentEntry.asInstanceOf[collection.mutable.LinkedEntry[K, V]]; currentEntry = de.next; de.value }
142-
def semiclone(half: Int) =
143-
new StepsAnyLinkedHashTableValue[K, V](underlying.asInstanceOf[Array[collection.mutable.HashEntry[K, collection.mutable.LinkedEntry[K, V]]]], i0, half)
144-
}
145-
146-
private[java8] class StepsDoubleLinkedHashTableValue[K](_underlying: Array[collection.mutable.HashEntry[K, collection.mutable.LinkedEntry[K, Double]]], _i0: Int, _iN: Int)
147-
extends StepsDoubleLikeGapped[StepsDoubleLinkedHashTableValue[K]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
148-
def nextDouble() =
149-
if (currentEntry eq null) throwNSEE
150-
else { val de = currentEntry.asInstanceOf[collection.mutable.LinkedEntry[K, Double]]; currentEntry = de.next; de.value }
151-
def semiclone(half: Int) =
152-
new StepsDoubleLinkedHashTableValue[K](underlying.asInstanceOf[Array[collection.mutable.HashEntry[K, collection.mutable.LinkedEntry[K, Double]]]], i0, half)
153-
}
154-
155-
private[java8] class StepsIntLinkedHashTableValue[K](_underlying: Array[collection.mutable.HashEntry[K, collection.mutable.LinkedEntry[K, Int]]], _i0: Int, _iN: Int)
156-
extends StepsIntLikeGapped[StepsIntLinkedHashTableValue[K]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
157-
def nextInt() =
158-
if (currentEntry eq null) throwNSEE
159-
else { val de = currentEntry.asInstanceOf[collection.mutable.LinkedEntry[K, Int]]; currentEntry = de.next; de.value }
160-
def semiclone(half: Int) =
161-
new StepsIntLinkedHashTableValue[K](underlying.asInstanceOf[Array[collection.mutable.HashEntry[K, collection.mutable.LinkedEntry[K, Int]]]], i0, half)
162-
}
163-
164-
private[java8] class StepsLongLinkedHashTableValue[K](_underlying: Array[collection.mutable.HashEntry[K, collection.mutable.LinkedEntry[K, Long]]], _i0: Int, _iN: Int)
165-
extends StepsLongLikeGapped[StepsLongLinkedHashTableValue[K]](_underlying.asInstanceOf[Array[AnyRef]], _i0, _iN) {
166-
def nextLong() =
167-
if (currentEntry eq null) throwNSEE
168-
else { val de = currentEntry.asInstanceOf[collection.mutable.LinkedEntry[K, Long]]; currentEntry = de.next; de.value }
169-
def semiclone(half: Int) =
170-
new StepsLongLinkedHashTableValue[K](underlying.asInstanceOf[Array[collection.mutable.HashEntry[K, collection.mutable.LinkedEntry[K, Long]]]], i0, half)
171-
}
172-
173-
private[java8] class StepsAnyImmHashMap[K, V](_underlying: collection.immutable.HashMap[K, V], _i0: Int, _iN: Int)
174-
extends StepsLikeImmHashMap[K, V, (K, V), StepsAnyImmHashMap[K, V]](_underlying, _i0, _iN) {
175-
protected def demiclone(u: collection.immutable.HashMap[K,V], j0: Int, jN: Int) = new StepsAnyImmHashMap[K, V](u, j0, jN)
176-
def next(): (K, V) =
177-
if (hasNext) {
178-
if (theIterator eq null) theIterator = underlying.iterator
179-
i += 1
180-
theIterator.next
181-
}
182-
else throwNSEE
183-
}
184-
185-
private[java8] class StepsAnyImmHashMapKey[K, V](_underlying: collection.immutable.HashMap[K, V], _i0: Int, _iN: Int)
186-
extends StepsLikeImmHashMap[K, V, K, StepsAnyImmHashMapKey[K, V]](_underlying, _i0, _iN) {
187-
protected def demiclone(u: collection.immutable.HashMap[K,V], j0: Int, jN: Int) = new StepsAnyImmHashMapKey[K, V](u, j0, jN)
188-
def next(): K =
189-
if (hasNext) {
190-
if (theIterator eq null) theIterator = underlying.keysIterator
191-
i += 1
192-
theIterator.next
193-
}
194-
else throwNSEE
195-
}
196-
197-
private[java8] class StepsAnyImmHashMapValue[K, V](_underlying: collection.immutable.HashMap[K, V], _i0: Int, _iN: Int)
198-
extends StepsLikeImmHashMap[K, V, V, StepsAnyImmHashMapValue[K, V]](_underlying, _i0, _iN) {
199-
protected def demiclone(u: collection.immutable.HashMap[K,V], j0: Int, jN: Int) = new StepsAnyImmHashMapValue[K, V](u, j0, jN)
200-
def next(): V =
201-
if (hasNext) {
202-
if (theIterator eq null) theIterator = underlying.valuesIterator
203-
i += 1
204-
theIterator.next
205-
}
206-
else throwNSEE
207-
}
208-
209-
private[java8] class StepsDoubleImmHashMapKey[V](_underlying: collection.immutable.HashMap[Double, V], _i0: Int, _iN: Int)
210-
extends StepsDoubleLikeImmHashMap[Double, V, StepsDoubleImmHashMapKey[V]](_underlying, _i0, _iN) {
211-
protected def demiclone(u: collection.immutable.HashMap[Double,V], j0: Int, jN: Int) = new StepsDoubleImmHashMapKey[V](u, j0, jN)
212-
def nextDouble() =
213-
if (hasNext) {
214-
if (theIterator eq null) theIterator = underlying.keysIterator
215-
i += 1
216-
theIterator.next
217-
}
218-
else throwNSEE
219-
}
220-
221-
private[java8] class StepsDoubleImmHashMapValue[K](_underlying: collection.immutable.HashMap[K, Double], _i0: Int, _iN: Int)
222-
extends StepsDoubleLikeImmHashMap[K, Double, StepsDoubleImmHashMapValue[K]](_underlying, _i0, _iN) {
223-
protected def demiclone(u: collection.immutable.HashMap[K,Double], j0: Int, jN: Int) = new StepsDoubleImmHashMapValue[K](u, j0, jN)
224-
def nextDouble() =
225-
if (hasNext) {
226-
if (theIterator eq null) theIterator = underlying.valuesIterator
227-
i += 1
228-
theIterator.next
229-
}
230-
else throwNSEE
231-
}
232-
233-
private[java8] class StepsIntImmHashMapKey[V](_underlying: collection.immutable.HashMap[Int, V], _i0: Int, _iN: Int)
234-
extends StepsIntLikeImmHashMap[Int, V, StepsIntImmHashMapKey[V]](_underlying, _i0, _iN) {
235-
protected def demiclone(u: collection.immutable.HashMap[Int,V], j0: Int, jN: Int) = new StepsIntImmHashMapKey[V](u, j0, jN)
236-
def nextInt() =
237-
if (hasNext) {
238-
if (theIterator eq null) theIterator = underlying.keysIterator
239-
i += 1
240-
theIterator.next
241-
}
242-
else throwNSEE
243-
}
244-
245-
private[java8] class StepsIntImmHashMapValue[K](_underlying: collection.immutable.HashMap[K, Int], _i0: Int, _iN: Int)
246-
extends StepsIntLikeImmHashMap[K, Int, StepsIntImmHashMapValue[K]](_underlying, _i0, _iN) {
247-
protected def demiclone(u: collection.immutable.HashMap[K,Int], j0: Int, jN: Int) = new StepsIntImmHashMapValue[K](u, j0, jN)
248-
def nextInt() =
249-
if (hasNext) {
250-
if (theIterator eq null) theIterator = underlying.valuesIterator
251-
i += 1
252-
theIterator.next
253-
}
254-
else throwNSEE
255-
}
256-
257-
private[java8] class StepsLongImmHashMapKey[V](_underlying: collection.immutable.HashMap[Long, V], _i0: Int, _iN: Int)
258-
extends StepsLongLikeImmHashMap[Long, V, StepsLongImmHashMapKey[V]](_underlying, _i0, _iN) {
259-
protected def demiclone(u: collection.immutable.HashMap[Long,V], j0: Int, jN: Int) = new StepsLongImmHashMapKey[V](u, j0, jN)
260-
def nextLong() =
261-
if (hasNext) {
262-
if (theIterator eq null) theIterator = underlying.keysIterator
263-
i += 1
264-
theIterator.next
265-
}
266-
else throwNSEE
267-
}
268-
269-
private[java8] class StepsLongImmHashMapValue[K](_underlying: collection.immutable.HashMap[K, Long], _i0: Int, _iN: Int)
270-
extends StepsLongLikeImmHashMap[K, Long, StepsLongImmHashMapValue[K]](_underlying, _i0, _iN) {
271-
protected def demiclone(u: collection.immutable.HashMap[K,Long], j0: Int, jN: Int) = new StepsLongImmHashMapValue[K](u, j0, jN)
272-
def nextLong() =
273-
if (hasNext) {
274-
if (theIterator eq null) theIterator = underlying.valuesIterator
275-
i += 1
276-
theIterator.next
277-
}
278-
else throwNSEE
279-
}
280-
281-
private[java8] class StepsAnyImmHashSet[A](_underlying: Iterator[A], _N: Int)
282-
extends StepsLikeTrieIterator[A, StepsAnyImmHashSet[A]](_underlying, _N) {
283-
protected def demiclone(it: Iterator[A], N: Int) = new StepsAnyImmHashSet(it, N)
284-
def next(): A = { val ans = underlying.next; i += 1; ans }
285-
}
286-
287-
private[java8] class StepsDoubleImmHashSet(_underlying: Iterator[Double], _N: Int)
288-
extends StepsDoubleLikeTrieIterator[StepsDoubleImmHashSet](_underlying, _N) {
289-
protected def demiclone(it: Iterator[Double], N: Int) = new StepsDoubleImmHashSet(it, N)
290-
def nextDouble() = { val ans = underlying.next; i += 1; ans }
291-
}
292-
293-
private[java8] class StepsIntImmHashSet(_underlying: Iterator[Int], _N: Int)
294-
extends StepsIntLikeTrieIterator[StepsIntImmHashSet](_underlying, _N) {
295-
protected def demiclone(it: Iterator[Int], N: Int) = new StepsIntImmHashSet(it, N)
296-
def nextInt() = { val ans = underlying.next; i += 1; ans }
297-
}
298-
299-
private[java8] class StepsLongImmHashSet(_underlying: Iterator[Long], _N: Int)
300-
extends StepsLongLikeTrieIterator[StepsLongImmHashSet](_underlying, _N) {
301-
protected def demiclone(it: Iterator[Long], N: Int) = new StepsLongImmHashSet(it, N)
302-
def nextLong() = { val ans = underlying.next; i += 1; ans }
303-
}
304-
305-
private[java8] class StepsIntBitSet(_underlying: Array[Long], _i0: Int, _iN: Int)
306-
extends StepsIntLikeSliced[Array[Long], StepsIntBitSet](_underlying, _i0, _iN) {
307-
private var mask: Long = (-1L) << (i & 0x3F)
308-
private var cache: Long = underlying(i >>> 6)
309-
private var found: Boolean = false
310-
def semiclone(half: Int) = {
311-
val ans = new StepsIntBitSet(underlying, i, half)
312-
i = half
313-
mask = (-1L) << (i & 0x3F)
314-
cache = underlying(i >>> 6)
315-
found = false
316-
ans
317-
}
318-
def hasNext(): Boolean = found || ((i < iN) && {
319-
while ((mask & cache) == 0) {
320-
i += java.lang.Long.numberOfLeadingZeros(~mask)
321-
if (i < 0 || i >= iN) { i = iN; return false }
322-
mask = -1L
323-
cache = underlying(i >>> 6)
324-
}
325-
var m = mask << 1
326-
while ((mask & cache) == (m & cache)) {
327-
mask = m
328-
m = mask << 1
329-
i += 1
330-
}
331-
if (i < 0 || i >= iN) {
332-
i = iN
333-
false
334-
}
335-
else {
336-
found = true
337-
true
338-
}
339-
})
340-
def nextInt() = if (hasNext) { val j = i; found = false; mask = mask << 1; i += 1; j } else throwNSEE
341-
}
34235

34336
final class RichArrayAnyCanStep[A](private val underlying: Array[A]) extends AnyVal with MakesAnyStepper[A] {
34437
@inline def stepper: AnyStepper[A] with EfficientSubstep = new StepsAnyArray[A](underlying, 0, underlying.length)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package scala.compat.java8.converterImpls
2+
3+
import language.implicitConversions
4+
5+
import scala.compat.java8.collectionImpl._
6+
import scala.compat.java8.runtime._
7+
8+
import Stepper._
9+
10+
private[java8] class StepsIntBitSet(_underlying: Array[Long], _i0: Int, _iN: Int)
11+
extends StepsIntLikeSliced[Array[Long], StepsIntBitSet](_underlying, _i0, _iN) {
12+
private var mask: Long = (-1L) << (i & 0x3F)
13+
private var cache: Long = underlying(i >>> 6)
14+
private var found: Boolean = false
15+
def semiclone(half: Int) = {
16+
val ans = new StepsIntBitSet(underlying, i, half)
17+
i = half
18+
mask = (-1L) << (i & 0x3F)
19+
cache = underlying(i >>> 6)
20+
found = false
21+
ans
22+
}
23+
def hasNext(): Boolean = found || ((i < iN) && {
24+
while ((mask & cache) == 0) {
25+
i += java.lang.Long.numberOfLeadingZeros(~mask)
26+
if (i < 0 || i >= iN) { i = iN; return false }
27+
mask = -1L
28+
cache = underlying(i >>> 6)
29+
}
30+
var m = mask << 1
31+
while ((mask & cache) == (m & cache)) {
32+
mask = m
33+
m = mask << 1
34+
i += 1
35+
}
36+
if (i < 0 || i >= iN) {
37+
i = iN
38+
false
39+
}
40+
else {
41+
found = true
42+
true
43+
}
44+
})
45+
def nextInt() = if (hasNext) { val j = i; found = false; mask = mask << 1; i += 1; j } else throwNSEE
46+
}
47+

0 commit comments

Comments
 (0)