@@ -26,7 +26,7 @@ class CompositeCounter {
26
26
final int _indexMask;
27
27
final int _offsetMask;
28
28
29
- CompositeCounter ({this .chunkBits = 16 , List <BitCounterChunk > chunks})
29
+ CompositeCounter ({this .chunkBits = 16 , List <BitCounterChunk >? chunks})
30
30
: _chunkLength = (1 << chunkBits),
31
31
_indexMask = (1 << chunkBits) - 1 ,
32
32
_offsetMask = ~ ((1 << chunkBits) - 1 ),
@@ -52,7 +52,7 @@ class CompositeCounter {
52
52
/// TODO: add BigInt support.
53
53
void operator []= (int index, int value) {
54
54
final chunkOffset = index & _offsetMask;
55
- final c = _getChunk (chunkOffset, true );
55
+ final c = _getChunk (chunkOffset, true )! ;
56
56
c.bitCounter[index & _indexMask] = value;
57
57
}
58
58
@@ -64,7 +64,7 @@ class CompositeCounter {
64
64
throw StateError ('Only sets with the same chunkBits can be added' );
65
65
}
66
66
for (BitSetChunk bsc in set .chunks) {
67
- final c = _getChunk (bsc.offset, true );
67
+ final c = _getChunk (bsc.offset, true )! ;
68
68
c.bitCounter.addBitSet (bsc.bitSet, shiftLeft: shiftLeft);
69
69
}
70
70
}
@@ -77,7 +77,7 @@ class CompositeCounter {
77
77
throw StateError ('Only counters with the same chunkBits can be added' );
78
78
}
79
79
for (BitCounterChunk bcc in counter.chunks) {
80
- final c = _getChunk (bcc.offset, true );
80
+ final c = _getChunk (bcc.offset, true )! ;
81
81
c.bitCounter.addBitCounter (bcc.bitCounter, shiftLeft: shiftLeft);
82
82
}
83
83
}
@@ -126,7 +126,7 @@ class CompositeCounter {
126
126
/// The increment starts at the bit position specified by [shiftLeft] .
127
127
void increment (int index, {int shiftLeft = 0 }) {
128
128
final chunkOffset = index & _offsetMask;
129
- final c = _getChunk (chunkOffset, true );
129
+ final c = _getChunk (chunkOffset, true )! ;
130
130
c.bitCounter.increment (index & _indexMask, shiftLeft: shiftLeft);
131
131
}
132
132
@@ -152,12 +152,11 @@ class CompositeCounter {
152
152
return CompositeSet (
153
153
chunkBits: chunkBits,
154
154
chunks: chunks
155
- .map ((c) {
155
+ .expand < BitSetChunk > ((c) {
156
156
final set = c.bitCounter.toMask (minValue: minValue);
157
- if (set .isEmpty) return null ;
158
- return BitSetChunk (c.offset, set );
157
+ if (set .isEmpty) return [] ;
158
+ return [ BitSetChunk (c.offset, set )] ;
159
159
})
160
- .where ((c) => c != null )
161
160
.toList ());
162
161
}
163
162
@@ -167,7 +166,7 @@ class CompositeCounter {
167
166
throw Exception ('chunkBits must match: $chunkBits != ${other .chunkBits }' );
168
167
}
169
168
for (BitCounterChunk oc in other.chunks) {
170
- final c = _getChunk (oc.offset, true );
169
+ final c = _getChunk (oc.offset, true )! ;
171
170
if (c.bitCounter.bitLength == 0 ) {
172
171
c.bitCounter._bits.addAll (oc.bitCounter._bits.map ((a) => a.clone ()));
173
172
} else {
@@ -238,7 +237,7 @@ class CompositeCounter {
238
237
);
239
238
}
240
239
241
- BitCounterChunk _getChunk (int offset, [bool forInsert = false ]) {
240
+ BitCounterChunk ? _getChunk (int offset, [bool forInsert = false ]) {
242
241
int left = 0 ;
243
242
int right = chunks.length - 1 ;
244
243
while (left <= right) {
0 commit comments