Awesome Reviewers

Reviewer · Algorithms

Prefer built-in ordered collections

When code needs a sorted or deduplicated collection, prefer using a data structure that provides those guarantees natively (e.g. `BTreeSet`/`BTreeMap`) instead of hand-rolled logic such as collecting into a `Vec` and then calling `sort_unstable()` + `dedup()`, or building a side `HashMap` just to get a stable iteration order. Built-in ordered collections...

Instruction

When code needs a sorted or deduplicated collection, prefer using a data structure that provides those guarantees natively (e.g. BTreeSet/BTreeMap) instead of hand-rolled logic such as collecting into a Vec and then calling sort_unstable() + dedup(), or building a side HashMap just to get a stable iteration order. Built-in ordered collections remove extra bookkeeping code, avoid subtle bugs, and often sidestep the need for lint suppressions or extra dependencies (e.g. swapping a HashMap plus #[allow(clippy::disallowed_types)] for a BTreeMap that satisfies the same requirement without the allow).

Before:

let mut outputs: Vec<PathBuf> = collect_outputs();
outputs.sort_unstable();
outputs.dedup();

After:

let outputs: BTreeSet<PathBuf> = collect_outputs().into_iter().collect();

This same principle applies when designing on-disk or in-memory structures for algorithms like garbage collection: choose the representation (e.g. a flat content-addressed objects directory instead of split blobs/unit_outputs) that makes the core algorithm (mark-and-sweep, traversal) simplest to implement and reason about, rather than one that mirrors conceptual categories but complicates the algorithm. When reviewing code that manually re-implements ordering, deduplication, or indexing behavior, check whether a standard collection or simpler data layout already provides it for free.