Skip to content

Commit 6d53c3f

Browse files
authored
Merge pull request #5 from eugmes/null-safety
Migrate the library to null safety
2 parents 78ab5b8 + cc5edb9 commit 6d53c3f

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

lib/src/bit_array.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BitArray extends BitSet {
2020
}
2121

2222
/// Creates a bit array using a generic bit set.
23-
factory BitArray.fromBitSet(BitSet set, {int length}) {
23+
factory BitArray.fromBitSet(BitSet set, {int? length}) {
2424
length ??= set.length;
2525
final setDataLength = _bufferLength32(set.length);
2626
final data = Uint32List(_bufferLength32(length));

lib/src/composite_counter.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CompositeCounter {
2626
final int _indexMask;
2727
final int _offsetMask;
2828

29-
CompositeCounter({this.chunkBits = 16, List<BitCounterChunk> chunks})
29+
CompositeCounter({this.chunkBits = 16, List<BitCounterChunk>? chunks})
3030
: _chunkLength = (1 << chunkBits),
3131
_indexMask = (1 << chunkBits) - 1,
3232
_offsetMask = ~((1 << chunkBits) - 1),
@@ -52,7 +52,7 @@ class CompositeCounter {
5252
/// TODO: add BigInt support.
5353
void operator []=(int index, int value) {
5454
final chunkOffset = index & _offsetMask;
55-
final c = _getChunk(chunkOffset, true);
55+
final c = _getChunk(chunkOffset, true)!;
5656
c.bitCounter[index & _indexMask] = value;
5757
}
5858

@@ -64,7 +64,7 @@ class CompositeCounter {
6464
throw StateError('Only sets with the same chunkBits can be added');
6565
}
6666
for (BitSetChunk bsc in set.chunks) {
67-
final c = _getChunk(bsc.offset, true);
67+
final c = _getChunk(bsc.offset, true)!;
6868
c.bitCounter.addBitSet(bsc.bitSet, shiftLeft: shiftLeft);
6969
}
7070
}
@@ -77,7 +77,7 @@ class CompositeCounter {
7777
throw StateError('Only counters with the same chunkBits can be added');
7878
}
7979
for (BitCounterChunk bcc in counter.chunks) {
80-
final c = _getChunk(bcc.offset, true);
80+
final c = _getChunk(bcc.offset, true)!;
8181
c.bitCounter.addBitCounter(bcc.bitCounter, shiftLeft: shiftLeft);
8282
}
8383
}
@@ -126,7 +126,7 @@ class CompositeCounter {
126126
/// The increment starts at the bit position specified by [shiftLeft].
127127
void increment(int index, {int shiftLeft = 0}) {
128128
final chunkOffset = index & _offsetMask;
129-
final c = _getChunk(chunkOffset, true);
129+
final c = _getChunk(chunkOffset, true)!;
130130
c.bitCounter.increment(index & _indexMask, shiftLeft: shiftLeft);
131131
}
132132

@@ -152,12 +152,11 @@ class CompositeCounter {
152152
return CompositeSet(
153153
chunkBits: chunkBits,
154154
chunks: chunks
155-
.map((c) {
155+
.expand<BitSetChunk>((c) {
156156
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)];
159159
})
160-
.where((c) => c != null)
161160
.toList());
162161
}
163162

@@ -167,7 +166,7 @@ class CompositeCounter {
167166
throw Exception('chunkBits must match: $chunkBits != ${other.chunkBits}');
168167
}
169168
for (BitCounterChunk oc in other.chunks) {
170-
final c = _getChunk(oc.offset, true);
169+
final c = _getChunk(oc.offset, true)!;
171170
if (c.bitCounter.bitLength == 0) {
172171
c.bitCounter._bits.addAll(oc.bitCounter._bits.map((a) => a.clone()));
173172
} else {
@@ -238,7 +237,7 @@ class CompositeCounter {
238237
);
239238
}
240239

241-
BitCounterChunk _getChunk(int offset, [bool forInsert = false]) {
240+
BitCounterChunk? _getChunk(int offset, [bool forInsert = false]) {
242241
int left = 0;
243242
int right = chunks.length - 1;
244243
while (left <= right) {

lib/src/composite_set.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CompositeSet extends BitSet {
4141
final int _indexMask;
4242
final int _offsetMask;
4343

44-
CompositeSet({this.chunkBits = 16, List<BitSetChunk> chunks})
44+
CompositeSet({this.chunkBits = 16, List<BitSetChunk>? chunks})
4545
: _chunkLength = (1 << chunkBits),
4646
_indexMask = (1 << chunkBits) - 1,
4747
_offsetMask = ~((1 << chunkBits) - 1),
@@ -61,7 +61,7 @@ class CompositeSet extends BitSet {
6161
/// Sets the bit specified by the [index] to the [value].
6262
void operator []=(int index, bool value) {
6363
final chunkOffset = index & _offsetMask;
64-
final c = _getChunk(chunkOffset, true);
64+
final c = _getChunk(chunkOffset, true)!;
6565
c.asBitArray(_chunkLength)[index & _indexMask] = value;
6666
}
6767

@@ -132,13 +132,13 @@ class CompositeSet extends BitSet {
132132
}
133133

134134
/// Optimize the containers.
135-
void optimize({BitArrayOptimizer optimizer, int removeThreshold = 0}) {
135+
void optimize({BitArrayOptimizer? optimizer, int removeThreshold = 0}) {
136136
optimizer ??= chunkBits == 16 ? _optimizeBitArray16 : _simpleOptimizer;
137137
int removeCount = 0;
138138
for (BitSetChunk c in chunks) {
139139
if (c._set is BitArray) {
140140
final bitSet = optimizer(c._set as BitArray);
141-
if (bitSet != null && bitSet is! BitArray) {
141+
if (bitSet is! BitArray) {
142142
c._set = bitSet;
143143
}
144144
}
@@ -170,7 +170,7 @@ class CompositeSet extends BitSet {
170170
}
171171
}
172172

173-
BitSetChunk _getChunk(int offset, [bool forInsert = false]) {
173+
BitSetChunk? _getChunk(int offset, [bool forInsert = false]) {
174174
int left = 0;
175175
int right = chunks.length - 1;
176176
while (left <= right) {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ homepage: https://github.com/isoos/bit_array
77
author: Istvan Soos <istvan.soos@gmail.com>
88

99
environment:
10-
sdk: '>=2.2.0 <3.0.0'
10+
sdk: '>=2.12.0 <3.0.0'
1111

1212
#dependencies:
1313
#

0 commit comments

Comments
 (0)