buildBitArray static method

BitArray buildBitArray(
  1. List<ExpandedPair> pairs
)

Implementation

static BitArray buildBitArray(List<ExpandedPair> pairs) {
  int charNumber = (pairs.length * 2) - 1;
  if (pairs[pairs.length - 1].rightChar == null) {
    charNumber -= 1;
  }

  final size = 12 * charNumber;

  final binary = BitArray(size);
  int accPos = 0;

  final firstPair = pairs[0];
  final firstValue = firstPair.rightChar!.value;
  for (int i = 11; i >= 0; --i) {
    if ((firstValue & (1 << i)) != 0) {
      binary.set(accPos);
    }
    accPos++;
  }

  for (int i = 1; i < pairs.length; ++i) {
    final currentPair = pairs[i];

    final leftValue = currentPair.leftChar!.value;
    for (int j = 11; j >= 0; --j) {
      if ((leftValue & (1 << j)) != 0) {
        binary.set(accPos);
      }
      accPos++;
    }

    if (currentPair.rightChar != null) {
      final rightValue = currentPair.rightChar!.value;
      for (int j = 11; j >= 0; --j) {
        if ((rightValue & (1 << j)) != 0) {
          binary.set(accPos);
        }
        accPos++;
      }
    }
  }
  return binary;
}