createBitmap static method
Implementation
static Uint8List createBitmap(List<int> bits) {
// Bits are read from left to right. e.g. 0b10000000 represents the first bit is set in one byte.
// The decimal value of 0b10000000 is 128.
const firstBitInByte = 128;
final bitmap = Uint8List.fromList([0, 0, 0, 0]);
// Check if duplicates exist in bits
final dupCheckSet = Set();
bits.forEach((bit) {
if (bit >= MAX_SIGNATURES_SUPPORTED) {
throw ArgumentError("Invalid bit value $bit.");
}
if (dupCheckSet.contains(bit)) {
throw ArgumentError("Duplicated bits detected.");
}
dupCheckSet.add(bit);
int byteOffset = (bit / 8).floor();
int byte = bitmap[byteOffset];
byte |= firstBitInByte >> bit % 8;
bitmap[byteOffset] = byte;
});
return bitmap;
}