Skip to content

Commit 4503143

Browse files
authored
[Bug Fix] Edge case: BitSet when highest bit index is a multiplication of 32 (#10)
* [Bug Fix] Edge case of bit index which has no residue when dividing with 32 (From last bit index to bit array length: +1) * [Code Review] Fixed according to code review * [Test] Simple values test fixed
1 parent aee098a commit 4503143

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lib/src/bit_set.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ListSet extends BitSet {
108108
}
109109

110110
@override
111-
int get length => _list.isEmpty ? 0 : _list.last;
111+
int get length => _list.isEmpty ? 0 : _list.last + 1;
112112

113113
@override
114114
int get cardinality {

test/bit_counter_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ void main() {
9999
expect(counter[2001], 0);
100100
});
101101

102+
test('bit sets (edge case)', () {
103+
final counter = BitCounter(0);
104+
counter.addBitSet(ListSet.fromSorted([0, 2, 5, 2048]));
105+
expect(counter[2048], 1);
106+
});
107+
102108
test('bit set with shift', () {
103109
final counter = BitCounter(128);
104110
counter.addBitSet(ListSet.fromSorted([0, 2, 5]), shiftLeft: 3);

test/bit_set_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void main() {
77
final set = ListSet.fromSorted([23, 45, 78, 98, 101, 102, 103]);
88

99
test('simple values', () {
10-
expect(set.length, 103);
10+
expect(set.length, 104);
1111
expect(set.cardinality, 7);
1212
expect(set[22], isFalse);
1313
expect(set[23], isTrue);

0 commit comments

Comments
 (0)