message: refactor: simplify SparseSet slightly
diff: @@ -14,52 +14,49 @@ use std::slice;
  #[derive(Clone, Debug)]
  pub struct SparseSet {
  /// Dense contains the instruction pointers in the order in which they
  - /// were inserted. Accessing elements >= self.size is illegal.
  + /// were inserted.
  dense: Vec<usize>,
  /// Sparse maps instruction pointers to their location in dense.
  ///
  /// An instruction pointer is in the set if and only if
  - /// sparse[ip] < size && ip == dense[sparse[ip]].
  - sparse: Vec<usize>,
  - /// The number of elements in the set.
  - size: usize,
  + /// sparse[ip] < dense.len() && ip == dense[sparse[ip]].
  + sparse: Box<[usize]>,
  }
  impl SparseSet {
  pub fn new(size: usize) -> SparseSet {
  SparseSet {
  - dense: vec![0; size],
  - sparse: vec![0; size],
  - size: 0,
  + dense: Vec::with_capacity(size),
  + sparse: vec![0; size].into_boxed_slice(),
  }
  }
  pub fn len(&self) -> usize {
  - self.size
  + self.dense.len()
  }
  pub fn is_empty(&self) -> bool {
  - self.size == 0
  + self.dense.is_empty()
  }
  pub fn capacity(&self) -> usize {
  - self.dense.len()
  + self.dense.capacity()
  }
  pub fn insert(&mut self, value: usize) {
  - let i = self.size;
  - self.dense[i] = value;
  + let i = self.len();
  + assert!(i < self.capacity());
  + self.dense.push(value);
  self.sparse[value] = i;
  - self.size += 1;
  }
  pub fn contains(&self, value: usize) -> bool {
  let i = self.sparse[value];
  - i < self.size && self.dense[i] == value
  + self.dense.get(i) == Some(&value)
  }
  pub fn clear(&mut self) {
  - self.size = 0;
  + self.dense.clear();
  }
  }
  @@ -67,7 +64,7 @@ impl Deref for SparseSet {
  type Target = [usize];
  fn deref(&self) -> &Self::Target {
  - &self.dense[0..self.size]
  + &self.dense
  }
  }
  