Skip to content

Commit 1758e00

Browse files
authored
Merge pull request scala#5697 from som-snytt/issue/10164
SI-10164 BitSet.tail zigs where it zagged
2 parents d5aad25 + 6c71379 commit 1758e00

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/library/scala/collection/BitSetLike.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,26 @@ trait BitSetLike[+This <: BitSetLike[This] with SortedSet[Int]] extends SortedSe
7777
def rangeImpl(from: Option[Int], until: Option[Int]): This = {
7878
val a = toBitMask
7979
val len = a.length
80-
if(from.isDefined) {
80+
if (from.isDefined) {
8181
var f = from.get
8282
var pos = 0
83-
while(f >= 64 && pos < len) {
83+
while (f >= 64 && pos < len) {
8484
f -= 64
8585
a(pos) = 0
8686
pos += 1
8787
}
88-
if(f > 0 && pos < len) a(pos) &= ~((1L << f)-1)
88+
if (f > 0 && pos < len) a(pos) &= ~((1L << f)-1)
8989
}
90-
if(until.isDefined) {
90+
if (until.isDefined) {
9191
val u = until.get
9292
val w = u / 64
9393
val b = u % 64
9494
var clearw = w+1
95-
while(clearw < len) {
95+
while (clearw < len) {
9696
a(clearw) = 0
9797
clearw += 1
9898
}
99-
if(w < len) a(w) &= (1L << b)-1
99+
if (w < len) a(w) &= (1L << b)-1
100100
}
101101
fromBitMaskNoCopy(a)
102102
}
@@ -220,7 +220,7 @@ trait BitSetLike[+This <: BitSetLike[This] with SortedSet[Int]] extends SortedSe
220220
while (i >= 0) {
221221
val wi = word(i)
222222
if (wi != 0L) return WordLength*i + 63 - java.lang.Long.numberOfLeadingZeros(wi)
223-
i += 1
223+
i -= 1
224224
}
225225
throw new NoSuchElementException("Empty BitSet")
226226
}
@@ -230,7 +230,7 @@ trait BitSetLike[+This <: BitSetLike[This] with SortedSet[Int]] extends SortedSe
230230
var pre = ""
231231
val max = nwords * WordLength
232232
var i = 0
233-
while(i != max) {
233+
while (i != max) {
234234
if (contains(i)) {
235235
sb append pre append i
236236
pre = sep

test/junit/scala/collection/mutable/BitSetTest.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.junit.runners.JUnit4
77
@RunWith(classOf[JUnit4])
88
class BitSetTest {
99
// Test for SI-8910
10-
@Test def capacityExpansionTest() {
10+
@Test def capacityExpansionTest(): Unit = {
1111
val bitSet = BitSet.empty
1212
val size = bitSet.toBitMask.length
1313
bitSet ^= bitSet
@@ -20,7 +20,7 @@ class BitSetTest {
2020
assert(bitSet.toBitMask.length == size, "Capacity of bitset changed after &~=")
2121
}
2222

23-
@Test def test_SI8917() {
23+
@Test def test_SI8917(): Unit = {
2424
val bigBitSet = BitSet(1, 100, 10000)
2525
val littleBitSet = BitSet(100)
2626
bigBitSet &= littleBitSet
@@ -29,10 +29,16 @@ class BitSetTest {
2929
assert(littleBitSet.toBitMask.length < bigBitSet.toBitMask.length, "Needlessly extended the size of bitset on &=")
3030
}
3131

32-
@Test def test_SI8647() {
32+
@Test def test_SI8647(): Unit = {
3333
val bs = BitSet()
3434
bs.map(_ + 1) // Just needs to compile
3535
val xs = bs: SortedSet[Int]
3636
xs.map(_ + 1) // Also should compile (did before)
3737
}
38+
39+
@Test def t10164(): Unit = {
40+
val bs = BitSet()
41+
val last = (bs ++ (0 to 128)).last // Just needs not to throw
42+
assert(last == 128)
43+
}
3844
}

0 commit comments

Comments
 (0)