Chriscbr / thinset

A data structure for sparse sets of unsigned integers.
Apache License 2.0
2 stars 1 forks source link

Index / IndexMut traits on SparseMap #9

Closed Chriscbr closed 8 months ago

Chriscbr commented 8 months ago

https://doc.rust-lang.org/std/ops/trait.Index.html

let mut m: SparseMap<u32, u32> = SparseMap::new();
m.insert(13, 2);
m.insert(8, 16);

{
  let x = m[13];
  let y = &mut m[8];
  *y += 1;
}

for Pair {key, value} in m.iter() {
  println!("{key}:{value}"); // 13:2, 8:17
}