@@ -22,86 +22,79 @@ final class BitArray private (
2222
2323 /** Reserves enough storage to store `n` elements in `this`. */
2424 def reserveCapacity (n : Int , assumeUniqueness : Boolean = false ): BitArray =
25- if ( n == 0 ) {
25+ if n == 0 then
2626 this
27- } else {
27+ else
2828 val k = 1 + ((n - 1 ) >> 5 )
29- if ( assumeUniqueness) {
29+ if assumeUniqueness then
3030 _bits = _bits.reserveCapacity(k, assumeUniqueness)
3131 this
32- } else {
32+ else
3333 new BitArray (_bits.reserveCapacity(k), _count)
34- }
35- }
3634
3735 /** Adds a new element at the end of the array. */
3836 def append (bit : Boolean , assumeUniqueness : Boolean = false ): BitArray =
3937 val result = if assumeUniqueness && (count < capacity) then this else copy(count + 1 )
4038 val p = BitArray .Position (count)
41- if ( p.bucket >= _bits.count) {
39+ if p.bucket >= _bits.count then
4240 result._bits = _bits.append(if bit then 1 else 0 )
43- } else {
41+ else
4442 result.setValue(bit, p)
45- }
4643 result._count += 1
4744 result
4845
4946 /** Removes and returns the last element, or returns `None` if the array is empty. */
5047 def popLast (assumeUniqueness : Boolean = false ): (BitArray , Option [Boolean ]) =
51- if ( isEmpty) {
48+ if isEmpty then
5249 (this , None )
53- } else {
50+ else
5451 val result = if assumeUniqueness then this else copy()
5552 val bit = result.at(BitArray .Position (count))
5653 result._count -= 1
5754 (result, Some (bit))
58- }
5955
6056 /** Removes all elements in the array, keeping allocated storage iff `keepStorage` is true. */
6157 def removeAll (
6258 keepStorage : Boolean = false ,
6359 assumeUniqueness : Boolean = false
6460 ): BitArray =
65- if ( isEmpty) {
61+ if isEmpty then
6662 this
67- } else if ( keepStorage) {
63+ else if keepStorage then
6864 val result = if assumeUniqueness then this else copy()
6965 result._bits.removeAll(keepStorage, assumeUniqueness = true )
7066 result._count = 0
7167 result
72- } else {
68+ else
7369 BitArray ()
74- }
7570
7671 /** Returns `true` iff all elements in `this` are `false`. */
7772 def allFalse : Boolean =
78- if ( isEmpty) {
73+ if isEmpty then
7974 true
80- } else {
75+ else
8176 val k = (count - 1 ) >> 5
8277 def loop (i : Int ): Boolean =
83- if ( i == k) {
78+ if i == k then
8479 val m = (1 << (count & 31 )) - 1
8580 (_bits.at(k) & m) == 0
86- } else if ( _bits.at(i) != 0 ) {
81+ else if _bits.at(i) != 0 then
8782 false
88- } else {
83+ else
8984 loop(i + 1 )
90- }
9185 loop(0 )
92- }
9386
9487 /** Returns `true` iff all elements in `this` are `true`. */
9588 def allTrue : Boolean =
96- if ( isEmpty) {
89+ if isEmpty then {
9790 true
9891 } else {
9992 val k = (count - 1 ) >> 5
10093 def loop (i : Int ): Boolean =
101- if ( i == k) {
94+ if i == k then {
10295 val m = (1 << (count & 31 )) - 1
10396 (_bits.at(k) & m) == m
104- } else if ( _bits.at(i) != ~ 0 ) {
97+ } else if _bits.at(i) != ~ 0 then {
10598 false
10699 } else {
107100 loop(i + 1 )
@@ -136,14 +129,14 @@ final class BitArray private (
136129 assumeUniqueness : Boolean = false
137130 ): BitArray =
138131 require(this .count == other.count)
139- if ( isEmpty) {
132+ if isEmpty then {
140133 this
141134 } else {
142135 val result = if assumeUniqueness then this else copy()
143136 var u = assumeUniqueness
144137 val k = (count - 1 ) >> 5
145138
146- for ( i <- 0 until k) {
139+ for i <- 0 until k do {
147140 result._bits = result._bits.modifyAt(
148141 i, (n) => operation(n, other._bits.at(n)),
149142 assumeUniqueness = u
@@ -184,7 +177,7 @@ final class BitArray private (
184177 * O(1).
185178 */
186179 def positionAfter (p : BitArray .Position ): BitArray .Position =
187- if ( p.offsetInBucket == 63 ) {
180+ if p.offsetInBucket == 63 then {
188181 BitArray .Position (p.bucket + 1 , 0 )
189182 } else {
190183 BitArray .Position (p.bucket, p.offsetInBucket + 1 )
@@ -244,7 +237,7 @@ final class BitArray private (
244237
245238 /** Returns an independent copy of `this`. */
246239 def copy (minimumCapacity : Int = 0 ): BitArray =
247- if ( minimumCapacity > capacity) {
240+ if minimumCapacity > capacity then {
248241 // If the requested capacity on the copy is greater than what we have, `reserveCapacity` will
249242 // create an independent value.
250243 reserveCapacity(minimumCapacity)
@@ -313,7 +306,7 @@ object BitArray {
313306 /** Creates an array with the given `bits`. */
314307 def apply [T ](bits : Boolean * ): BitArray =
315308 var result = new BitArray (HyArray [Int ](), 0 )
316- for ( b <- bits) result = result.append(b, assumeUniqueness = true )
309+ for b <- bits do result = result.append(b, assumeUniqueness = true )
317310 result
318311
319312}
0 commit comments