Use BTreeSet instead of HashSet whenever possible.

This commit is contained in:
KtorZ 2024-03-14 23:08:39 +01:00
parent fd50473a32
commit 1caed3e87c
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 10 additions and 10 deletions

View File

@ -51,7 +51,7 @@ use pallas::ledger::{
traverse::ComputeHash, traverse::ComputeHash,
}; };
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{BTreeSet, HashMap},
fs::{self, File}, fs::{self, File},
io::BufReader, io::BufReader,
path::{Path, PathBuf}, path::{Path, PathBuf},
@ -198,7 +198,7 @@ where
let mut modules = self.parse_sources(self.config.name.clone())?; let mut modules = self.parse_sources(self.config.name.clone())?;
let our_modules: HashSet<String> = modules.keys().cloned().collect(); let our_modules: BTreeSet<String> = modules.keys().cloned().collect();
self.with_dependencies(&mut modules)?; self.with_dependencies(&mut modules)?;
@ -296,7 +296,7 @@ where
let mut modules = self.parse_sources(self.config.name.clone())?; let mut modules = self.parse_sources(self.config.name.clone())?;
let our_modules: HashSet<String> = modules.keys().cloned().collect(); let our_modules: BTreeSet<String> = modules.keys().cloned().collect();
self.with_dependencies(&mut modules)?; self.with_dependencies(&mut modules)?;
@ -684,7 +684,7 @@ where
fn type_check( fn type_check(
&mut self, &mut self,
our_modules: &HashSet<String>, our_modules: &BTreeSet<String>,
mut all_modules: ParsedModules, mut all_modules: ParsedModules,
tracing: Tracing, tracing: Tracing,
validate_module_name: bool, validate_module_name: bool,

View File

@ -8,7 +8,7 @@ use aiken_lang::{
}; };
use petgraph::{algo, graph::NodeIndex, Direction, Graph}; use petgraph::{algo, graph::NodeIndex, Direction, Graph};
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{BTreeSet, HashMap},
io, io,
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
path::PathBuf, path::PathBuf,
@ -47,7 +47,7 @@ impl ParsedModules {
Self(HashMap::new()) Self(HashMap::new())
} }
pub fn sequence(&self, our_modules: &HashSet<String>) -> Result<Vec<String>, Error> { pub fn sequence(&self, our_modules: &BTreeSet<String>) -> Result<Vec<String>, Error> {
let inputs = self let inputs = self
.0 .0
.values() .values()
@ -60,7 +60,7 @@ impl ParsedModules {
let mut indices = HashMap::with_capacity(capacity); let mut indices = HashMap::with_capacity(capacity);
let mut our_indices = HashSet::with_capacity(our_modules.len()); let mut our_indices = BTreeSet::new();
for (value, _) in &inputs { for (value, _) in &inputs {
let index = graph.add_node(value.to_string()); let index = graph.add_node(value.to_string());
@ -90,7 +90,7 @@ impl ParsedModules {
// know starting indices for our search, so when we remove a dependency, we need find // know starting indices for our search, so when we remove a dependency, we need find
// back what those indices are. // back what those indices are.
if messed_up_indices { if messed_up_indices {
our_indices = HashSet::with_capacity(our_modules.len()); our_indices = BTreeSet::new();
for j in graph.node_indices() { for j in graph.node_indices() {
if our_modules.contains(graph[j].as_str()) { if our_modules.contains(graph[j].as_str()) {
our_indices.insert(j); our_indices.insert(j);
@ -125,7 +125,7 @@ impl ParsedModules {
let mut path = vec![]; let mut path = vec![];
find_cycle(origin, origin, &graph, &mut path, &mut HashSet::new()); find_cycle(origin, origin, &graph, &mut path, &mut BTreeSet::new());
let modules = path let modules = path
.iter() .iter()
@ -176,7 +176,7 @@ fn find_cycle<W>(
parent: NodeIndex, parent: NodeIndex,
graph: &petgraph::Graph<W, ()>, graph: &petgraph::Graph<W, ()>,
path: &mut Vec<NodeIndex>, path: &mut Vec<NodeIndex>,
seen: &mut HashSet<NodeIndex>, seen: &mut BTreeSet<NodeIndex>,
) -> bool { ) -> bool {
seen.insert(parent); seen.insert(parent);