pub(in crate::inspect::smp) fn decode_live_entry_ids_from_tombstone_bitset(
    bitset: &[u8],
    live_id_bound: u32,
) -> Option<Vec<u32>> {
    let ids = decode_live_entry_ids_with_mapping(bitset, live_id_bound, false);
    if ids.is_some() {
        return ids;
    }
    decode_live_entry_ids_with_mapping(bitset, live_id_bound, true)
}

pub(in crate::inspect::smp) fn decode_live_entry_ids_with_mapping(
    bitset: &[u8],
    live_id_bound: u32,
    subtract_one: bool,
) -> Option<Vec<u32>> {
    let mut live_entry_ids = Vec::new();

    for entry_id in 1..=live_id_bound {
        let bit_index = if subtract_one {
            entry_id.checked_sub(1)?
        } else {
            entry_id
        };
        let byte_index = usize::try_from(bit_index / 8).ok()?;
        let bit_mask = 1u8.checked_shl(bit_index % 8).unwrap_or(0);
        let tombstone_byte = *bitset.get(byte_index)?;
        if tombstone_byte & bit_mask == 0 {
            live_entry_ids.push(entry_id);
        }
    }

    Some(live_entry_ids)
}
