Skip to content

Commit

Permalink
Use BTreeMap to get a sorted map instead of Vec + HashMap (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil authored Jan 13, 2025
2 parents e05284e + e9c61e0 commit 37a9555
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ pub fn check_values(
);

Ok(check_result.map(|elems| ratchet::Nixpkgs {
package_names: elems.iter().map(|(name, _)| name.to_owned()).collect(),
package_map: elems.into_iter().collect(),
packages: elems.into_iter().collect(),
}))
}

Expand Down
12 changes: 5 additions & 7 deletions src/ratchet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Each type has a `compare` method that validates the ratchet checks for that item.
use std::collections::HashMap;
use std::collections::BTreeMap;

use relative_path::RelativePathBuf;

Expand All @@ -13,10 +13,8 @@ use crate::validation::{self, Validation, Validation::Success};
/// The ratchet value for the entirety of Nixpkgs.
#[derive(Default)]
pub struct Nixpkgs {
/// Sorted list of packages in `package_map`
pub package_names: Vec<String>,
/// The ratchet values for all packages
pub package_map: HashMap<String, Package>,
pub packages: BTreeMap<String, Package>,
}

impl Nixpkgs {
Expand All @@ -25,9 +23,9 @@ impl Nixpkgs {
validation::sequence_(
// We only loop over the current attributes,
// we don't need to check ones that were removed
to.package_names.into_iter().map(|name| {
Package::compare(&name, from.package_map.get(&name), &to.package_map[&name])
}),
to.packages
.into_iter()
.map(|(name, pkg)| Package::compare(&name, from.packages.get(&name), &pkg)),
)
}
}
Expand Down

0 comments on commit 37a9555

Please sign in to comment.