void SetU32::append()

in glean/rts/ownership/setu32.cpp [210:245]


void SetU32::append(uint32_t value) {
  const auto block = value / 256;
  const auto bit = value % 256;
  if (!hdrs.empty() && hdrs.back().id() == block) {
    auto& hdr = hdrs.back();
    switch (hdr.type()) {
      case Hdr::Sparse:
        assert(bit >= sparse.back());
        if (bit != sparse.back()) {
          const auto len = hdr.sparseLen();
          if (fitsSparse(len, 1)) {
            hdr.addSparseLen(1);
            sparse.push_back(bit);
          } else {
            dense.push_back(Bits256(&*(sparse.end() - len), len) | Bits256::single(bit));
            sparse.resize(sparse.size() - len);
            hdr = Hdr::dense(block);
          }
        }
        break;
      case Hdr::Dense:
        dense.back() |= Bits256::single(bit);
        if (dense.back() == Bits256::all()) {
          dense.pop_back();
          hdr = Hdr::full(block);
        }
        break;

      case Hdr::Full:
        assert(bit == 255);
    }
  } else {
    hdrs.push_back(Hdr::sparse(block, 1));
    sparse.push_back(bit);
  }
}