ofIterable static method
- Iterable<
LogicValue> it
Constructs a LogicValue from it
.
The order of the created LogicValue will be such that the i
th entry in
it
corresponds to the i
th group of bits. That is, the 0th element of
it
will be the least significant chunk of bits of the returned
LogicValue. Bits within each element of it
are kept in the same
order as they were originally.
For example:
var it = [LogicValue.zero, LogicValue.x, LogicValue.ofString('01xz')];
var lv = LogicValue.of(it);
print(lv); // This prints `6'b01xzx0`
Implementation
static LogicValue ofIterable(Iterable<LogicValue> it) {
var smallBuffer = LogicValue.empty;
var fullResult = LogicValue.empty;
// shift small chunks in together before shifting BigInt's, since
// shifting BigInt's is expensive
for (final lv in it) {
final lvPlusSmall = lv.width + smallBuffer.width;
if (lvPlusSmall <= INT_BITS) {
smallBuffer = lv._concatenate(smallBuffer);
} else {
// only put 64-bit chunks onto `fullResult`, rest onto `smallBuffer`
final upperBound =
INT_BITS * (lvPlusSmall ~/ INT_BITS) - smallBuffer.width;
fullResult = lv
.getRange(0, upperBound)
._concatenate(smallBuffer)
._concatenate(fullResult);
smallBuffer = lv.getRange(upperBound, lv.width);
}
assert(smallBuffer.width <= INT_BITS,
'Keep smallBuffer small to meet invariants and efficiency');
}
// grab what's left
return smallBuffer._concatenate(fullResult);
}