@@ -22,86 +22,79 @@ final class BitArray private (
22
22
23
23
/** Reserves enough storage to store `n` elements in `this`. */
24
24
def reserveCapacity (n : Int , assumeUniqueness : Boolean = false ): BitArray =
25
- if ( n == 0 ) {
25
+ if n == 0 then
26
26
this
27
- } else {
27
+ else
28
28
val k = 1 + ((n - 1 ) >> 5 )
29
- if ( assumeUniqueness) {
29
+ if assumeUniqueness then
30
30
_bits = _bits.reserveCapacity(k, assumeUniqueness)
31
31
this
32
- } else {
32
+ else
33
33
new BitArray (_bits.reserveCapacity(k), _count)
34
- }
35
- }
36
34
37
35
/** Adds a new element at the end of the array. */
38
36
def append (bit : Boolean , assumeUniqueness : Boolean = false ): BitArray =
39
37
val result = if assumeUniqueness && (count < capacity) then this else copy(count + 1 )
40
38
val p = BitArray .Position (count)
41
- if ( p.bucket >= _bits.count) {
39
+ if p.bucket >= _bits.count then
42
40
result._bits = _bits.append(if bit then 1 else 0 )
43
- } else {
41
+ else
44
42
result.setValue(bit, p)
45
- }
46
43
result._count += 1
47
44
result
48
45
49
46
/** Removes and returns the last element, or returns `None` if the array is empty. */
50
47
def popLast (assumeUniqueness : Boolean = false ): (BitArray , Option [Boolean ]) =
51
- if ( isEmpty) {
48
+ if isEmpty then
52
49
(this , None )
53
- } else {
50
+ else
54
51
val result = if assumeUniqueness then this else copy()
55
52
val bit = result.at(BitArray .Position (count))
56
53
result._count -= 1
57
54
(result, Some (bit))
58
- }
59
55
60
56
/** Removes all elements in the array, keeping allocated storage iff `keepStorage` is true. */
61
57
def removeAll (
62
58
keepStorage : Boolean = false ,
63
59
assumeUniqueness : Boolean = false
64
60
): BitArray =
65
- if ( isEmpty) {
61
+ if isEmpty then
66
62
this
67
- } else if ( keepStorage) {
63
+ else if keepStorage then
68
64
val result = if assumeUniqueness then this else copy()
69
65
result._bits.removeAll(keepStorage, assumeUniqueness = true )
70
66
result._count = 0
71
67
result
72
- } else {
68
+ else
73
69
BitArray ()
74
- }
75
70
76
71
/** Returns `true` iff all elements in `this` are `false`. */
77
72
def allFalse : Boolean =
78
- if ( isEmpty) {
73
+ if isEmpty then
79
74
true
80
- } else {
75
+ else
81
76
val k = (count - 1 ) >> 5
82
77
def loop (i : Int ): Boolean =
83
- if ( i == k) {
78
+ if i == k then
84
79
val m = (1 << (count & 31 )) - 1
85
80
(_bits.at(k) & m) == 0
86
- } else if ( _bits.at(i) != 0 ) {
81
+ else if _bits.at(i) != 0 then
87
82
false
88
- } else {
83
+ else
89
84
loop(i + 1 )
90
- }
91
85
loop(0 )
92
- }
93
86
94
87
/** Returns `true` iff all elements in `this` are `true`. */
95
88
def allTrue : Boolean =
96
- if ( isEmpty) {
89
+ if isEmpty then {
97
90
true
98
91
} else {
99
92
val k = (count - 1 ) >> 5
100
93
def loop (i : Int ): Boolean =
101
- if ( i == k) {
94
+ if i == k then {
102
95
val m = (1 << (count & 31 )) - 1
103
96
(_bits.at(k) & m) == m
104
- } else if ( _bits.at(i) != ~ 0 ) {
97
+ } else if _bits.at(i) != ~ 0 then {
105
98
false
106
99
} else {
107
100
loop(i + 1 )
@@ -136,14 +129,14 @@ final class BitArray private (
136
129
assumeUniqueness : Boolean = false
137
130
): BitArray =
138
131
require(this .count == other.count)
139
- if ( isEmpty) {
132
+ if isEmpty then {
140
133
this
141
134
} else {
142
135
val result = if assumeUniqueness then this else copy()
143
136
var u = assumeUniqueness
144
137
val k = (count - 1 ) >> 5
145
138
146
- for ( i <- 0 until k) {
139
+ for i <- 0 until k do {
147
140
result._bits = result._bits.modifyAt(
148
141
i, (n) => operation(n, other._bits.at(n)),
149
142
assumeUniqueness = u
@@ -184,7 +177,7 @@ final class BitArray private (
184
177
* O(1).
185
178
*/
186
179
def positionAfter (p : BitArray .Position ): BitArray .Position =
187
- if ( p.offsetInBucket == 63 ) {
180
+ if p.offsetInBucket == 63 then {
188
181
BitArray .Position (p.bucket + 1 , 0 )
189
182
} else {
190
183
BitArray .Position (p.bucket, p.offsetInBucket + 1 )
@@ -244,7 +237,7 @@ final class BitArray private (
244
237
245
238
/** Returns an independent copy of `this`. */
246
239
def copy (minimumCapacity : Int = 0 ): BitArray =
247
- if ( minimumCapacity > capacity) {
240
+ if minimumCapacity > capacity then {
248
241
// If the requested capacity on the copy is greater than what we have, `reserveCapacity` will
249
242
// create an independent value.
250
243
reserveCapacity(minimumCapacity)
@@ -313,7 +306,7 @@ object BitArray {
313
306
/** Creates an array with the given `bits`. */
314
307
def apply [T ](bits : Boolean * ): BitArray =
315
308
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 )
317
310
result
318
311
319
312
}
0 commit comments