compact method

int compact()

Implementation

int compact() {
  // Collect alive tuples with their data
  final alive = <({int slotIdx, Uint8List data})>[];
  for (int i = 0; i < slotCount; i++) {
    final data = readTuple(i);
    if (data != null) alive.add((slotIdx: i, data: data));
  }

  // Reset header
  final type = pageType;
  final lsnVal = lsn;
  final np = nextPage;
  _buf.fillRange(0, PageConst.pageSize, 0);
  _bd = ByteData.sublistView(_buf);
  _initHeader(type);
  setLsn(lsnVal);
  setNextPage(np);

  // Re-insert alive tuples
  for (final t in alive) {
    insertTuple(t.data);
  }

  return freeSpace;
}