Skip to content

Use Vec::resize and Vec::truncate to update levels in week 2 #159

@ppdogg

Description

@ppdogg

In compact.rs of week2 day1 commit. You use HashSet to update state.l0_sstables in function force_full_compaction:

let mut l0_sstables_map = l0_sstables.iter().copied().collect::<HashSet<_>>();
state.l0_sstables = state
                    .l0_sstables
                    .iter()
                    .filter(|x| !l0_sstables_map.remove(x))
                    .copied()
                    .collect::<Vec<_>>();

Actually, Vec::resize can be used to update state.l0_sstables. Because we always choose consecutive sst_ids from l0_sstables array:

snapshot
      .l0_sstables
      .resize(snapshot.l0_sstables.len() - l0_sstables.len(), 0);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions