Skip to content

Commit

Permalink
attempt to do away with BTreeMap
Browse files Browse the repository at this point in the history
  • Loading branch information
anastygnome committed Jun 24, 2024
1 parent df196b5 commit 76abc9d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/uu/tsort/src/tsort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use clap::{crate_version, Arg, Command};
use std::collections::{BTreeMap, HashSet, VecDeque};
use std::collections::{HashMap, HashSet, VecDeque};
use std::fmt::Write;
use std::fs::File;
use std::io::{stdin, BufReader, Read};
Expand Down Expand Up @@ -132,14 +132,14 @@ impl<'input> Node<'input> {
}

struct Graph<'input> {
nodes: BTreeMap<&'input str, Node<'input>>,
nodes: HashMap<&'input str, Node<'input>>,
result: Result<Vec<&'input str>, Vec<&'input str>>,
}

impl<'input> Graph<'input> {
fn new() -> Self {
Self {
nodes: BTreeMap::new(),
nodes: HashMap::new(),
result: Ok(Vec::new()),
}
}
Expand Down Expand Up @@ -176,7 +176,7 @@ impl<'input> Graph<'input> {
}
})
.collect();

independent_nodes_queue.make_contiguous().sort_unstable();
while let Some(name_of_next_node_to_process) = independent_nodes_queue.pop_front() {
result.push(name_of_next_node_to_process);
if let Some(node_to_process) = self.nodes.remove(name_of_next_node_to_process) {
Expand Down

0 comments on commit 76abc9d

Please sign in to comment.